Spaces:
Sleeping
Sleeping
Deploy Myco from CI
Browse files- ui/renderers.py +111 -275
ui/renderers.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
-
"""
|
|
|
|
|
|
|
| 2 |
|
| 3 |
from typing import Any, cast
|
| 4 |
import gradio as gr
|
|
@@ -11,332 +13,166 @@ from game.engine import (
|
|
| 11 |
from game.state import welcome_history
|
| 12 |
from models.mushroom import Mushroom
|
| 13 |
from ui.renderers import (
|
| 14 |
-
dex_markdown,
|
| 15 |
-
|
| 16 |
-
mushroom_card, play_hook_markdown, progress_markdown,
|
| 17 |
-
world_map_markdown,
|
| 18 |
)
|
| 19 |
|
|
|
|
| 20 |
EMPTY_COLLECTION = None
|
| 21 |
START_POSITION = (1, 1)
|
| 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 |
def mushroom_card_from_state(current):
|
| 54 |
-
if current is None:
|
| 55 |
-
|
| 56 |
-
return mushroom_card(
|
| 57 |
-
Mushroom.from_dict(current),
|
| 58 |
-
current.get("clue"),
|
| 59 |
-
current.get("secret"),
|
| 60 |
-
current,
|
| 61 |
-
)
|
| 62 |
-
|
| 63 |
|
|
|
|
| 64 |
def search_forest(collection, position):
|
| 65 |
mushroom, current, history = discover_mushroom(collection)
|
| 66 |
pos = _safe_pos(position)
|
| 67 |
-
return (
|
| 68 |
-
|
| 69 |
-
game_status_markdown(current, collection, pos),
|
| 70 |
-
mushroom_card_from_state(current),
|
| 71 |
-
current,
|
| 72 |
-
history,
|
| 73 |
-
dex_markdown(collection),
|
| 74 |
-
progress_markdown(collection),
|
| 75 |
-
)
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
|
|
|
| 78 |
def ask_companion(message, history, current, collection, position):
|
| 79 |
return myco_reply(message, history, current, collection, position)
|
| 80 |
|
| 81 |
-
|
| 82 |
def collect_discovery(current, collection, history, position):
|
| 83 |
updated_coll, updated_hist = collect_current(current, collection, history)
|
| 84 |
pos = _safe_pos(position)
|
| 85 |
-
return (
|
| 86 |
-
|
| 87 |
-
forest_scene(current, updated_coll, pos),
|
| 88 |
-
game_status_markdown(current, updated_coll, pos),
|
| 89 |
-
dex_markdown(updated_coll),
|
| 90 |
-
world_map_markdown(updated_coll),
|
| 91 |
-
updated_hist,
|
| 92 |
-
progress_markdown(updated_coll),
|
| 93 |
-
)
|
| 94 |
-
|
| 95 |
|
| 96 |
def pick_discovery(current, collection, history, position):
|
| 97 |
updated_coll, updated_current, updated_hist = pick_current(current, collection, history)
|
| 98 |
pos = _safe_pos(position)
|
| 99 |
-
return (
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
forest_scene(updated_current, updated_coll, pos),
|
| 103 |
-
game_status_markdown(updated_current, updated_coll, pos),
|
| 104 |
-
mushroom_card_from_state(updated_current),
|
| 105 |
-
dex_markdown(updated_coll),
|
| 106 |
-
world_map_markdown(updated_coll),
|
| 107 |
-
updated_hist,
|
| 108 |
-
progress_markdown(updated_coll),
|
| 109 |
-
)
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
def follow_story_whisper(current, collection, history, position):
|
| 113 |
-
updated_current, updated_hist = follow_whisper(current, collection, history)
|
| 114 |
-
pos = _safe_pos(position)
|
| 115 |
-
return (
|
| 116 |
-
updated_current,
|
| 117 |
-
forest_scene(updated_current, collection, pos),
|
| 118 |
-
game_status_markdown(updated_current, collection, pos),
|
| 119 |
-
mushroom_card_from_state(updated_current),
|
| 120 |
-
updated_hist,
|
| 121 |
-
)
|
| 122 |
-
|
| 123 |
|
| 124 |
def study_discovery(current, history, collection, position):
|
| 125 |
updated_current, updated_hist = study_current(current, history)
|
| 126 |
pos = _safe_pos(position)
|
| 127 |
-
return (
|
| 128 |
-
|
| 129 |
-
forest_scene(updated_current, collection, pos),
|
| 130 |
-
game_status_markdown(updated_current, collection, pos),
|
| 131 |
-
mushroom_card_from_state(updated_current),
|
| 132 |
-
updated_hist,
|
| 133 |
-
)
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
def move_player(position, direction, current, collection):
|
| 137 |
-
x, y = _safe_pos(position)
|
| 138 |
-
if direction == "north": y -= 1
|
| 139 |
-
elif direction == "south": y += 1
|
| 140 |
-
elif direction == "west": x -= 1
|
| 141 |
-
elif direction == "east": x += 1
|
| 142 |
-
pos = _safe_pos((x, y))
|
| 143 |
-
return pos, forest_scene(current, collection, pos), game_status_markdown(current, collection, pos)
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
def block_unsafe_eating(current, history):
|
| 147 |
-
return eat_current(current, history)
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
def open_play_tab():
|
| 151 |
-
return gr.update(selected="play")
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
def _safe_pos(position):
|
| 155 |
-
if position is None:
|
| 156 |
-
return START_POSITION
|
| 157 |
-
x, y = position
|
| 158 |
-
return (max(0, min(2, int(x))), max(0, min(2, int(y))))
|
| 159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
|
|
|
| 161 |
def build_app():
|
| 162 |
with gr.Blocks(title="Myco โ AI Forest Game", theme=gr.themes.Soft()) as demo:
|
|
|
|
| 163 |
gr.HTML("""
|
| 164 |
-
<
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
transition: opacity 0.15s ease !important;
|
| 173 |
-
}
|
| 174 |
-
.pending, .generating {
|
| 175 |
-
opacity: 0.85 !important;
|
| 176 |
-
background: transparent !important;
|
| 177 |
-
}
|
| 178 |
-
/* Hide the white overlay Gradio adds during updates */
|
| 179 |
-
.progress-level, .progress-level-inner {
|
| 180 |
-
display: none !important;
|
| 181 |
-
}
|
| 182 |
-
</style>
|
| 183 |
""")
|
| 184 |
|
| 185 |
-
# โโ State โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 186 |
current_mushroom = gr.State(None)
|
| 187 |
collection = gr.State([])
|
| 188 |
player_position = gr.State(START_POSITION)
|
| 189 |
|
| 190 |
-
# โโ Hero โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 191 |
gr.HTML(hero_markdown())
|
| 192 |
|
| 193 |
with gr.Tabs(selected="home") as tabs:
|
| 194 |
-
|
| 195 |
-
# โโ HOME โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 196 |
with gr.Tab("๐ Home", id="home"):
|
| 197 |
-
gr.Markdown(
|
| 198 |
-
gr.
|
| 199 |
-
|
| 200 |
-
"๐ Enter the Forest", variant="primary", size="lg"
|
| 201 |
-
)
|
| 202 |
-
gr.Markdown(f"*{hf_companion_status()}*")
|
| 203 |
-
|
| 204 |
-
# โโ PLAY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 205 |
with gr.Tab("๐ฎ Play", id="play"):
|
| 206 |
-
gr.HTML(game_intro_markdown())
|
| 207 |
-
|
| 208 |
-
# Forest scene + controls
|
| 209 |
-
scene = gr.HTML(
|
| 210 |
-
forest_scene(None, EMPTY_COLLECTION, START_POSITION),
|
| 211 |
-
elem_id="forest-scene",
|
| 212 |
-
)
|
| 213 |
-
|
| 214 |
with gr.Row():
|
| 215 |
-
with gr.Column(scale=1):
|
| 216 |
-
search_button = gr.Button("๐ฎ Search Clearing", variant="primary", size="lg")
|
| 217 |
-
with gr.Column(scale=1):
|
| 218 |
-
gr.Markdown("**Move Myco**")
|
| 219 |
-
with gr.Row():
|
| 220 |
-
gr.HTML("<div></div>")
|
| 221 |
-
north_button = gr.Button("โฌ๏ธ", size="sm")
|
| 222 |
-
gr.HTML("<div></div>")
|
| 223 |
-
with gr.Row():
|
| 224 |
-
west_button = gr.Button("โฌ
๏ธ", size="sm")
|
| 225 |
-
pick_button = gr.Button("๐ Pick", variant="primary", size="sm")
|
| 226 |
-
east_button = gr.Button("โก๏ธ", size="sm")
|
| 227 |
-
with gr.Row():
|
| 228 |
-
gr.HTML("<div></div>")
|
| 229 |
-
south_button = gr.Button("โฌ๏ธ", size="sm")
|
| 230 |
-
gr.HTML("<div></div>")
|
| 231 |
-
|
| 232 |
-
# Quest log
|
| 233 |
-
status = gr.Markdown(
|
| 234 |
-
game_status_markdown(None, EMPTY_COLLECTION, START_POSITION)
|
| 235 |
-
)
|
| 236 |
-
|
| 237 |
-
# Discovery card + action buttons + chat
|
| 238 |
-
with gr.Row(equal_height=True):
|
| 239 |
with gr.Column(scale=2):
|
| 240 |
-
gr.Markdown("### ๐ Current Discovery")
|
| 241 |
discovery = gr.Markdown(mushroom_card(None))
|
| 242 |
with gr.Row():
|
| 243 |
-
|
| 244 |
-
|
| 245 |
with gr.Row():
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
with gr.Column(scale=3):
|
| 250 |
-
gr.
|
| 251 |
-
chat = gr.Chatbot(
|
| 252 |
-
value=cast(Any, welcome_history()),
|
| 253 |
-
label="Myco",
|
| 254 |
-
height=400,
|
| 255 |
-
show_label=False,
|
| 256 |
-
)
|
| 257 |
with gr.Row():
|
| 258 |
-
prompt = gr.Textbox(
|
| 259 |
-
|
| 260 |
-
show_label=False,
|
| 261 |
-
scale=4,
|
| 262 |
-
lines=1,
|
| 263 |
-
)
|
| 264 |
-
ask_button = gr.Button("Ask ๐", variant="primary", scale=1)
|
| 265 |
|
| 266 |
-
|
| 267 |
-
|
| 268 |
with gr.Row():
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
)
|
| 289 |
-
|
| 290 |
-
ask_button.click(
|
| 291 |
-
ask_companion,
|
| 292 |
-
inputs=[prompt, chat, current_mushroom, collection, player_position],
|
| 293 |
-
outputs=[prompt, chat],
|
| 294 |
-
show_progress="hidden",
|
| 295 |
-
)
|
| 296 |
-
prompt.submit(
|
| 297 |
-
ask_companion,
|
| 298 |
-
inputs=[prompt, chat, current_mushroom, collection, player_position],
|
| 299 |
-
outputs=[prompt, chat],
|
| 300 |
-
show_progress="hidden",
|
| 301 |
-
)
|
| 302 |
-
|
| 303 |
-
for direction, button in [
|
| 304 |
-
("north", north_button), ("south", south_button),
|
| 305 |
-
("west", west_button), ("east", east_button),
|
| 306 |
-
]:
|
| 307 |
-
button.click(
|
| 308 |
-
move_player,
|
| 309 |
-
inputs=[player_position, gr.State(direction), current_mushroom, collection],
|
| 310 |
-
outputs=[player_position, scene, status],
|
| 311 |
-
show_progress="hidden",
|
| 312 |
-
)
|
| 313 |
-
|
| 314 |
-
study_button.click(
|
| 315 |
-
study_discovery,
|
| 316 |
-
inputs=[current_mushroom, chat, collection, player_position],
|
| 317 |
-
outputs=[current_mushroom, scene, status, discovery, chat],
|
| 318 |
-
)
|
| 319 |
-
collect_button.click(
|
| 320 |
-
collect_discovery,
|
| 321 |
-
inputs=[current_mushroom, collection, chat, player_position],
|
| 322 |
-
outputs=[collection, scene, status, dex, world_map, chat, progress],
|
| 323 |
-
)
|
| 324 |
-
pick_button.click(
|
| 325 |
-
pick_discovery,
|
| 326 |
-
inputs=[current_mushroom, collection, chat, player_position],
|
| 327 |
-
outputs=[collection, current_mushroom, scene, status, discovery, dex, world_map, chat, progress],
|
| 328 |
-
show_progress="hidden",
|
| 329 |
-
)
|
| 330 |
-
whisper_button.click(
|
| 331 |
-
follow_story_whisper,
|
| 332 |
-
inputs=[current_mushroom, collection, chat, player_position],
|
| 333 |
-
outputs=[current_mushroom, scene, status, discovery, chat],
|
| 334 |
-
)
|
| 335 |
-
eat_button.click(
|
| 336 |
-
block_unsafe_eating,
|
| 337 |
-
inputs=[current_mushroom, chat],
|
| 338 |
-
outputs=[chat],
|
| 339 |
-
)
|
| 340 |
|
| 341 |
demo.queue()
|
| 342 |
return demo
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Myco โ LLM-powered forest adventure (Atmospheric UI Edition)
|
| 3 |
+
"""
|
| 4 |
|
| 5 |
from typing import Any, cast
|
| 6 |
import gradio as gr
|
|
|
|
| 13 |
from game.state import welcome_history
|
| 14 |
from models.mushroom import Mushroom
|
| 15 |
from ui.renderers import (
|
| 16 |
+
dex_markdown, game_status_markdown, hero_markdown, home_forest_markdown,
|
| 17 |
+
mushroom_card, progress_markdown, world_map_markdown,
|
|
|
|
|
|
|
| 18 |
)
|
| 19 |
|
| 20 |
+
# โโ Constants โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 21 |
EMPTY_COLLECTION = None
|
| 22 |
START_POSITION = (1, 1)
|
| 23 |
|
| 24 |
+
# โโ New Atmospheric Forest View (No Grid) โโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 25 |
+
def forest_scene(current, collection, position):
|
| 26 |
+
"""Displays an immersive, non-grid view of your current location."""
|
| 27 |
+
px, py = _safe_pos(position)
|
| 28 |
+
|
| 29 |
+
# You can customize this HTML/CSS to show your forest lore or current environment
|
| 30 |
+
return f"""
|
| 31 |
+
<div style="
|
| 32 |
+
background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
|
| 33 |
+
padding: 30px;
|
| 34 |
+
border-radius: 16px;
|
| 35 |
+
border: 1px solid #3e3e5f;
|
| 36 |
+
text-align: center;
|
| 37 |
+
color: #e2e2e2;
|
| 38 |
+
box-shadow: 0 4px 15px rgba(0,0,0,0.3);
|
| 39 |
+
">
|
| 40 |
+
<h3 style="margin-top: 0; color: #00b4d8;">๐ฒ The Ancient Clearing</h3>
|
| 41 |
+
<p style="font-size: 1.1em; opacity: 0.9;">
|
| 42 |
+
You stand at coordinate <b>[{px}, {py}]</b>. The air is thick with the scent of damp earth and magic.
|
| 43 |
+
</p>
|
| 44 |
+
<div style="font-size: 50px; margin: 20px 0;">โจ</div>
|
| 45 |
+
<p style="font-size: 0.9em; color: #8a8aaf; font-family: monospace;">
|
| 46 |
+
Myco is waiting for your next move...
|
| 47 |
+
</p>
|
| 48 |
+
</div>
|
| 49 |
+
"""
|
| 50 |
+
|
| 51 |
+
# โโ Controller Functions โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 52 |
+
def _safe_pos(position):
|
| 53 |
+
if position is None: return START_POSITION
|
| 54 |
+
x, y = position
|
| 55 |
+
return (max(0, min(2, int(x))), max(0, min(2, int(y))))
|
| 56 |
|
| 57 |
def mushroom_card_from_state(current):
|
| 58 |
+
if current is None: return mushroom_card(None)
|
| 59 |
+
return mushroom_card(Mushroom.from_dict(current), current.get("clue"), current.get("secret"), current)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
# [Keeping your previous logic intact for compatibility]
|
| 62 |
def search_forest(collection, position):
|
| 63 |
mushroom, current, history = discover_mushroom(collection)
|
| 64 |
pos = _safe_pos(position)
|
| 65 |
+
return (forest_scene(current, collection, pos), game_status_markdown(current, collection, pos),
|
| 66 |
+
mushroom_card_from_state(current), current, history, dex_markdown(collection), progress_markdown(collection))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
def move_player(position, direction, collection):
|
| 69 |
+
x, y = _safe_pos(position)
|
| 70 |
+
if direction == "north": y -= 1
|
| 71 |
+
elif direction == "south": y += 1
|
| 72 |
+
elif direction == "west": x -= 1
|
| 73 |
+
elif direction == "east": x += 1
|
| 74 |
+
pos = _safe_pos((x, y))
|
| 75 |
+
|
| 76 |
+
mushroom, current, history = discover_mushroom(collection)
|
| 77 |
+
return (pos, forest_scene(current, collection, pos), game_status_markdown(current, collection, pos),
|
| 78 |
+
mushroom_card_from_state(current), current, history, dex_markdown(collection), progress_markdown(collection))
|
| 79 |
|
| 80 |
+
# (Other functions like ask_companion, collect_discovery, etc. remain the same as your previous version)
|
| 81 |
def ask_companion(message, history, current, collection, position):
|
| 82 |
return myco_reply(message, history, current, collection, position)
|
| 83 |
|
|
|
|
| 84 |
def collect_discovery(current, collection, history, position):
|
| 85 |
updated_coll, updated_hist = collect_current(current, collection, history)
|
| 86 |
pos = _safe_pos(position)
|
| 87 |
+
return (updated_coll, forest_scene(current, updated_coll, pos), game_status_markdown(current, updated_coll, pos),
|
| 88 |
+
dex_markdown(updated_coll), world_map_markdown(updated_coll), updated_hist, progress_markdown(updated_coll))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
def pick_discovery(current, collection, history, position):
|
| 91 |
updated_coll, updated_current, updated_hist = pick_current(current, collection, history)
|
| 92 |
pos = _safe_pos(position)
|
| 93 |
+
return (updated_coll, updated_current, forest_scene(updated_current, updated_coll, pos),
|
| 94 |
+
game_status_markdown(updated_current, updated_coll, pos), mushroom_card_from_state(updated_current),
|
| 95 |
+
dex_markdown(updated_coll), world_map_markdown(updated_coll), updated_hist, progress_markdown(updated_coll))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
def study_discovery(current, history, collection, position):
|
| 98 |
updated_current, updated_hist = study_current(current, history)
|
| 99 |
pos = _safe_pos(position)
|
| 100 |
+
return (updated_current, forest_scene(updated_current, collection, pos), game_status_markdown(updated_current, collection, pos),
|
| 101 |
+
mushroom_card_from_state(updated_current), updated_hist)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
+
def follow_story_whisper(current, collection, history, position):
|
| 104 |
+
updated_current, updated_hist = follow_whisper(current, collection, history)
|
| 105 |
+
pos = _safe_pos(position)
|
| 106 |
+
return (updated_current, forest_scene(updated_current, collection, pos), game_status_markdown(updated_current, collection, pos),
|
| 107 |
+
mushroom_card_from_state(updated_current), updated_hist)
|
| 108 |
|
| 109 |
+
# โโ App Builder โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 110 |
def build_app():
|
| 111 |
with gr.Blocks(title="Myco โ AI Forest Game", theme=gr.themes.Soft()) as demo:
|
| 112 |
+
# Keyboard Navigation JS preserved
|
| 113 |
gr.HTML("""
|
| 114 |
+
<script>
|
| 115 |
+
document.addEventListener('keydown', function(event) {
|
| 116 |
+
if (event.target.nodeName === 'INPUT' || event.target.nodeName === 'TEXTAREA') return;
|
| 117 |
+
const keyMap = { 'w': 'btn-north', 'W': 'btn-north', 'ArrowUp': 'btn-north', 'a': 'btn-west', 'A': 'btn-west', 'ArrowLeft': 'btn-west', 's': 'btn-south', 'S': 'btn-south', 'ArrowDown': 'btn-south', 'd': 'btn-east', 'D': 'btn-east', 'ArrowRight': 'btn-east', 'e': 'btn-pick', 'E': 'btn-pick', 'q': 'btn-study', 'Q': 'btn-study', 'c': 'btn-collect', 'C': 'btn-collect' };
|
| 118 |
+
const btn = document.getElementById(keyMap[event.key]);
|
| 119 |
+
if (btn) btn.click();
|
| 120 |
+
});
|
| 121 |
+
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
""")
|
| 123 |
|
|
|
|
| 124 |
current_mushroom = gr.State(None)
|
| 125 |
collection = gr.State([])
|
| 126 |
player_position = gr.State(START_POSITION)
|
| 127 |
|
|
|
|
| 128 |
gr.HTML(hero_markdown())
|
| 129 |
|
| 130 |
with gr.Tabs(selected="home") as tabs:
|
|
|
|
|
|
|
| 131 |
with gr.Tab("๐ Home", id="home"):
|
| 132 |
+
gr.Markdown(home_forest_markdown())
|
| 133 |
+
start_play_button = gr.Button("๐ Enter the Forest", variant="primary", size="lg")
|
| 134 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
with gr.Tab("๐ฎ Play", id="play"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
with gr.Column(scale=2):
|
|
|
|
| 138 |
discovery = gr.Markdown(mushroom_card(None))
|
| 139 |
with gr.Row():
|
| 140 |
+
study_btn = gr.Button("๐ Study (Q)", variant="secondary", elem_id="btn-study")
|
| 141 |
+
collect_btn = gr.Button("๐ Collect (C)", variant="secondary", elem_id="btn-collect")
|
| 142 |
with gr.Row():
|
| 143 |
+
whisper_btn = gr.Button("๐ Follow Whisper", variant="secondary", elem_id="btn-whisper")
|
| 144 |
+
eat_btn = gr.Button("๐ฝ๏ธ Eat?", variant="stop", elem_id="btn-eat")
|
| 145 |
+
|
| 146 |
with gr.Column(scale=3):
|
| 147 |
+
chat = gr.Chatbot(value=cast(Any, welcome_history()), label="Myco", height=400)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
with gr.Row():
|
| 149 |
+
prompt = gr.Textbox(placeholder="Ask Myco...", show_label=False)
|
| 150 |
+
ask_btn = gr.Button("Ask ๐", variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
+
status = gr.Markdown(game_status_markdown(None, EMPTY_COLLECTION, START_POSITION))
|
| 153 |
+
|
| 154 |
with gr.Row():
|
| 155 |
+
scene = gr.HTML(forest_scene(None, EMPTY_COLLECTION, START_POSITION))
|
| 156 |
+
with gr.Column():
|
| 157 |
+
search_btn = gr.Button("๐ฟ Inspect Spot", variant="secondary")
|
| 158 |
+
with gr.Row():
|
| 159 |
+
n_btn = gr.Button("โฌ๏ธ", size="sm", elem_id="btn-north")
|
| 160 |
+
w_btn = gr.Button("โฌ
๏ธ", size="sm", elem_id="btn-west")
|
| 161 |
+
p_btn = gr.Button("๐ Pick (E)", variant="primary", size="sm", elem_id="btn-pick")
|
| 162 |
+
e_btn = gr.Button("โก๏ธ", size="sm", elem_id="btn-east")
|
| 163 |
+
s_btn = gr.Button("โฌ๏ธ", size="sm", elem_id="btn-south")
|
| 164 |
+
|
| 165 |
+
# Event Wiring
|
| 166 |
+
start_play_button.click(lambda: gr.update(selected="play"), outputs=[tabs])
|
| 167 |
+
for dir, btn in [("north", n_btn), ("south", s_btn), ("west", w_btn), ("east", e_btn)]:
|
| 168 |
+
btn.click(move_player, inputs=[player_position, gr.State(dir), collection],
|
| 169 |
+
outputs=[player_position, scene, status, discovery, current_mushroom, chat, dex, progress])
|
| 170 |
+
search_btn.click(search_forest, inputs=[collection, player_position], outputs=[scene, status, discovery, current_mushroom, chat, dex, progress])
|
| 171 |
+
study_btn.click(study_discovery, inputs=[current_mushroom, chat, collection, player_position], outputs=[current_mushroom, scene, status, discovery, chat])
|
| 172 |
+
collect_btn.click(collect_discovery, inputs=[current_mushroom, collection, chat, player_position], outputs=[collection, scene, status, dex, world_map, chat, progress])
|
| 173 |
+
pick_btn.click(pick_discovery, inputs=[current_mushroom, collection, chat, player_position], outputs=[collection, current_mushroom, scene, status, discovery, dex, world_map, chat, progress])
|
| 174 |
+
ask_btn.click(ask_companion, inputs=[prompt, chat, current_mushroom, collection, player_position], outputs=[prompt, chat])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
demo.queue()
|
| 177 |
return demo
|
| 178 |
+
|