Spaces:
Sleeping

byte-vortex commited on
Commit
5ba4a33
·
verified ·
1 Parent(s): d8024be

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. ui/renderers.py +423 -571
ui/renderers.py CHANGED
@@ -1,592 +1,444 @@
1
- """Markdown renderers for the Myco Gradio interface."""
2
 
3
- from html import escape
4
- from game.progression import (
5
- AREA_UNLOCKS, current_area, next_area, next_mystery,
6
- revealed_mysteries, unlocked_areas,
 
 
 
7
  )
8
- from game.state import CollectionState, EMPTY_DEX, MushroomState
9
  from models.mushroom import Mushroom
 
 
 
 
 
 
10
 
11
- POISONOUS_MUSHROOM_NAMES = {
12
- "Ghost Gill", "Pepper Pixie", "Ruby Knuckle", "Clockwork Chanterelle",
13
- }
14
-
15
- # ── Inline CSS + keyframes injected once into the scene ──────────────────────
16
- SCENE_STYLES = """
17
- <style>
18
- /* ── Base scene ── */
19
- .forest-scene {
20
- position: relative; isolation: isolate;
21
- overflow: hidden; min-height: 20rem;
22
- padding: 0.75rem; border-radius: 28px;
23
- background:
24
- radial-gradient(circle at 50% 72%, rgba(255,239,173,.26), transparent 8rem),
25
- radial-gradient(circle at 18% 24%, rgba(134,225,153,.22), transparent 10rem),
26
- linear-gradient(180deg,#123626 0%,#245c3c 54%,#523b20 100%);
27
- border: 1px solid rgba(225,255,209,.25);
28
- box-shadow: 0 18px 48px rgba(8,30,20,.26);
29
- color: #f9ffe9;
30
- }
31
-
32
- /* ── HUD bar ── */
33
- .scene-hud {
34
- position: relative; z-index: 3;
35
- display: flex; flex-wrap: wrap; gap: .4rem;
36
- padding: .5rem .75rem; border-radius: 999px;
37
- background: rgba(13,38,28,.72); backdrop-filter: blur(6px);
38
- font-size: .8rem; font-weight: 800;
39
- }
40
-
41
- /* ── Stage ── */
42
- .scene-stage {
43
- position: relative; height: 13rem;
44
- margin: .6rem 0;
45
- background:
46
- linear-gradient(transparent 62%, rgba(106,79,33,.55) 63%),
47
- radial-gradient(ellipse at bottom, rgba(190,255,180,.2), transparent 60%);
48
- border-radius: 22px; overflow: hidden;
49
- }
50
- .scene-stage span { position: absolute; line-height:1; }
51
-
52
- /* ── Trees / grass ── */
53
- .tree-left { left:6%; bottom:18%; font-size:5rem; filter:drop-shadow(0 8px 12px rgba(0,0,0,.28)); }
54
- .tree-right { right:7%; bottom:20%; font-size:4.75rem; filter:drop-shadow(0 8px 12px rgba(0,0,0,.28)); }
55
- .grass-one { left:26%; bottom:14%; font-size:2.4rem; }
56
- .grass-two { right:28%;bottom:16%; font-size:2.2rem; }
57
-
58
- /* ── Sparkles ── */
59
- .sparkle-one { left:34%; top:18%; font-size:1.8rem; animation:twinkle 1.8s ease-in-out infinite; }
60
- .sparkle-two { right:33%; top:24%; font-size:1.6rem; animation:twinkle 2.2s ease-in-out infinite reverse; }
61
- @keyframes twinkle {
62
- 0%,100%{opacity:.3;transform:scale(.85);}
63
- 50%{opacity:1;transform:scale(1.18);}
64
- }
65
-
66
- /* ── Myco player — position grid ── */
67
- .myco-player {
68
- font-size:4rem; z-index:2;
69
- transition: left .32s cubic-bezier(.34,1.56,.64,1), bottom .32s cubic-bezier(.34,1.56,.64,1);
70
- animation: myco-bob 2.4s ease-in-out infinite;
71
- filter:drop-shadow(0 6px 14px rgba(255,92,92,.28));
72
- }
73
- @keyframes myco-bob {
74
- 0%,100%{transform:translateY(0);}
75
- 50%{transform:translateY(-.45rem);}
76
- }
77
- .pos-0-0 .myco-player{left:14%;bottom:62%;}
78
- .pos-1-0 .myco-player{left:41%;bottom:62%;}
79
- .pos-2-0 .myco-player{left:67%;bottom:62%;}
80
- .pos-0-1 .myco-player{left:14%;bottom:36%;}
81
- .pos-1-1 .myco-player{left:41%;bottom:36%;}
82
- .pos-2-1 .myco-player{left:67%;bottom:36%;}
83
- .pos-0-2 .myco-player{left:14%;bottom:13%;}
84
- .pos-1-2 .myco-player{left:41%;bottom:13%;}
85
- .pos-2-2 .myco-player{left:67%;bottom:13%;}
86
-
87
- /* ── Mushroom sprite ── */
88
- .mushroom-sprite {
89
- right:33%; bottom:22%; font-size:3.6rem; z-index:2;
90
- filter:drop-shadow(0 6px 14px rgba(0,0,0,.3));
91
- }
92
-
93
- /* ── STATE: waiting (no mushroom) ── */
94
- .state-waiting .mushroom-sprite { opacity:0; }
95
-
96
- /* ── STATE: discovered — mushroom pops up, Myco runs toward it ── */
97
- .state-discovered .mushroom-sprite {
98
- animation: shroom-popup 0.7s cubic-bezier(.34,1.56,.64,1) both;
99
- }
100
- .state-discovered .myco-player {
101
- animation: myco-bob 2.4s ease-in-out infinite,
102
- myco-run-in 0.6s cubic-bezier(.34,1.56,.64,1) both;
103
- }
104
- @keyframes shroom-popup {
105
- 0% { opacity:0; transform:translateY(3rem) scale(.2); }
106
- 60% { opacity:1; transform:translateY(-.4rem) scale(1.18); }
107
- 100% { opacity:1; transform:translateY(0) scale(1); }
108
- }
109
- @keyframes myco-run-in {
110
- 0% { transform:translateX(-3rem) scaleX(-1); }
111
- 100% { transform:translateX(0) scaleX(1); }
112
- }
113
-
114
- /* ── STATE: picked — mushroom flies up and disappears ── */
115
- .state-picked .mushroom-sprite {
116
- animation: shroom-catch 0.55s cubic-bezier(.34,1.56,.64,1) both;
117
- }
118
- .state-picked .myco-player {
119
- animation: myco-bob 2.4s ease-in-out infinite,
120
- myco-catch-jump 0.55s ease both;
121
- }
122
- @keyframes shroom-catch {
123
- 0% { opacity:1; transform:translateY(0) scale(1); }
124
- 40% { opacity:1; transform:translateY(-2.5rem) scale(1.3) rotate(15deg); }
125
- 100% { opacity:0; transform:translateY(-5rem) scale(.2) rotate(40deg); }
126
- }
127
- @keyframes myco-catch-jump {
128
- 0%,100%{ transform:translateY(0); }
129
- 40% { transform:translateY(-1.4rem) scale(1.1); }
130
- }
131
-
132
- /* ── STATE: danger (poison, not yet picked) ── */
133
- .state-danger .mushroom-sprite {
134
- animation: shroom-popup 0.7s cubic-bezier(.34,1.56,.64,1) both,
135
- poison-pulse 1.2s ease-in-out infinite 0.7s;
136
- filter: drop-shadow(0 0 18px rgba(255,62,91,.9));
137
- }
138
- .state-danger .myco-player {
139
- animation: myco-bob 2.4s ease-in-out infinite,
140
- myco-recoil 0.5s ease both;
141
- }
142
- @keyframes poison-pulse {
143
- 0%,100%{ filter:drop-shadow(0 0 10px rgba(255,62,91,.6)); }
144
- 50% { filter:drop-shadow(0 0 28px rgba(255,62,91,1)); }
145
- }
146
- @keyframes myco-recoil {
147
- 0% { transform:translateX(0); }
148
- 30% { transform:translateX(-1.2rem); }
149
- 60% { transform:translateX(.4rem); }
150
- 100%{ transform:translateX(0); }
151
- }
152
-
153
- /* ── STATE: game over ── */
154
- .state-game-over .forest-scene,
155
- .state-game-over {
156
- animation: screen-shake .45s ease both;
157
- background:
158
- radial-gradient(circle at 50% 72%, rgba(255,62,91,.35), transparent 8rem),
159
- linear-gradient(180deg,#3b0a0a 0%,#6b1a1a 54%,#2a0a0a 100%) !important;
160
- }
161
- .state-game-over .mushroom-sprite {
162
- animation: shroom-explode .6s ease both;
163
- filter: drop-shadow(0 0 24px rgba(255,62,91,1));
164
- }
165
- .state-game-over .myco-player {
166
- animation: myco-fall .6s ease both;
167
- }
168
- @keyframes screen-shake {
169
- 0%,100%{ transform:translateX(0); }
170
- 20% { transform:translateX(-8px); }
171
- 40% { transform:translateX(8px); }
172
- 60% { transform:translateX(-5px); }
173
- 80% { transform:translateX(5px); }
174
- }
175
- @keyframes shroom-explode {
176
- 0% { transform:scale(1) rotate(0); opacity:1; }
177
- 50% { transform:scale(1.8) rotate(20deg); opacity:.8; }
178
- 100%{ transform:scale(0) rotate(90deg); opacity:0; }
179
- }
180
- @keyframes myco-fall {
181
- 0% { transform:rotate(0) translateY(0); opacity:1; }
182
- 100%{ transform:rotate(-90deg) translateY(2rem); opacity:.4; }
183
- }
184
-
185
- /* ── Rarity glows ── */
186
- .rarity-rare .mushroom-sprite { filter:drop-shadow(0 0 18px rgba(138,220,255,.9)); }
187
- .rarity-legendary .mushroom-sprite{ filter:drop-shadow(0 0 28px rgba(255,215,0,1)); animation:legendary-pulse 1s ease-in-out infinite 0.7s; }
188
- @keyframes legendary-pulse {
189
- 0%,100%{ filter:drop-shadow(0 0 18px rgba(255,215,0,.7)); transform:scale(1); }
190
- 50% { filter:drop-shadow(0 0 36px rgba(255,215,0,1)); transform:scale(1.1); }
191
- }
192
-
193
- /* ── Mini map grid ── */
194
- .forest-map {
195
- display:grid; grid-template-columns:repeat(3,1fr);
196
- gap:.3rem; margin:.4rem auto .6rem;
197
- max-width:9rem; padding:.4rem;
198
- border:1px solid rgba(255,255,255,.18); border-radius:14px;
199
- background:rgba(13,38,28,.58);
200
- }
201
- .map-tile {
202
- display:grid; min-height:1.7rem; place-items:center;
203
- border-radius:8px; background:rgba(255,255,255,.1); font-weight:900;
204
- }
205
- .map-tile.active { background:rgba(255,224,138,.92); color:#3d2c00!important; }
206
-
207
- /* ── Caption ── */
208
- .scene-caption {
209
- display:flex; justify-content:space-between; gap:.6rem;
210
- padding:.55rem .8rem; border-radius:14px;
211
- background:rgba(13,38,28,.68); backdrop-filter:blur(6px);
212
- align-items:center;
213
- }
214
- .scene-caption span { color:#d9f4d4; }
215
-
216
- /* ── Score burst ── */
217
- .score-burst {
218
- margin:.65rem auto 0; max-width:520px;
219
- padding:.5rem .85rem; border-radius:999px;
220
- background:rgba(255,224,112,.18); border:1px solid rgba(255,244,190,.36);
221
- color:#fff7d6; font-weight:900; text-align:center;
222
- animation:score-pop .56s ease both;
223
- }
224
- @keyframes score-pop {
225
- 0%{transform:scale(.92);opacity:0;}
226
- 45%{transform:scale(1.06);opacity:1;}
227
- 100%{transform:scale(1);opacity:1;}
228
- }
229
- .state-game-over .score-burst {
230
- background:rgba(130,0,30,.45); border-color:rgba(255,120,140,.55);
231
- }
232
-
233
- /* ── Story moment ── */
234
- .story-moment {
235
- margin:.75rem auto 0; max-width:760px;
236
- padding:.8rem 1rem; border:1px solid rgba(255,234,166,.3);
237
- border-radius:18px; background:rgba(25,18,45,.72);
238
- color:#fff7d6; box-shadow:0 0 24px rgba(165,111,255,.22);
239
- }
240
- .story-moment strong,.story-moment span { display:block; }
241
- .story-moment span { margin-top:.2rem; color:#f6e7b2; }
242
-
243
- /* ── Suppress Gradio white flash ── */
244
- .generating .forest-scene, .pending .forest-scene { opacity:.88!important; }
245
- .progress-level,.progress-level-inner { display:none!important; }
246
- div.gradio-html { background:transparent!important; }
247
- .wrap.default.pending,.wrap.default.generating { background:transparent!important; }
248
- </style>
249
- """
250
 
