Spaces:
Sleeping

byte-vortex commited on
Commit
84b873f
ยท
verified ยท
1 Parent(s): 1003d86

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. ui/renderers.py +111 -275
ui/renderers.py CHANGED
@@ -1,4 +1,6 @@
1
- """Gradio game UI for Myco โ€” LLM-powered forest adventure."""
 
 
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, forest_scene, game_intro_markdown,
15
- game_status_markdown, hero_markdown, home_forest_markdown,
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
- HOME_MARKDOWN = """
24
- ## Welcome to the Myco forest
25
-
26
- Myco is a tiny AI-powered forest game. Open **๐ŸŽฎ Play** to search for mushrooms,
27
- visit **๐Ÿ“– MycoDex** to review your collection, and use **๐Ÿงญ Guide** for help.
28
-
29
- **Goal:** solve one mystery โ€” why does Myco remember a forest that vanished before it was born?
30
- Follow clues until the Impossible Mushroom blooms inside the MycoDex.
31
- """
32
-
33
- GUIDE_MARKDOWN = """
34
- ## How to play
35
-
36
- 1. Go to **๐ŸŽฎ Play** and click **๐ŸŽฎ Search Clearing** to discover a mushroom.
37
- 2. **Myco (the AI) reacts** โ€” read what it senses about the mushroom.
38
- 3. Choose your action:
39
- - **๐Ÿ” Study** โ€” Myco examines the mushroom and updates its magic field.
40
- - **๐Ÿ„ Pick** โ€” grab it as a game item. Poisonous picks = Game Over!
41
- - **๐Ÿ“– Collect** โ€” add it to the MycoDex for safe keeping and score.
42
- - **๐ŸŒŒ Follow Whisper** โ€” reveal mystery fragments. Risky on unstudied mushrooms!
43
- - **๐Ÿฝ๏ธ Eat?** โ€” Myco will stop you every time (for good reason).
44
- 4. **Ask Myco** anything in the chat โ€” it knows the forest, the mystery, and the mushrooms.
45
- 5. Use **โฌ†๏ธโฌ‡๏ธโฌ…๏ธโžก๏ธ** to move through the 3ร—3 forest grid.
46
-
47
- **Scoring:** Common = 10 spores ยท Rare = 35 ยท Legendary = 100 ยท Poison = โˆ’25 + Game Over
48
-
49
- **Poisonous mushrooms:** Ghost Gill ยท Pepper Pixie ยท Ruby Knuckle ยท Clockwork Chanterelle
50
- """
51
-
 
 
 
52
 
53
  def mushroom_card_from_state(current):
54
- if current is None:
55
- return mushroom_card(None)
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
- forest_scene(current, collection, pos),
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
- updated_coll,
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
- updated_coll,
101
- updated_current,
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
- updated_current,
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
- <style>
165
- .gradio-container { background: #1a1a2e !important; }
166
- .gr-html, iframe, .html-container {
167
- transition: none !important;
168
- animation: none !important;
169
- }
170
- /* Prevent white flash on component updates */
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(HOME_MARKDOWN)
198
- gr.HTML(home_forest_markdown())
199
- start_play_button = gr.Button(
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
- study_button = gr.Button("๐Ÿ” Study", variant="secondary")
244
- collect_button = gr.Button("๐Ÿ“– Collect", variant="secondary")
245
  with gr.Row():
246
- whisper_button = gr.Button("๐ŸŒŒ Follow Whisper", variant="secondary")
247
- eat_button = gr.Button("๐Ÿฝ๏ธ Eat?", variant="stop")
248
-
249
  with gr.Column(scale=3):
250
- gr.Markdown("### ๐Ÿ’ฌ Myco Chat")
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
- placeholder="Ask Myco anything about the forest...",
260
- show_label=False,
261
- scale=4,
262
- lines=1,
263
- )
264
- ask_button = gr.Button("Ask ๐Ÿ„", variant="primary", scale=1)
265
 
266
- # โ”€โ”€ MYCODEX โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
267
- with gr.Tab("๐Ÿ“– MycoDex"):
268
  with gr.Row():
269
- progress = gr.Markdown(progress_markdown(EMPTY_COLLECTION))
270
- dex = gr.Markdown(dex_markdown(EMPTY_COLLECTION))
271
-
272
- # โ”€โ”€ WORLD MAP โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
273
- with gr.Tab("๐Ÿ—บ๏ธ World Map"):
274
- world_map = gr.HTML(world_map_markdown(EMPTY_COLLECTION))
275
-
276
- # โ”€โ”€ GUIDE โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
277
- with gr.Tab("๐Ÿงญ Guide"):
278
- gr.Markdown(GUIDE_MARKDOWN)
279
-
280
- # โ”€โ”€ Event wiring โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
281
- start_play_button.click(open_play_tab, outputs=[tabs])
282
-
283
- search_button.click(
284
- search_forest,
285
- inputs=[collection, player_position],
286
- outputs=[scene, status, discovery, current_mushroom, chat, dex, progress],
287
- show_progress="hidden",
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
+