Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -82,7 +82,7 @@ def arrange_images(image_files, canvas_size=(3000, 3000)):
|
|
82 |
buffer = BytesIO()
|
83 |
canvas.save(buffer, format="PNG")
|
84 |
buffer.seek(0)
|
85 |
-
return buffer
|
86 |
|
87 |
# Streamlit App
|
88 |
st.title("Dynamic Dungeon Map Generator")
|
@@ -95,6 +95,17 @@ map_dir = "." # Top-level directory
|
|
95 |
canvas_size = 3000
|
96 |
scroll_offset = {"x": 0, "y": 0}
|
97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
# WASD Controls for scrolling
|
99 |
st.sidebar.title("Scroll Map")
|
100 |
scroll_buttons = st.sidebar.columns(3)
|
@@ -107,26 +118,32 @@ if scroll_buttons[2].button("➡️"):
|
|
107 |
if st.sidebar.button("⬇️"):
|
108 |
scroll_offset["y"] += 100
|
109 |
|
110 |
-
#
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
# Sidebar for file upload
|
132 |
st.sidebar.title("Options")
|
|
|
82 |
buffer = BytesIO()
|
83 |
canvas.save(buffer, format="PNG")
|
84 |
buffer.seek(0)
|
85 |
+
return buffer, canvas
|
86 |
|
87 |
# Streamlit App
|
88 |
st.title("Dynamic Dungeon Map Generator")
|
|
|
95 |
canvas_size = 3000
|
96 |
scroll_offset = {"x": 0, "y": 0}
|
97 |
|
98 |
+
# Generate map on load
|
99 |
+
if "layout_image" not in st.session_state:
|
100 |
+
# Scan the directory for .png files
|
101 |
+
image_files = [f for f in os.listdir(map_dir) if f.endswith(".png")]
|
102 |
+
if image_files:
|
103 |
+
layout_image, canvas = arrange_images(image_files, canvas_size=(canvas_size, canvas_size))
|
104 |
+
st.session_state["layout_image"] = layout_image
|
105 |
+
st.session_state["canvas"] = canvas
|
106 |
+
else:
|
107 |
+
st.write("No PNG files found in the top-level directory.")
|
108 |
+
|
109 |
# WASD Controls for scrolling
|
110 |
st.sidebar.title("Scroll Map")
|
111 |
scroll_buttons = st.sidebar.columns(3)
|
|
|
118 |
if st.sidebar.button("⬇️"):
|
119 |
scroll_offset["y"] += 100
|
120 |
|
121 |
+
# Display map
|
122 |
+
if "layout_image" in st.session_state:
|
123 |
+
st.image(
|
124 |
+
st.session_state["layout_image"],
|
125 |
+
caption="Generated Dungeon Map Layout",
|
126 |
+
use_column_width=True,
|
127 |
+
output_format="PNG",
|
128 |
+
clamp=True,
|
129 |
+
)
|
130 |
+
|
131 |
+
# Add save button
|
132 |
+
if st.button("💾 Save Map"):
|
133 |
+
save_path = "saved_dungeon_map.png"
|
134 |
+
st.session_state["canvas"].save(save_path)
|
135 |
+
st.success(f"Map saved as {save_path}")
|
136 |
+
|
137 |
+
# Regenerate map button
|
138 |
+
if st.button("🗺️ Regenerate Map"):
|
139 |
+
image_files = [f for f in os.listdir(map_dir) if f.endswith(".png")]
|
140 |
+
if image_files:
|
141 |
+
layout_image, canvas = arrange_images(image_files, canvas_size=(canvas_size, canvas_size))
|
142 |
+
st.session_state["layout_image"] = layout_image
|
143 |
+
st.session_state["canvas"] = canvas
|
144 |
+
st.experimental_rerun()
|
145 |
+
else:
|
146 |
+
st.write("No PNG files found in the top-level directory.")
|
147 |
|
148 |
# Sidebar for file upload
|
149 |
st.sidebar.title("Options")
|