251
- def hero_markdown() -> str:
252
- return """
253
- <div class="myco-hero">
254
- <div class="myco-mascot">🍄</div>
255
- <div>
256
- <p class="eyebrow">Tiny AI forest game</p>
257
- <h1>Myco</h1>
258
- <p>Follow an AI mushroom companion through a glowing forest. Every discovery starts with Myco's intuition.</p>
259
- </div>
260
- </div>
261
- """
262
 
263
- def home_forest_markdown() -> str:
264
- return """
265
- <div class="home-forest-postcard" aria-label="Animated Myco forest postcard">
266
- <div class="home-sky">
267
- <span class="home-milky-way" title="Milky Way">🌌</span>
268
- <span class="home-star star-one">✨</span>
269
- <span class="home-star star-two">✦</span>
270
- <span class="home-star star-three">✧</span>
271
- </div>
272
- <div class="home-forest-floor">
273
- <span class="home-tree left">🌲</span>
274
- <span class="home-grass grass-left">🌿</span>
275
- <span class="home-myco" title="Myco">🍄</span>
276
- <span class="home-brown-mushroom" title="Brown mushroom">🍄‍🟫</span>
277
- <span class="home-grass grass-right">🍃</span>
278
- <span class="home-tree right">🌳</span>
279
- <span class="home-moon">🌖</span>
280
- </div>
281
- <p><strong>The Milky Way is awake.</strong> Myco hears a brown mushroom whispering your first clue.</p>
282
- <span class="home-whisper">"Tap Play. Let's find what the forest is hiding."</span>
283
- </div>
284
  """
