Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -95,43 +95,37 @@ map_dir = "." # Top-level directory
|
|
95 |
canvas_size = 3000
|
96 |
scroll_offset = {"x": 0, "y": 0}
|
97 |
|
98 |
-
#
|
99 |
if "layout_image" not in st.session_state:
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
112 |
-
if scroll_buttons[0].button("⬅️"):
|
113 |
-
scroll_offset["x"] -= 100
|
114 |
-
if scroll_buttons[1].button("⬆️"):
|
115 |
-
scroll_offset["y"] -= 100
|
116 |
-
if scroll_buttons[2].button("➡️"):
|
117 |
-
scroll_offset["x"] += 100
|
118 |
-
if st.sidebar.button("⬇️"):
|
119 |
-
scroll_offset["y"] += 100
|
120 |
|
121 |
# Display map
|
122 |
-
if "layout_image"
|
123 |
st.image(
|
124 |
st.session_state["layout_image"],
|
125 |
caption="Generated Dungeon Map Layout",
|
126 |
-
|
127 |
output_format="PNG",
|
128 |
clamp=True,
|
129 |
)
|
130 |
|
131 |
-
#
|
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
|
@@ -141,9 +135,20 @@ if st.button("🗺️ Regenerate Map"):
|
|
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 |
-
|
146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
|
148 |
# Sidebar for file upload
|
149 |
st.sidebar.title("Options")
|
|
|
95 |
canvas_size = 3000
|
96 |
scroll_offset = {"x": 0, "y": 0}
|
97 |
|
98 |
+
# Initialize session state
|
99 |
if "layout_image" not in st.session_state:
|
100 |
+
st.session_state["layout_image"] = None
|
101 |
+
if "canvas" not in st.session_state:
|
102 |
+
st.session_state["canvas"] = None
|
103 |
+
if "saved" not in st.session_state:
|
104 |
+
st.session_state["saved"] = False
|
105 |
+
|
106 |
+
# Generate map if not saved and layout_image is empty
|
107 |
+
if st.session_state["layout_image"] is None or not st.session_state["saved"]:
|
108 |
image_files = [f for f in os.listdir(map_dir) if f.endswith(".png")]
|
109 |
if image_files:
|
110 |
layout_image, canvas = arrange_images(image_files, canvas_size=(canvas_size, canvas_size))
|
111 |
st.session_state["layout_image"] = layout_image
|
112 |
st.session_state["canvas"] = canvas
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
# Display map
|
115 |
+
if st.session_state["layout_image"] is not None:
|
116 |
st.image(
|
117 |
st.session_state["layout_image"],
|
118 |
caption="Generated Dungeon Map Layout",
|
119 |
+
use_column_width=True,
|
120 |
output_format="PNG",
|
121 |
clamp=True,
|
122 |
)
|
123 |
|
124 |
+
# Save map button
|
125 |
if st.button("💾 Save Map"):
|
126 |
save_path = "saved_dungeon_map.png"
|
127 |
st.session_state["canvas"].save(save_path)
|
128 |
+
st.session_state["saved"] = True
|
129 |
st.success(f"Map saved as {save_path}")
|
130 |
|
131 |
# Regenerate map button
|
|
|
135 |
layout_image, canvas = arrange_images(image_files, canvas_size=(canvas_size, canvas_size))
|
136 |
st.session_state["layout_image"] = layout_image
|
137 |
st.session_state["canvas"] = canvas
|
138 |
+
st.session_state["saved"] = False # Mark as unsaved
|
139 |
st.experimental_rerun()
|
140 |
+
|
141 |
+
# WASD Controls for scrolling
|
142 |
+
st.sidebar.title("Scroll Map")
|
143 |
+
scroll_buttons = st.sidebar.columns(3)
|
144 |
+
if scroll_buttons[0].button("⬅️"):
|
145 |
+
scroll_offset["x"] -= 100
|
146 |
+
if scroll_buttons[1].button("⬆️"):
|
147 |
+
scroll_offset["y"] -= 100
|
148 |
+
if scroll_buttons[2].button("➡️"):
|
149 |
+
scroll_offset["x"] += 100
|
150 |
+
if st.sidebar.button("⬇️"):
|
151 |
+
scroll_offset["y"] += 100
|
152 |
|
153 |
# Sidebar for file upload
|
154 |
st.sidebar.title("Options")
|