Spaces:
Sleeping

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

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. ui/renderers.py +374 -102
ui/renderers.py CHANGED
@@ -1,6 +1,4 @@
1
- """
2
- Myco โ€” LLM-powered forest adventure (Atmospheric UI Edition)
3
- """
4
 
5
  from typing import Any, cast
6
  import gradio as gr
@@ -13,165 +11,439 @@ from game.engine import (
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
 
1
+ """Gradio game UI for Myco โ€” LLM-powered forest adventure."""
 
 
2
 
3
  from typing import Any, cast
4
  import gradio as gr
 
11
  from game.state import welcome_history
12
  from models.mushroom import Mushroom
13
  from ui.renderers import (
14
+ dex_markdown,
15
+ game_status_markdown,
16
+ hero_markdown,
17
+ home_forest_markdown,
18
+ mushroom_card,
19
+ play_hook_markdown,
20
+ progress_markdown,
21
+ world_map_markdown,
22
  )
23
 
24
+ # Now your application will load successfully
25
+
26
  EMPTY_COLLECTION = None
27
  START_POSITION = (1, 1)
28
 
29
+ HOME_MARKDOWN = """
30
+ ## Welcome to the Myco forest
31
+
32
+ Myco is a tiny AI-powered forest game. Open **๐ŸŽฎ Play** to search for mushrooms,
33
+ visit **๐Ÿ“– MycoDex** to review your collection, and use **๐Ÿงญ Guide** for help.
34
+
35
+ **Goal:** solve one mystery โ€” why does Myco remember a forest that vanished before it was born?
36
+ Follow clues until the Impossible Mushroom blooms inside the MycoDex.
37
+ """
38
+
39
+ GUIDE_MARKDOWN = """
40
+ ## How to play
41
+
42
+ 1. Use **โฌ†๏ธโฌ‡๏ธโฌ…๏ธโžก๏ธ** or **WASD** keys to walk through the forest grid.
43
+ 2. Moving automatically triggers a new clearing encounter! Myco will immediately report what it senses.
44
+ 3. Choose your tactical action:
45
+ - **๐Ÿ” Study (Q)** โ€” Myco examines the mushroom and updates its magic field.
46
+ - **๐Ÿ„ Pick (E)** โ€” grab it as a game item. Poisonous picks = Game Over!
47
+ - **๐Ÿ“– Collect (C)** โ€” add it to the MycoDex for safe keeping and score.
48
+ - **๐ŸŒŒ Follow Whisper** โ€” reveal mystery fragments. Risky on unstudied mushrooms!
49
+ - **๐Ÿฝ๏ธ Eat?** โ€” Myco will stop you every time (for good reason).
50
+ 4. **Ask Myco** anything in the chat โ€” it knows the forest, the mystery, and the mushrooms.
51
+
52
+ **Controls:** W/A/S/D or Arrows = Move ยท Q = Study ยท E = Pick ยท C = Collect
53
+
54
+ **Scoring:** Common = 10 spores ยท Rare = 35 ยท Legendary = 100 ยท Poison = โˆ’25 + Game Over
55
+ """
56
+
57
+
58
+ def mushroom_card_from_state(current):
59
+ if current is None:
60
+ return mushroom_card(None)
61
+ return mushroom_card(
62
+ Mushroom.from_dict(current),
63
+ current.get("clue"),
64
+ current.get("secret"),
65
+ current,
66
+ )
67
+
68
+
69
  def forest_scene(current, collection, position):
70
+ """Renders an interactive, visually responsive CSS map representing the real game layout."""
71
  px, py = _safe_pos(position)
72
 
73
+ html = """
 
74
  <div style="
75
+ display: flex;
76
+ flex-direction: column;
77
+ align-items: center;
78
+ justify-content: center;
79
+ background: #111122;
80
+ padding: 20px;
81
+ border-radius: 12px;
82
+ border: 2px solid #2e2e4f;
83
+ margin-bottom: 15px;
84
  ">
85
+ <div style="color: #8a8aaf; font-weight: bold; margin-bottom: 12px; font-size: 13px; letter-spacing: 2px; font-family: monospace;">
86
+ ๐ŸŒฒ MYCO FOREST VIEWPORT (3 ร— 3) ๐ŸŒฒ
87
+ </div>
88
+ <div style="
89
+ display: grid;
90
+ grid-template-columns: repeat(3, 85px);
91
+ grid-template-rows: repeat(3, 85px);
92
+ gap: 10px;
93
+ ">
94
+ """
95
+
96
+ for y in range(3):
97
+ for x in range(3):
98
+ is_player = (x == px and y == py)
99
+
100
+ tile_style = """
101
+ width: 85px;
102
+ height: 85px;
103
+ background: #1b263b;
104
+ border-radius: 8px;
105
+ display: flex;
106
+ align-items: center;
107
+ justify-content: center;
108
+ font-size: 32px;
109
+ position: relative;
110
+ box-shadow: inset 0 0 12px rgba(0,0,0,0.6);
111
+ """
112
+
113
+ if is_player:
114
+ tile_style += "border: 3px solid #00b4d8; background: #22333b; box-shadow: 0 0 18px rgba(0,180,216,0.4);"
115
+ cell_content = "๐Ÿง™โ€โ™‚๏ธ"
116
+ else:
117
+ cell_content = "๐ŸŒฒ"
118
+
119
+ coord_label = f'<span style="position: absolute; bottom: 4px; right: 6px; font-size: 9px; color: #415a77; font-family: monospace;">{x},{y}</span>'
120
+ html += f'<div style="{tile_style}">{cell_content}{coord_label}</div>'
121
+
122
+ html += f"""
123
+ </div>
124
+ <div style="margin-top: 14px; color: #00b4d8; font-size: 12px; font-family: monospace; letter-spacing: 1px;">
125
+ Coordinates: [X: {px}, Y: {py}]
126
+ </div>
127
  </div>
128
  """
129
+ return html
130
 
 
 
 
 
 
131
 
 
 
 
 
 
132
  def search_forest(collection, position):
133
  mushroom, current, history = discover_mushroom(collection)
134
  pos = _safe_pos(position)
135
+ return (
136
+ forest_scene(current, collection, pos),
137
+ game_status_markdown(current, collection, pos),
138
+ mushroom_card_from_state(current),
139
+ current,
140
+ history,
141
+ dex_markdown(collection),
142
+ progress_markdown(collection),
143
+ )
144
 
 
 
 
 
 
 
 
 
 
 
 
145
 
 
146
  def ask_companion(message, history, current, collection, position):
147
  return myco_reply(message, history, current, collection, position)
148
 
149
+
150
  def collect_discovery(current, collection, history, position):
151
  updated_coll, updated_hist = collect_current(current, collection, history)
152
  pos = _safe_pos(position)
153
+ return (
154
+ updated_coll,
155
+ forest_scene(current, updated_coll, pos),
156
+ game_status_markdown(current, updated_coll, pos),
157
+ dex_markdown(updated_coll),
158
+ world_map_markdown(updated_coll),
159
+ updated_hist,
160
+ progress_markdown(updated_coll),
161
+ )
162
+
163
 
164
  def pick_discovery(current, collection, history, position):
165
  updated_coll, updated_current, updated_hist = pick_current(current, collection, history)
166
  pos = _safe_pos(position)
167
+ return (
168
+ updated_coll,
169
+ updated_current,
170
+ forest_scene(updated_current, updated_coll, pos),
171
+ game_status_markdown(updated_current, updated_coll, pos),
172
+ mushroom_card_from_state(updated_current),
173
+ dex_markdown(updated_coll),
174
+ world_map_markdown(updated_coll),
175
+ updated_hist,
176
+ progress_markdown(updated_coll),
177
+ )
178
 
 
 
 
 
 
179
 
180
  def follow_story_whisper(current, collection, history, position):
181
  updated_current, updated_hist = follow_whisper(current, collection, history)
182
  pos = _safe_pos(position)
183
+ return (
184
+ updated_current,
185
+ forest_scene(updated_current, collection, pos),
186
+ game_status_markdown(updated_current, collection, pos),
187
+ mushroom_card_from_state(updated_current),
188
+ updated_hist,
189
+ )
190
+
191
+
192
+ def study_discovery(current, history, collection, position):
193
+ updated_current, updated_hist = study_current(current, history)
194
+ pos = _safe_pos(position)
195
+ return (
196
+ updated_current,
197
+ forest_scene(updated_current, collection, pos),
198
+ game_status_markdown(updated_current, collection, pos),
199
+ mushroom_card_from_state(updated_current),
200
+ updated_hist,
201
+ )
202
+
203
+
204
+ def move_player(position, direction, collection):
205
+ """Calculates movement coordinates and instantly triggers a continuous gameplay search event loop."""
206
+ x, y = _safe_pos(position)
207
+ if direction == "north": y -= 1
208
+ elif direction == "south": y += 1
209
+ elif direction == "west": x -= 1
210
+ elif direction == "east": x += 1
211
+ pos = _safe_pos((x, y))
212
+
213
+ # Real Game Loop Mechanics: Moving handles exploration encounters automatically
214
+ mushroom, current, history = discover_mushroom(collection)
215
+ return (
216
+ pos,
217
+ forest_scene(current, collection, pos),
218
+ game_status_markdown(current, collection, pos),
219
+ mushroom_card_from_state(current),
220
+ current,
221
+ history,
222
+ dex_markdown(collection),
223
+ progress_markdown(collection),
224
+ )
225
+
226
+
227
+ def block_unsafe_eating(current, history):
228
+ return eat_current(current, history)
229
+
230
+
231
+ def open_play_tab():
232
+ return gr.update(selected="play")
233
+
234
+
235
+ def _safe_pos(position):
236
+ if position is None:
237
+ return START_POSITION
238
+ x, y = position
239
+ return (max(0, min(2, int(x))), max(0, min(2, int(y))))
240
+
241
 
 
242
  def build_app():
243
  with gr.Blocks(title="Myco โ€” AI Forest Game", theme=gr.themes.Soft()) as demo:
 
244
  gr.HTML("""
245
+ <style>
246
+ .gradio-container { background: #1a1a2e !important; }
247
+ .gr-html, iframe, .html-container {
248
+ transition: none !important;
249
+ animation: none !important;
250
+ }
251
+ /* Completely freeze component flickering layout shifts */
252
+ * {
253
+ transition: none !important;
254
+ }
255
+ .pending, .generating {
256
+ opacity: 1.0 !important;
257
+ background: transparent !important;
258
+ animation: none !important;
259
+ border: none !important;
260
+ box-shadow: none !important;
261
+ }
262
+ /* Completely clear default overlay panels */
263
+ .progress-level, .progress-level-inner {
264
+ display: none !important;
265
+ }
266
+ </style>
267
+
268
  <script>
269
+ document.addEventListener('keydown', function(event) {
270
+ // Keep keyboard hotkeys completely quiet if typing a query in the chatbox input
271
+ if (event.target.nodeName === 'INPUT' || event.target.nodeName === 'TEXTAREA') return;
272
+
273
+ const keyMap = {
274
+ 'w': 'btn-north', 'W': 'btn-north', 'ArrowUp': 'btn-north',
275
+ 'a': 'btn-west', 'A': 'btn-west', 'ArrowLeft': 'btn-west',
276
+ 's': 'btn-south', 'S': 'btn-south', 'ArrowDown': 'btn-south',
277
+ 'd': 'btn-east', 'D': 'btn-east', 'ArrowRight': 'btn-east',
278
+ 'e': 'btn-pick', 'E': 'btn-pick',
279
+ 'q': 'btn-study', 'Q': 'btn-study',
280
+ 'c': 'btn-collect', 'C': 'btn-collect'
281
+ };
282
+
283
+ const targetId = keyMap[event.key];
284
+ if (targetId) {
285
+ const btn = document.getElementById(targetId);
286
  if (btn) btn.click();
287
+ }
288
+ });
289
  </script>
290
  """)
291
 
292
+ # โ”€โ”€ State โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
293
  current_mushroom = gr.State(None)
294
  collection = gr.State([])
295
  player_position = gr.State(START_POSITION)
296
 
297
+ # โ”€โ”€ Hero header removed here โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
298
 
299
  with gr.Tabs(selected="home") as tabs:
300
+
301
+ # โ”€โ”€ HOME โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
302
  with gr.Tab("๐Ÿ  Home", id="home"):
303
+ gr.Markdown(HOME_MARKDOWN)
304
+ gr.HTML(home_forest_markdown())
305
+ start_play_button = gr.Button(
306
+ "๐Ÿ„ Enter the Forest", variant="primary", size="lg"
307
+ )
308
+ gr.Markdown(f"*{hf_companion_status()}*")
309
+
310
+ # โ”€โ”€ PLAY โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
311
  with gr.Tab("๐ŸŽฎ Play", id="play"):
312
+ # TOP: Discovery card + action buttons + chat
313
+ with gr.Row(equal_height=True):
314
  with gr.Column(scale=2):
315
+ gr.Markdown("### ๐Ÿ„ Current Discovery")
316
  discovery = gr.Markdown(mushroom_card(None))
317
  with gr.Row():
318
+ study_button = gr.Button("๐Ÿ” Study", variant="secondary", elem_id="btn-study")
319
+ collect_button = gr.Button("๐Ÿ“– Collect", variant="secondary", elem_id="btn-collect")
320
  with gr.Row():
321
+ whisper_button = gr.Button("๐ŸŒŒ Follow Whisper", variant="secondary", elem_id="btn-whisper")
322
+ eat_button = gr.Button("๐Ÿฝ๏ธ Eat?", variant="stop", elem_id="btn-eat")
323
+
324
  with gr.Column(scale=3):
325
+ gr.Markdown("### ๐Ÿ’ฌ Myco Chat")
326
+ chat = gr.Chatbot(
327
+ value=cast(Any, welcome_history()),
328
+ label="Myco",
329
+ height=400,
330
+ show_label=False,
331
+ )
332
  with gr.Row():
333
+ prompt = gr.Textbox(
334
+ placeholder="Ask Myco anything about the forest...",
335
+ show_label=False,
336
+ scale=4,
337
+ lines=1,
338
+ )
339
+ ask_button = gr.Button("Ask ๐Ÿ„", variant="primary", scale=1)
340
+
341
+ # MIDDLE: Quest log
342
+ status = gr.Markdown(
343
+ game_status_markdown(None, EMPTY_COLLECTION, START_POSITION)
344
+ )
345
 
346
+ # BOTTOM: Forest Map + Controls
 
347
  with gr.Row():
348
+ with gr.Column(scale=2):
349
+ scene = gr.HTML(
350
+ forest_scene(None, EMPTY_COLLECTION, START_POSITION),
351
+ elem_id="forest-scene",
352
+ )
353
+ with gr.Column(scale=1):
354
+ search_button = gr.Button("๐ŸŒฟ Inspect Current Spot", variant="secondary")
355
+ gr.Markdown("**Move Navigator (WASD / Arrows)**")
356
+ with gr.Row():
357
+ gr.HTML("<div></div>")
358
+ north_button = gr.Button("โฌ†๏ธ", size="sm", elem_id="btn-north")
359
+ gr.HTML("<div></div>")
360
  with gr.Row():
361
+ west_button = gr.Button("โฌ…๏ธ", size="sm", elem_id="btn-west")
362
+ pick_button = gr.Button("๐Ÿ„ Pick", variant="primary", size="sm", elem_id="btn-pick")
363
+ east_button = gr.Button("โžก๏ธ", size="sm", elem_id="btn-east")
364
+ with gr.Row():
365
+ gr.HTML("<div></div>")
366
+ south_button = gr.Button("โฌ‡๏ธ", size="sm", elem_id="btn-south")
367
+ gr.HTML("<div></div>")
368
+
369
+ # โ”€โ”€ MYCODEX โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
370
+ with gr.Tab("๐Ÿ“– MycoDex"):
371
+ with gr.Row():
372
+ progress = gr.Markdown(progress_markdown(EMPTY_COLLECTION))
373
+ dex = gr.Markdown(dex_markdown(EMPTY_COLLECTION))
374
+
375
+ # โ”€โ”€ WORLD MAP โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
376
+ with gr.Tab("๐Ÿ—บ๏ธ World Map"):
377
+ world_map = gr.HTML(world_map_markdown(EMPTY_COLLECTION))
378
+
379
+ # โ”€โ”€ GUIDE โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
380
+ with gr.Tab("๐Ÿงญ Guide"):
381
+ gr.Markdown(GUIDE_MARKDOWN)
382
+
383
+ # โ”€โ”€ Event wiring โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
384
+ start_play_button.click(open_play_tab, outputs=[tabs], show_progress="hidden")
385
+
386
+ search_button.click(
387
+ search_forest,
388
+ inputs=[collection, player_position],
389
+ outputs=[scene, status, discovery, current_mushroom, chat, dex, progress],
390
+ show_progress="hidden",
391
+ )
392
+
393
+ ask_button.click(
394
+ ask_companion,
395
+ inputs=[prompt, chat, current_mushroom, collection, player_position],
396
+ outputs=[prompt, chat],
397
+ show_progress="hidden",
398
+ )
399
+ prompt.submit(
400
+ ask_companion,
401
+ inputs=[prompt, chat, current_mushroom, collection, player_position],
402
+ outputs=[prompt, chat],
403
+ show_progress="hidden",
404
+ )
405
+
406
+ for direction, button in [
407
+ ("north", north_button), ("south", south_button),
408
+ ("west", west_button), ("east", east_button),
409
+ ]:
410
+ button.click(
411
+ move_player,
412
+ inputs=[player_position, gr.State(direction), collection],
413
+ outputs=[player_position, scene, status, discovery, current_mushroom, chat, dex, progress],
414
+ show_progress="hidden",
415
+ )
416
+
417
+ study_button.click(
418
+ study_discovery,
419
+ inputs=[current_mushroom, chat, collection, player_position],
420
+ outputs=[current_mushroom, scene, status, discovery, chat],
421
+ show_progress="hidden",
422
+ )
423
+ collect_button.click(
424
+ collect_discovery,
425
+ inputs=[current_mushroom, collection, chat, player_position],
426
+ outputs=[collection, scene, status, dex, world_map, chat, progress],
427
+ show_progress="hidden",
428
+ )
429
+ pick_button.click(
430
+ pick_discovery,
431
+ inputs=[current_mushroom, collection, chat, player_position],
432
+ outputs=[collection, current_mushroom, scene, status, discovery, dex, world_map, chat, progress],
433
+ show_progress="hidden",
434
+ )
435
+ whisper_button.click(
436
+ follow_story_whisper,
437
+ inputs=[current_mushroom, collection, chat, player_position],
438
+ outputs=[current_mushroom, scene, status, discovery, chat],
439
+ show_progress="hidden",
440
+ )
441
+ eat_button.click(
442
+ block_unsafe_eating,
443
+ inputs=[current_mushroom, chat],
444
+ outputs=[chat],
445
+ show_progress="hidden",
446
+ )
447
 
448
  demo.queue()
449
  return demo