285
 
286
- def play_hook_markdown() -> str:
287
- return """
288
- <div class="play-hook">
289
- <p class="eyebrow">Mission</p>
290
- <h2>Goal: follow clues until Myco remembers the Impossible Mushroom.</h2>
291
- <div class="hook-steps">
292
- <span>1 · Move through the forest</span>
293
- <span>2 · Search Clearing — mushroom pops up!</span>
294
- <span>3 · Myco reacts · Pick, Study, or Follow Whisper</span>
295
- </div>
296
- <p>Every clue advances one mystery. Follow whispers to reveal why the MycoDex is regrowing a forest that vanished.</p>
297
- </div>
 
 
 
 
298
  """
299
 
300
- def forest_scene(
301
- current: MushroomState | None,
302
- collection: CollectionState | None,
303
- position: tuple[int, int] | None = None,
304
- ) -> str:
305
- count = len(_safe_collection(collection))
306
- area = current_area(count)
307
- pos_x, pos_y = _safe_position(position)
308
- pos_cls = f"pos-{pos_x}-{pos_y}"
309
 
 
310
  if current is None:
311
- mushroom_name = "Hidden mushroom"
312
- rarity = "common"
313
- sprite = "✨"
314
- status = "The moss is listening. Click Search Clearing to wake the forest."
315
- omen = "Myco is waiting to sense the first spore."
316
- event_label = "🌌 Dreaming Forest"
317
- encounter = "The next clearing may reveal a memory, creature, or poison omen."
318
- mystery_label = "The Wrong Memory"
319
- score_total = "0"
320
- health = "3"
321
- reward_text = "Search a clearing to score spores."
322
- state_cls = "state-waiting"
323
- else:
324
- mushroom_name = current.get("name", "Mystery mushroom")
325
- rarity = current.get("rarity", "Common").lower()
326
- sprite = "🍄‍🟫"
327
- game_over = current.get("game_over") == "Yes"
328
- studied = current.get("studied") == "Yes"
329
- event_label = f"{current.get('event_emoji','✨')} {current.get('event_title','Strange Omen')}"
330
- encounter = current.get("encounter", "The forest waits for Myco's reaction.")
331
- mystery_label = current.get("mystery_title", "The Wrong Memory")
332
- score_total = current.get("score_total", "0")
333
- health = current.get("health", "3")
334
- reward_text = current.get("reward_text", "Decide whether to risk the pickup.")
335
- state_cls = _scene_state_class(current)
336
- status = f"A {rarity} {mushroom_name} breaks through the moss!"
337
- if game_over:
338
- status = f"💀 GAME OVER: {mushroom_name} was poisonous!"
339
- omen = "New field note unlocked." if studied else "Ask Myco what the forest is hiding."
340
- if current.get("picked") == "Yes":
341
- omen = "✅ Picked! Move to the next clearing."
342
- if game_over:
343
- omen = "Press Search Clearing to start a new run."
344
-
345
- # Unique key forces browser to re-run CSS animations on every render
346
- import time
347
- anim_key = str(int(time.time() * 1000))[-6:]
348
-
349
- return f'''{SCENE_STYLES}
350
- <div class="forest-scene rarity-{escape(rarity)} {pos_cls} {state_cls}" data-key="{anim_key}">
351
- <div class="scene-hud">
352
- <span>🧭 {escape(area.name)}</span>
353
- <span>🎮 ({pos_x+1},{pos_y+1})</span>
354
- <span>📖 {count} found</span>
355
- <span>⭐ {escape(score_total)}</span>
356
- <span>❤️ {escape(health)}/3</span>
357
- <span>{escape(event_label)}</span>
358
- <span>🧩 {escape(mystery_label)}</span>
359
- </div>
360
-
361
- <div class="scene-stage" aria-label="Magical forest scene">
362
- <span class="tree tree-left">🌲</span>
363
- <span class="tree tree-right">🌳</span>
364
- <span class="grass grass-one">🌿</span>
365
- <span class="grass grass-two">🍃</span>
366
- <span class="myco-player" title="Myco">🍄</span>
367
- <span class="mushroom-sprite" title="{escape(mushroom_name)}">{sprite if current else "✨"}</span>
368
- <span class="sparkle sparkle-one">✨</span>
369
- <span class="sparkle sparkle-two">✦</span>
370
- </div>
371
-
372
- <div class="forest-map" aria-label="Forest grid">
373
- {_movement_tiles(pos_x, pos_y)}
374
- </div>
375
-
376
- <div class="scene-caption">
377
- <strong>{escape(status)}</strong>
378
- <span>{escape(omen)}</span>
379
- </div>
380
- <div class="score-burst" aria-live="polite">{escape(reward_text)}</div>
381
- <div class="story-moment">
382
- <strong>{escape(event_label)}</strong>
383
- <span>{escape(encounter)}</span>
384
- </div>
385
- </div>
386
- '''
387
-
388
- def _safe_position(position):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389
  if position is None:
