-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
101 lines (82 loc) · 3.39 KB
/
Copy pathapp.py
File metadata and controls
101 lines (82 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from src.WADViewer import WadViewer
from src.WADParser import WAD_file
import matplotlib.pyplot as plt
from loguru import logger
import os
import streamlit as st
from app_utils import banner_html
def get_titlepic(viewer):
fig, ax = plt.subplots(1, 1, figsize=(1.6, 1))
fig.patch.set_alpha(0)
ax.axis("off")
if "TITLEPIC" in viewer.wad.lump_names:
viewer.draw_patch("TITLEPIC", ax=ax)
elif "TITLE" in viewer.wad.lump_names:
viewer.draw_flat("TITLE", ax=ax)
else:
return None
return fig
def init_app():
if "wad" not in st.session_state:
st.session_state["wad"] = None
st.session_state["viewer"] = None
st.session_state["wad_path"] = None
st.session_state["title_pic"] = None
st.set_page_config(page_title="WAD Viewer",
page_icon="media/skull.png", layout="centered")
st.components.v1.html(banner_html)
init_app()
st.header("DOOM WAD Viewer")
st.text("A simple WAD file viewer for DOOM, DOOM II and other games using the same engine.")
st.text("Will read and display the contents of a WAD file, including maps, textures, sprites, sounds and musics.")
head_container = st.container(border=False)
with head_container:
head_col1, head_col2 = st.columns([1, 1])
with head_col1:
uploaded_file = st.file_uploader(
"Upload a WAD file to get started.", accept_multiple_files=False)
if uploaded_file is not None:
if uploaded_file.name != st.session_state["wad_path"]:
wad = WAD_file(uploaded_file)
st.session_state["wad"] = wad
st.session_state["wad_path"] = uploaded_file.name
st.session_state["viewer"] = WadViewer(wad)
logger.info("App: WAD file uploaded.")
try:
pic = get_titlepic(st.session_state["viewer"])
except:
pic = None
st.session_state["title_pic"] = pic
# Cleaning the output folder.
for f in os.listdir("output"):
if f != ".gitkeep":
os.remove(os.path.join("output", f))
if st.session_state["wad"] is None:
for col in st.columns(5):
col.image("media/caco.png", use_container_width=True,
output_format="PNG")
st.write(
"You can download some WAD files from the [Doom Wiki](https://doomwiki.org/wiki/Category:Doom_II_WADs).")
st.write(
"The full version of the app is available on [Github](https://github.com/Sylvain-Rama/pyWAD).")
else:
if st.session_state["title_pic"] is not None:
with head_col2:
st.pyplot(
st.session_state["title_pic"], format="png", dpi=300, bbox_inches="tight", use_container_width=True
)
pages = []
if st.session_state["wad"].maps is not None:
pages.append(st.Page("st_pages/maps.py", title="Maps"))
if st.session_state["wad"].flats is not None:
pages.append(st.Page("st_pages/flats.py", title="Flats"))
if st.session_state["wad"].musics is not None:
pages.append(st.Page("st_pages/musics.py", title="Musics"))
if st.session_state["wad"].textures is not None:
pages.append(st.Page("st_pages/textures.py", title="Textures"))
if st.session_state["wad"].spritesheets is not None:
pages.append(st.Page("st_pages/sprites.py", title="Sprites"))
if st.session_state["wad"].sounds is not None:
pages.append(st.Page("st_pages/sounds.py", title="Sounds"))
pg = st.navigation(pages)
pg.run()