390
- return (1, 1)
391
  x, y = position
392
  return (max(0, min(2, int(x))), max(0, min(2, int(y))))
393
 
394
- def _movement_tiles(active_x, active_y):
395
- tiles = []
396
- for y in range(3):
397
- for x in range(3):
398
- active = " active" if (x, y) == (active_x, active_y) else ""
399
- icon = "🍄" if active else "·"
400
- tiles.append(f'<span class="map-tile{active}">{icon}</span>')
401
- return "".join(tiles)
402
-
403
- def _scene_state_class(current):
404
- if current.get("game_over") == "Yes":
405
- return "state-game-over"
406
- if current.get("picked") == "Yes":
407
- return "state-picked"
408
- if current.get("poison") == "Yes":
409
- return "state-danger"
410
- return "state-discovered"
411
-
412
- def game_status_markdown(
413
- current: MushroomState | None,
414
- collection: CollectionState | None,
415
- position: tuple[int, int] | None = None,
416
- ) -> str:
417
- count = len(_safe_collection(collection))
418
- pos_x, pos_y = _safe_position(position)
419
- active_mystery = next_mystery(count)
420
- mystery_line = _mystery_goal_line(active_mystery, count)
421
 
422
- if current is None:
423
- objective = "Goal: solve **one mystery** — why does Myco remember a vanished forest?"
424
- discovery = "No active discovery yet. Move Myco, then Search Clearing."
425
- ai_job = "Myco's job: notice clues you would miss alone."
426
- event = "**Event:** waiting for the first omen"
427
- clue_line = mystery_line
428
- thread_line= "**Mystery thread:** The Wrong Memory — search the first clearing."
429
- bloom_line = f"**Impossible bloom:** {_mystery_bloom_meter(count)}"
430
- score_line = "**Score:** 0 spores · **Health:** 3/3"
431
- else:
432
- name = current.get("name", "Mystery mushroom")
433
- studied = current.get("studied") == "Yes"
434
- next_step= "Collect it to preserve the clue" if studied else "Ask Myco, then Study or Follow Whisper"
435
- if current.get("game_over") == "Yes":
436
- objective = "**💀 GAME OVER** — press **Search Clearing** to start a new run."
437
- elif current.get("picked") == "Yes":
438
- objective = "Current objective: **move to the next clearing and search again**."
439
- else:
440
- objective = f"Current objective: **{next_step}**."
441
- bloom_line = f"**Impossible bloom:** {_mystery_bloom_meter(count)}"
442
- score_line = (
443
- f"**Score:** {current.get('score_total','0')} spores · "
444
- f"**Health:** {current.get('health','3')}/3 · "
445
- f"**Last:** {current.get('reward_text','—')}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446
  )
447
- discovery = f"Active discovery: **{name}** · Rarity: **{current.get('rarity','Unknown')}**"
448
- event = f"**Event:** {current.get('event_emoji','✨')} {current.get('event_title','Strange Omen')}"
449
- clue_line = f"**Clue:** {current.get('clue','Myco is still listening.')}"
450
- thread_line = (
451
- f"**Mystery thread:** {current.get('mystery_title','The Wrong Memory')} — "
452
- f"Next: {current.get('mystery_next','follow the whisper.')}"
453
  )
454
- ai_job = "Myco's job: interpret clues, warn you away from danger, make discoveries feel alive."
455
-
456
- return "\n".join((
457
- "### 🎮 Quest Log",
458
- f"**MycoDex:** {count} discoveries · **Map:** ({pos_x+1},{pos_y+1})",
459
- discovery, objective, score_line, bloom_line,
460
- event, clue_line, thread_line, mystery_line, ai_job,
461
- ))
462
-
463
- def _mystery_bloom_meter(count):
464
- filled = max(0, min(5, count))
465
- petals = "".join("🌕" if i < filled else "🌑" for i in range(5))
466
- if filled >= 5:
467
- return f"{petals} Impossible Bloom visible"
468
- return f"{petals} {5-filled} clue-whispers remain"
469
-
470
- def mushroom_card(
471
- mushroom: Mushroom | None,
472
- clue: str | None = None,
473
- secret: str | None = None,
474
- state: MushroomState | None = None,
475
- ) -> str:
476
- if mushroom is None:
477
- return "### 🌲 Forest Clearing\nClick **Search Clearing** — watch Myco run toward the mushroom!"
478
- s = state or {}
479
- poison = mushroom.name in POISONOUS_MUSHROOM_NAMES
480
- poison_warning = "\n> ⚠️ **Myco senses danger — do NOT pick this without studying first!**" if poison else ""
481
- return "\n".join((
482
- f"### 🍄‍🟫 {mushroom.name}",
483
- f"**{mushroom.rarity} discovery** · found near **{mushroom.habitat}**",
484
- f"> {mushroom.lore}",
485
- poison_warning,
486
- "",
487
- f"* **Edible:** {mushroom.edible}",
488
- f"* **Magic:** {mushroom.magic}",
489
- f"* **Danger:** {mushroom.danger}",
490
- f"* **Value:** {_mushroom_value_label(mushroom.rarity)}",
491
- f"* **Poison risk:** {_poison_risk_label(mushroom.name)}",
492
- f"* **Event:** {s.get('event_emoji','✨')} {s.get('event_title','Strange Omen')}",
493
- f"* **Mystery:** {s.get('mystery_title','The Wrong Memory')}",
494
- f"* **Clue:** {clue or 'Study with Myco to reveal the clue.'}",
495
- f"* **Secret:** {secret or 'Collect it to see how the MycoDex reacts.'}",
496
- ))
497
-
498
- def _mushroom_value_label(rarity):
499
- if rarity == "Legendary": return "100 spores"
500
- if rarity == "Rare": return "35 spores + special discovery"
501
- return "10 spores"
502
-
503
- def _poison_risk_label(name):
504
- return "⚠️ POISONOUS — Game Over if picked!" if name in POISONOUS_MUSHROOM_NAMES else "No obvious poison"
505
-
506
- def world_map_markdown(collection: CollectionState | None) -> str:
507
- count = len(_safe_collection(collection))
508
- cards = []
509
- for area in AREA_UNLOCKS:
510
- unlocked = count >= area.required_discoveries
511
- state = "unlocked" if unlocked else "locked"
512
- badge = "✅ Unlocked" if unlocked else f"🔒 {area.required_discoveries - count} away"
513
- cards.append("\n".join((
514
- f'<div class="map-card {state}">',
515
- ' <div class="map-card-top">',
516
- f' <strong>{escape(area.name)}</strong><span>{badge}</span>',
517
- ' </div>',
518
- f' <p>{escape(area.description)}</p>',
519
- '</div>',
520
- )))
521
- secrets = tuple(_secret_badge(t.name, count >= t.required_discoveries) for t in revealed_mysteries(count))
522
- if not secrets:
523
- secrets = (_secret_badge("First Spore", False),)
524
- return "\n".join((
525
- '<div class="world-map-panel">',
526
- ' <div class="world-map-header"><p class="eyebrow">World Map</p>',
527
- ' <h2>Forest Atlas</h2>',
528
- f' <p>{count} discoveries logged.</p></div>',
529
- f' <div class="achievement-row">{"".join(secrets)}</div>',
530
- f' <div class="map-grid">{"".join(cards)}</div>',
531
- '</div>',
532
- ))
533
-
534
- def _secret_badge(label, unlocked):
535
- state = "earned" if unlocked else "pending"
536
- icon = "🔎" if unlocked else "◇"
537
- return f'<span class="achievement {state}">{icon} {escape(label)}</span>'
538
-
539
- def dex_markdown(collection: CollectionState | None) -> str:
540
- current_collection = _safe_collection(collection)
541
- if not current_collection:
542
- return EMPTY_DEX
543
- rows = ["### 📖 MycoDex", ""]
544
- for entry in current_collection:
545
- rows.append(
546
- f"* 🍄 **{entry['name']}** — {entry['rarity']} — {entry['habitat']} "
547
- f"— clue: {entry.get('clue','not studied yet')}"
548
  )
549
- return "\n".join(rows)
550
-
551
- def _safe_collection(collection):
552
- return list(collection or [])
553
-
554
- def progress_markdown(collection: CollectionState | None) -> str:
555
- count = len(_safe_collection(collection))
556
- active_area = current_area(count)
557
- upcoming_area = next_area(count)
558
- unlocked_names= ", ".join(a.name for a in unlocked_areas(count))
559
- rows = [
560
- "### ✨ Forest Progress",
561
- f"**MycoDex discoveries:** {count}",
562
- f"**Current area:** {active_area.name} — {active_area.description}",
563
- f"**Unlocked:** {unlocked_names}",
564
- ]
565
- upcoming_mystery = next_mystery(count)
566
- if upcoming_area:
567
- rows.append(f"**Next area:** {upcoming_area.required_discoveries - count} more to unlock **{upcoming_area.name}**.")
568
- else:
569
- rows.append(f"**All areas visible:** You reached **{AREA_UNLOCKS[-1].name}**.")
570
- if upcoming_mystery:
571
- rows.append(f"**Next secret:** {upcoming_mystery.required_discoveries - count} more to reveal **{upcoming_mystery.name}**.")
572
- else:
573
- rows.append("**All current secrets found.** Myco thinks the Elder is watching kindly.")
574
- return "\n\n".join(rows)
575
-
576
- def _mystery_goal_line(active_mystery, count):
577
- if active_mystery is None:
578
- return "**Mystery:** Every known clue is awake. Keep exploring for rare surprises."
579
- remaining = active_mystery.required_discoveries - count
580
- return f"**Mystery:** {remaining} clue discoveries until **{active_mystery.name}** — {active_mystery.clue}"
581
-
582
- def game_intro_markdown() -> str:
583
- return """
584
- <div style="text-align:center;margin-bottom:.75rem;">
585
- <h3>🌲 The Deep Forest</h3>
586
- <p style="color:#666;font-size:.9em;">
587
- You step into the glowing undergrowth. Myco hops off your shoulder, its cap faintly pulsing.<br>
588
- Click <strong>Search Clearing</strong> — watch Myco run toward whatever pops up.
589
- </p>
590
- </div>
591
- """
 
 
592
 
 
1
+ """Gradio game UI for Myco — LLM-powered forest adventure."""
2
 
3
+ from typing import Any, cast
4
+ import gradio as gr
5
+
6
+ from game.engine import (
7
+ collect_current, discover_mushroom, eat_current,
8
+ follow_whisper, hf_companion_status, myco_reply,
9
+ pick_current, study_current,
10
  )
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, 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. Use **⬆️⬇️⬅️➡️** or **WASD** keys to walk through the forest grid.
37
+ 2. Moving automatically triggers a new clearing encounter! Myco will immediately report what it senses.
38
+ 3. Choose your tactical action:
39
+ - **🔍 Study (Q)** — Myco examines the mushroom and updates its magic field.
40
+ - **🍄 Pick (E)** — grab it as a game item. Poisonous picks = Game Over!
41
+ - **📖 Collect (C)** — 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
+
46
+ **Controls:** W/A/S/D or Arrows = Move · Q = Study · E = Pick · C = Collect
47
+
48
+ **Scoring:** Common = 10 spores · Rare = 35 · Legendary = 100 · Poison = −25 + Game Over
49
  """
50
 
 
 
 
 
 
 
 
 
 
51
 
52
+ def mushroom_card_from_state(current):
53
  if current is None:
54
+ return mushroom_card(None)
55
+ return mushroom_card(
56
+ Mushroom.from_dict(current),
57
+ current.get("clue"),
58
+ current.get("secret"),
59
+ current,
60
+ )
61
+
62
+
63
+ def forest_scene(current, collection, position):
64
+ """Renders an interactive, visually responsive CSS map representing the real game layout."""
65
+ px, py = _safe_pos(position)
66
+
67
+ html = """
68
+ <div style="
69
+ display: flex;
70
+ flex-direction: column;
71
+ align-items: center;
72
+ justify-content: center;
73
+ background: #111122;
74
+ padding: 20px;
75
+ border-radius: 12px;
76
+ border: 2px solid #2e2e4f;
77
+ margin-bottom: 15px;
78
+ ">
79
+ <div style="color: #8a8aaf; font-weight: bold; margin-bottom: 12px; font-size: 13px; letter-spacing: 2px; font-family: monospace;">
80
+ 🌲 MYCO FOREST VIEWPORT (3 × 3) 🌲
81
+ </div>
82
+ <div style="
83
+ display: grid;
84
+ grid-template-columns: repeat(3, 85px);
85
+ grid-template-rows: repeat(3, 85px);
86
+ gap: 10px;
87
+ ">
88
+ """
89
+
90
+ for y in range(3):
91
+ for x in range(3):
92
+ is_player = (x == px and y == py)
93
+
94
+ tile_style = """
95
+ width: 85px;
96
+ height: 85px;
97
+ background: #1b263b;
98
+ border-radius: 8px;
99
+ display: flex;
100
+ align-items: center;
101
+ justify-content: center;
102
+ font-size: 32px;
103
+ position: relative;
104
+ box-shadow: inset 0 0 12px rgba(0,0,0,0.6);
105
+ """
106
+
107
+ if is_player:
108
+ tile_style += "border: 3px solid #00b4d8; background: #22333b; box-shadow: 0 0 18px rgba(0,180,216,0.4);"
109
+ cell_content = "🧙‍♂️"
110
+ else:
111
+ cell_content = "🌲"
112
+
113
+ coord_label = f'<span style="position: absolute; bottom: 4px; right: 6px; font-size: 9px; color: #415a77; font-family: monospace;">{x},{y}</span>'
114
+ html += f'<div style="{tile_style}">{cell_content}{coord_label}</div>'
115
+
116
+ html += f"""
117
+ </div>
118
+ <div style="margin-top: 14px; color: #00b4d8; font-size: 12px; font-family: monospace; letter-spacing: 1px;">
119
+ Coordinates: [X: {px}, Y: {py}]
120
+ </div>
121
+ </div>
122
+ """
123
+ return html
124
+
125
+
126
+ def search_forest(collection, position):
127
+ mushroom, current, history = discover_mushroom(collection)
128
+ pos = _safe_pos(position)
129
+ return (
130
+ forest_scene(current, collection, pos),
131
+ game_status_markdown(current, collection, pos),
132
+ mushroom_card_from_state(current),
133
+ current,
134
+ history,
135
+ dex_markdown(collection),
136
+ progress_markdown(collection),
137
+ )
138
+
139
+
140
+ def ask_companion(message, history, current, collection, position):
141
+ return myco_reply(message, history, current, collection, position)
142
+
143
+
144
+ def collect_discovery(current, collection, history, position):
145
+ updated_coll, updated_hist = collect_current(current, collection, history)
146
+ pos = _safe_pos(position)
147
+ return (
148
+ updated_coll,
149
+ forest_scene(current, updated_coll, pos),
150
+ game_status_markdown(current, updated_coll, pos),
151
+ dex_markdown(updated_coll),
152
+ world_map_markdown(updated_coll),
153
+ updated_hist,
154
+ progress_markdown(updated_coll),
155
+ )
156
+
157
+
158
+ def pick_discovery(current, collection, history, position):
159
+ updated_coll, updated_current, updated_hist = pick_current(current, collection, history)
160
+ pos = _safe_pos(position)
161
+ return (
162
+ updated_coll,
163
+ updated_current,
164
+ forest_scene(updated_current, updated_coll, pos),
165
+ game_status_markdown(updated_current, updated_coll, pos),
166
+ mushroom_card_from_state(updated_current),
167
+ dex_markdown(updated_coll),
168
+ world_map_markdown(updated_coll),
169
+ updated_hist,
170
+ progress_markdown(updated_coll),
171
+ )
172
+
173
+
174
+ def follow_story_whisper(current, collection, history, position):
175
+ updated_current, updated_hist = follow_whisper(current, collection, history)
176
+ pos = _safe_pos(position)
177
+ return (
178
+ updated_current,
179
+ forest_scene(updated_current, collection, pos),
180
+ game_status_markdown(updated_current, collection, pos),
181
+ mushroom_card_from_state(updated_current),
182
+ updated_hist,
183
+ )
184
+
185
+
186
+ def study_discovery(current, history, collection, position):
187
+ updated_current, updated_hist = study_current(current, history)
188
+ pos = _safe_pos(position)
189
+ return (
190
+ updated_current,
191
+ forest_scene(updated_current, collection, pos),
192
+ game_status_markdown(updated_current, collection, pos),
193
+ mushroom_card_from_state(updated_current),
194
+ updated_hist,
195
+ )
196
+
197
+
198
+ def move_player(position, direction, collection):
199
+ """Calculates movement coordinates and instantly triggers a continuous gameplay search event loop."""
200
+ x, y = _safe_pos(position)
201
+ if direction == "north": y -= 1
202
+ elif direction == "south": y += 1
203
+ elif direction == "west": x -= 1
204
+ elif direction == "east": x += 1
205
+ pos = _safe_pos((x, y))
206
+
207
+ # Real Game Loop Mechanics: Moving handles exploration encounters automatically
208
+ mushroom, current, history = discover_mushroom(collection)
209
+ return (
210
+ pos,
211
+ forest_scene(current, collection, pos),
212
+ game_status_markdown(current, collection, pos),
213
+ mushroom_card_from_state(current),
214
+ current,
215
+ history,
216
+ dex_markdown(collection),
217
+ progress_markdown(collection),
218
+ )
219
+
220
+
221
+ def block_unsafe_eating(current, history):
222
+ return eat_current(current, history)
223
+
224
+
225
+ def open_play_tab():
226
+ return gr.update(selected="play")
227
+
228
+
229
+ def _safe_pos(position):
230
  if position is None:
231
+ return START_POSITION
232
  x, y = position
233
  return (max(0, min(2, int(x))), max(0, min(2, int(y))))
234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
 
236
+ def build_app():
237
+ with gr.Blocks(title="Myco — AI Forest Game", theme=gr.themes.Soft()) as demo:
238
+ gr.HTML("""
239
+ <style>
240
+ .gradio-container { background: #1a1a2e !important; }
241
+ .gr-html, iframe, .html-container {
242
+ transition: none !important;
243
+ animation: none !important;
244
+ }
245
+ /* Completely freeze component flickering layout shifts */
246
+ * {
247
+ transition: none !important;
248
+ }
249
+ .pending, .generating {
250
+ opacity: 1.0 !important;
251
+ background: transparent !important;
252
+ animation: none !important;
253
+ border: none !important;
254
+ box-shadow: none !important;
255
+ }
256
+ /* Completely clear default overlay panels */
257
+ .progress-level, .progress-level-inner {
258
+ display: none !important;
259
+ }
260
+ </style>
261
+
262
+ <script>
263
+ document.addEventListener('keydown', function(event) {
264
+ // Keep keyboard hotkeys completely quiet if typing a query in the chatbox input
265
+ if (event.target.nodeName === 'INPUT' || event.target.nodeName === 'TEXTAREA') return;
266
+
267
+ const keyMap = {
268
+ 'w': 'btn-north', 'W': 'btn-north', 'ArrowUp': 'btn-north',
269
+ 'a': 'btn-west', 'A': 'btn-west', 'ArrowLeft': 'btn-west',
270
+ 's': 'btn-south', 'S': 'btn-south', 'ArrowDown': 'btn-south',
271
+ 'd': 'btn-east', 'D': 'btn-east', 'ArrowRight': 'btn-east',
272
+ 'e': 'btn-pick', 'E': 'btn-pick',
273
+ 'q': 'btn-study', 'Q': 'btn-study',
274
+ 'c': 'btn-collect', 'C': 'btn-collect'
275
+ };
276
+
277
+ const targetId = keyMap[event.key];
278
+ if (targetId) {
279
+ const btn = document.getElementById(targetId);
280
+ if (btn) btn.click();
281
+ }
282
+ });
283
+ </script>
284
+ """)
285
+
286
+ # ── State ──────────────────────────────────────────────────────────
287
+ current_mushroom = gr.State(None)
288
+ collection = gr.State([])
289
+ player_position = gr.State(START_POSITION)
290
+
291
+ # ── Hero header removed here ───────────────────────────────────────
292
+
293
+ with gr.Tabs(selected="home") as tabs:
294
+
295
+ # ── HOME ───────────────────────────────────────────────────────
296
+ with gr.Tab("🏠 Home", id="home"):
297
+ gr.Markdown(HOME_MARKDOWN)
298
+ gr.HTML(home_forest_markdown())
299
+ start_play_button = gr.Button(
300
+ "🍄 Enter the Forest", variant="primary", size="lg"
301
+ )
302
+ gr.Markdown(f"*{hf_companion_status()}*")
303
+
304
+ # ── PLAY ───────────────────────────────────────────────────────
305
+ with gr.Tab("🎮 Play", id="play"):
306
+ # TOP: Discovery card + action buttons + chat
307
+ with gr.Row(equal_height=True):
308
+ with gr.Column(scale=2):
309
+ gr.Markdown("### 🍄 Current Discovery")
310
+ discovery = gr.Markdown(mushroom_card(None))
311
+ with gr.Row():
312
+ study_button = gr.Button("🔍 Study", variant="secondary", elem_id="btn-study")
313
+ collect_button = gr.Button("📖 Collect", variant="secondary", elem_id="btn-collect")
314
+ with gr.Row():
315
+ whisper_button = gr.Button("🌌 Follow Whisper", variant="secondary", elem_id="btn-whisper")
316
+ eat_button = gr.Button("🍽️ Eat?", variant="stop", elem_id="btn-eat")
317
+
318
+ with gr.Column(scale=3):
319
+ gr.Markdown("### 💬 Myco Chat")
320
+ chat = gr.Chatbot(
321
+ value=cast(Any, welcome_history()),
322
+ label="Myco",
323
+ height=400,
324
+ show_label=False,
325
+ )
326
+ with gr.Row():
327
+ prompt = gr.Textbox(
328
+ placeholder="Ask Myco anything about the forest...",
329
+ show_label=False,
330
+ scale=4,
331
+ lines=1,
332
+ )
333
+ ask_button = gr.Button("Ask 🍄", variant="primary", scale=1)
334
+
335
+ # MIDDLE: Quest log
336
+ status = gr.Markdown(
337
+ game_status_markdown(None, EMPTY_COLLECTION, START_POSITION)
338
+ )
339
+
340
+ # BOTTOM: Forest Map + Controls
341
+ with gr.Row():
342
+ with gr.Column(scale=2):
343
+ scene = gr.HTML(
344
+ forest_scene(None, EMPTY_COLLECTION, START_POSITION),
345
+ elem_id="forest-scene",
346
+ )
347
+ with gr.Column(scale=1):
348
+ search_button = gr.Button("🌿 Inspect Current Spot", variant="secondary")
349
+ gr.Markdown("**Move Navigator (WASD / Arrows)**")
350
+ with gr.Row():
351
+ gr.HTML("<div></div>")
352
+ north_button = gr.Button("⬆️", size="sm", elem_id="btn-north")
353
+ gr.HTML("<div></div>")
354
+ with gr.Row():
355
+ west_button = gr.Button("⬅️", size="sm", elem_id="btn-west")
356
+ pick_button = gr.Button("🍄 Pick", variant="primary", size="sm", elem_id="btn-pick")
357
+ east_button = gr.Button("➡️", size="sm", elem_id="btn-east")
358
+ with gr.Row():
359
+ gr.HTML("<div></div>")
360
+ south_button = gr.Button("⬇️", size="sm", elem_id="btn-south")
361
+ gr.HTML("<div></div>")
362
+
363
+ # ── MYCODEX ────────────────────────────────────────────────────
364
+ with gr.Tab("📖 MycoDex"):
365
+ with gr.Row():
366
+ progress = gr.Markdown(progress_markdown(EMPTY_COLLECTION))
367
+ dex = gr.Markdown(dex_markdown(EMPTY_COLLECTION))
368
+
369
+ # ── WORLD MAP ──────────────────────────────────────────────────
370
+ with gr.Tab("🗺️ World Map"):
371
+ world_map = gr.HTML(world_map_markdown(EMPTY_COLLECTION))
372
+
373
+ # ── GUIDE ──────────────────────────────────────────────────────
374
+ with gr.Tab("🧭 Guide"):
375
+ gr.Markdown(GUIDE_MARKDOWN)
376
+
377
+ # ── Event wiring ───────────────────────────────────────────────────
378
+ start_play_button.click(open_play_tab, outputs=[tabs], show_progress="hidden")
379
+
380
+ search_button.click(
381
+ search_forest,
382
+ inputs=[collection, player_position],
383
+ outputs=[scene, status, discovery, current_mushroom, chat, dex, progress],
384
+ show_progress="hidden",
385
  )
386
+
387
+ ask_button.click(
388
+ ask_companion,
389
+ inputs=[prompt, chat, current_mushroom, collection, player_position],
390
+ outputs=[prompt, chat],
391
+ show_progress="hidden",
392
  )
393
+ prompt.submit(
394
+ ask_companion,
395
+ inputs=[prompt, chat, current_mushroom, collection, player_position],
396
+ outputs=[prompt, chat],
397
+ show_progress="hidden",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
398
  )
399
+
400
+ for direction, button in [
401
+ ("north", north_button), ("south", south_button),
402
+ ("west", west_button), ("east", east_button),
403
+ ]:
404
+ button.click(
405
+ move_player,
406
+ inputs=[player_position, gr.State(direction), collection],
407
+ outputs=[player_position, scene, status, discovery, current_mushroom, chat, dex, progress],
408
+ show_progress="hidden",
409
+ )
410
+
411
+ study_button.click(
412
+ study_discovery,
413
+ inputs=[current_mushroom, chat, collection, player_position],
414
+ outputs=[current_mushroom, scene, status, discovery, chat],
415
+ show_progress="hidden",
416
+ )
417
+ collect_button.click(
418
+ collect_discovery,
419
+ inputs=[current_mushroom, collection, chat, player_position],
420
+ outputs=[collection, scene, status, dex, world_map, chat, progress],
421
+ show_progress="hidden",
422
+ )
423
+ pick_button.click(
424
+ pick_discovery,
425
+ inputs=[current_mushroom, collection, chat, player_position],
426
+ outputs=[collection, current_mushroom, scene, status, discovery, dex, world_map, chat, progress],
427
+ show_progress="hidden",
428
+ )
429
+ whisper_button.click(
430
+ follow_story_whisper,
431
+ inputs=[current_mushroom, collection, chat, player_position],
432
+ outputs=[current_mushroom, scene, status, discovery, chat],
433
+ show_progress="hidden",
434
+ )
435
+ eat_button.click(
436
+ block_unsafe_eating,
437
+ inputs=[current_mushroom, chat],
438
+ outputs=[chat],
439
+ show_progress="hidden",
440
+ )
441
+
442
+ demo.queue()
443
+ return demo
444