Spaces:
Sleeping

byte-vortex commited on
Commit
0940fb5
Β·
verified Β·
1 Parent(s): 9d6e9b4

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. ui/renderers.py +155 -76
ui/renderers.py CHANGED
@@ -15,7 +15,6 @@ POISONOUS_MUSHROOM_NAMES = {
15
  "Ghost Gill", "Pepper Pixie", "Ruby Knuckle", "Clockwork Chanterelle",
16
  }
17
 
18
-
19
  # ---------------------------------------------------------------------------
20
  # Static UI fragments
21
  # ---------------------------------------------------------------------------
@@ -33,10 +32,7 @@ def hero_markdown() -> str:
33
  """
34
 
35
  def myco_talking_markdown(text: str) -> str:
36
- """Renders Myco's latest thought in a dynamic speech bubble."""
37
- # Escape quotes to prevent breaking the HTML string
38
- safe_text = str(text).replace('"', '\\"')
39
-
40
  return f'''
41
  <div class="myco-speech-container">
42
  <div class="myco-bubble">
@@ -105,7 +101,7 @@ def play_hook_markdown() -> str:
105
  <span>2 Β· Search Clearing β€” mushroom pops up!</span>
106
  <span>3 Β· Myco reacts Β· Pick, Study, or Follow Whisper</span>
107
  </div>
108
- <p>Every clue advances one mystery. Follow whispers to reveal why the MycoDex is regrowing a forest that vanished.</p>
109
  </div>
110
  """
111
 
@@ -121,23 +117,23 @@ def game_intro_markdown() -> str:
121
  </div>
122
  """
123
 
124
-
125
  # ---------------------------------------------------------------------------
126
- # Forest scene β€” main animated panel
127
  # ---------------------------------------------------------------------------
128
 
129
  def forest_scene(
130
  current: "MushroomState | None",
131
  collection: "CollectionState | None",
132
  position: "tuple[int,int] | None" = None,
 
133
  ) -> str:
134
  import time
135
- count = len(_safe_collection(collection))
136
- area = current_area(count)
137
  pos_x, pos_y = _safe_position(position)
138
- pos_cls = f"pos-{pos_x}-{pos_y}"
139
 
140
- # Safe defaults
141
  mushroom_name = "Hidden mushroom"
142
  rarity = "common"
143
  sprite = "✨"
@@ -155,7 +151,6 @@ def forest_scene(
155
  mushroom_name = current.get("name", "Mystery cluster")
156
  rarity = current.get("rarity", "Common").lower()
157
  game_over = current.get("game_over") == "Yes"
158
-
159
  event_label = f"{current.get('event_emoji','✨')} {current.get('event_title','Strange Omen')}"
160
  encounter = current.get("encounter", "Go pick them up!")
161
  mystery_label = current.get("mystery_title", "The Wrong Memory")
@@ -168,15 +163,107 @@ def forest_scene(
168
  status = "πŸ’€ GAME OVER: You stepped on a poisonous mushroom!"
169
  omen = "Press Search Clearing to start a new run."
170
  elif current.get("picked") == "Yes":
171
- status = "βœ… Area clear! All safe mushrooms collected."
172
  omen = "Search the next clearing!"
173
  else:
174
- status = "Mushrooms sprouted! Move Myco over them to collect."
175
- omen = "πŸ„ Watch your step!"
176
 
 
 
177
  anim_key = str(int(time.time() * 1000))[-6:]
178
 
179
  return f'''
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  <div class="forest-scene rarity-{escape(rarity)} {pos_cls} {state_cls}" data-key="{anim_key}">
181
  <div class="scene-hud">
182
  <span>🧭 {escape(area.name)}</span>
@@ -195,13 +282,13 @@ def forest_scene(
195
  <span class="grass grass-two">πŸƒ</span>
196
  <span class="myco-player" title="Myco">πŸ„</span>
197
  <span class="mushroom-sprite" title="{escape(mushroom_name)}">{escape(sprite)}</span>
 
198
  <span class="sparkle sparkle-one">✨</span>
199
  <span class="sparkle sparkle-two">✦</span>
200
- <span class="wood-log">πŸͺ΅</span>
201
  </div>
202
 
203
  <div class="forest-map" aria-label="Forest grid">
204
- {_movement_tiles(pos_x, pos_y, current)}
205
  </div>
206
 
207
  <div class="scene-caption">
@@ -216,6 +303,30 @@ def forest_scene(
216
  </div>'''
217
 
218
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
  # ---------------------------------------------------------------------------
220
  # Helpers
221
  # ---------------------------------------------------------------------------
@@ -230,49 +341,34 @@ def _safe_position(position):
230
  return (1, 1)
231
 
232
 
233
- def _movement_tiles(active_x, active_y, current=None):
234
- """Draws the grid, safely decoding strings to ensure mushrooms always show up!"""
235
  mush_coords = {}
236
-
237
- # --- DEFENSIVE PARSING ---
238
- # If Gradio passed the state as a string, turn it back into a dictionary
239
- if isinstance(current, str):
240
- try:
241
- current = json.loads(current)
242
- except:
243
- try:
244
- current = ast.literal_eval(current)
245
- except:
246
- current = {} # Default to empty if parsing fails
247
-
248
- # Map out where the mushrooms are
249
- if current and isinstance(current, dict) and "active_mushrooms" in current:
250
- for m in current["active_mushrooms"]:
251
- # Ensure we are using ints for coordinates, just in case
252
- if m.get("picked") == "No" or m.get("picked") is False:
253
- mx, my = int(m["mush_x"]), int(m["mush_y"])
254
- mush_coords[(mx, my)] = m
255
 
256
  tiles = []
257
  for y in range(3):
258
  for x in range(3):
259
- # Ensure player coordinates are ints
260
- is_player = (int(x), int(y)) == (int(active_x), int(active_y))
261
- is_mush = (int(x), int(y)) in mush_coords
262
-
263
- active_class = " active" if is_player else ""
264
-
265
  if is_player:
266
- icon = "πŸ„" # Myco
267
- elif is_mush:
268
- # If it's a mushroom, show poison skull or magic sparkles
269
- m_data = mush_coords[(int(x), int(y))]
270
- icon = "☠️" if m_data.get("poison") == "Yes" else "✨"
 
271
  else:
272
- icon = "Β·" # Empty grass
273
-
274
- tiles.append(f'<span class="map-tile{active_class}">{icon}</span>')
275
-
276
  return "".join(tiles)
277
 
278
 
@@ -287,6 +383,7 @@ def _scene_state_class(current):
287
  return "state-danger"
288
  return "state-discovered"
289
 
 
290
  def _safe_collection(collection):
291
  return list(collection or [])
292
 
@@ -319,7 +416,6 @@ def game_status_markdown(
319
  studied = current.get("studied") == "Yes"
320
  game_over = current.get("game_over") == "Yes"
321
  picked = current.get("picked") == "Yes"
322
-
323
  if game_over:
324
  objective = "**πŸ’€ GAME OVER** β€” press **Search Clearing** to start a new run."
325
  elif picked:
@@ -327,7 +423,6 @@ def game_status_markdown(
327
  else:
328
  next_step = "Collect it to preserve the clue" if studied else "Study it, then Collect or Pick"
329
  objective = f"Current objective: **{next_step}**."
330
-
331
  bloom_line = f"**Impossible bloom:** {_mystery_bloom_meter(count)}"
332
  score_line = (
333
  f"**Score:** {current.get('score_total','0')} spores Β· "
@@ -370,8 +465,7 @@ def mushroom_card(
370
  f"### πŸ„β€πŸŸ« {mushroom.name}",
371
  f"**{mushroom.rarity} discovery** Β· found near **{mushroom.habitat}**",
372
  f"> {mushroom.lore}",
373
- warning,
374
- "",
375
  f"* **Edible:** {mushroom.edible}",
376
  f"* **Magic:** {mushroom.magic}",
377
  f"* **Danger:** {mushroom.danger}",
@@ -392,7 +486,7 @@ def _poison_risk_label(name):
392
 
393
 
394
  # ---------------------------------------------------------------------------
395
- # World map
396
  # ---------------------------------------------------------------------------
397
 
398
  def world_map_markdown(collection: "CollectionState | None") -> str:
@@ -428,11 +522,6 @@ def _secret_badge(label, unlocked):
428
  icon = "πŸ”Ž" if unlocked else "β—‡"
429
  return f'<span class="achievement {state}">{icon} {escape(label)}</span>'
430
 
431
-
432
- # ---------------------------------------------------------------------------
433
- # MycoDex
434
- # ---------------------------------------------------------------------------
435
-
436
  def dex_markdown(collection: "CollectionState | None") -> str:
437
  current_collection = _safe_collection(collection)
438
  if not current_collection:
@@ -441,17 +530,12 @@ def dex_markdown(collection: "CollectionState | None") -> str:
441
  for entry in current_collection:
442
  poison_flag = " ☠️" if entry.get("poison") == "Yes" else ""
443
  rows.append(
444
- f"* πŸ„ **{entry.get('name','Unknown Mushroom')}**{poison_flag} β€” "
445
  f"{entry.get('rarity','Unknown')} β€” "
446
  f"{entry.get('habitat','Unknown habitat')} β€” clue: {entry.get('clue','not studied yet')}"
447
  )
448
  return "\n".join(rows)
449
 
450
-
451
- # ---------------------------------------------------------------------------
452
- # Progress
453
- # ---------------------------------------------------------------------------
454
-
455
  def progress_markdown(collection: "CollectionState | None") -> str:
456
  count = len(_safe_collection(collection))
457
  active_area = current_area(count)
@@ -471,14 +555,9 @@ def progress_markdown(collection: "CollectionState | None") -> str:
471
  if upcoming_mystery:
472
  rows.append(f"**Next secret:** {upcoming_mystery.required_discoveries - count} more to reveal **{upcoming_mystery.name}**.")
473
  else:
474
- rows.append("**All current secrets found.** Myco thinks the Elder is watching kindly.")
475
  return "\n\n".join(rows)
476
 
477
-
478
- # ---------------------------------------------------------------------------
479
- # Helpers
480
- # ---------------------------------------------------------------------------
481
-
482
  def _mystery_goal_line(active_mystery, count):
483
  if active_mystery is None:
484
  return "**Mystery:** Every known clue is awake. Keep exploring for rare surprises."
 
15
  "Ghost Gill", "Pepper Pixie", "Ruby Knuckle", "Clockwork Chanterelle",
16
  }
17
 
 
18
  # ---------------------------------------------------------------------------
19
  # Static UI fragments
20
  # ---------------------------------------------------------------------------
 
32
  """
33
 
34
  def myco_talking_markdown(text: str) -> str:
35
+ safe_text = escape(str(text))
 
 
 
36
  return f'''
37
  <div class="myco-speech-container">
38
  <div class="myco-bubble">
 
101
  <span>2 Β· Search Clearing β€” mushroom pops up!</span>
102
  <span>3 Β· Myco reacts Β· Pick, Study, or Follow Whisper</span>
103
  </div>
104
+ <p>Every clue advances one mystery.</p>
105
  </div>
106
  """
107
 
 
117
  </div>
118
  """
119
 
 
120
  # ---------------------------------------------------------------------------
121
+ # Forest scene β€” accepts optional active_mushrooms list
122
  # ---------------------------------------------------------------------------
123
 
124
  def forest_scene(
125
  current: "MushroomState | None",
126
  collection: "CollectionState | None",
127
  position: "tuple[int,int] | None" = None,
128
+ active_mushrooms: "list | None" = None, # ← NEW: list of mushroom dicts
129
  ) -> str:
130
  import time
131
+ count = len(_safe_collection(collection))
132
+ area = current_area(count)
133
  pos_x, pos_y = _safe_position(position)
134
+ pos_cls = f"pos-{pos_x}-{pos_y}"
135
 
136
+ # Safe defaults β€” all variables set before any conditional
137
  mushroom_name = "Hidden mushroom"
138
  rarity = "common"
139
  sprite = "✨"
 
151
  mushroom_name = current.get("name", "Mystery cluster")
152
  rarity = current.get("rarity", "Common").lower()
153
  game_over = current.get("game_over") == "Yes"
 
154
  event_label = f"{current.get('event_emoji','✨')} {current.get('event_title','Strange Omen')}"
155
  encounter = current.get("encounter", "Go pick them up!")
156
  mystery_label = current.get("mystery_title", "The Wrong Memory")
 
163
  status = "πŸ’€ GAME OVER: You stepped on a poisonous mushroom!"
164
  omen = "Press Search Clearing to start a new run."
165
  elif current.get("picked") == "Yes":
166
+ status = "βœ… Area clear! Move to the next clearing."
167
  omen = "Search the next clearing!"
168
  else:
169
+ status = f"A {rarity} {mushroom_name} breaks through the moss!"
170
+ omen = "πŸ„ Study it before picking!"
171
 
172
+ # Build roaming mushroom sprites from active_mushrooms
173
+ active_sprites = _build_active_sprites(active_mushrooms or [])
174
  anim_key = str(int(time.time() * 1000))[-6:]
175
 
176
  return f'''
177
+ <style>
178
+ /* ── Base scene ── */
179
+ .forest-scene {{
180
+ position:relative; isolation:isolate; overflow:hidden; min-height:20rem;
181
+ padding:0.75rem; border-radius:28px;
182
+ background:
183
+ radial-gradient(circle at 50% 72%, rgba(255,239,173,.26), transparent 8rem),
184
+ radial-gradient(circle at 18% 24%, rgba(134,225,153,.22), transparent 10rem),
185
+ linear-gradient(180deg,#123626 0%,#245c3c 54%,#523b20 100%);
186
+ border:1px solid rgba(225,255,209,.25);
187
+ box-shadow:0 18px 48px rgba(8,30,20,.26);
188
+ color:#f9ffe9;
189
+ }}
190
+ .scene-hud {{
191
+ position:relative; z-index:3; display:flex; flex-wrap:wrap; gap:.4rem;
192
+ padding:.5rem .75rem; border-radius:999px;
193
+ background:rgba(13,38,28,.72); backdrop-filter:blur(6px);
194
+ font-size:.8rem; font-weight:800;
195
+ }}
196
+ .scene-stage {{
197
+ position:relative; height:13rem; margin:.6rem 0;
198
+ background:linear-gradient(transparent 62%,rgba(106,79,33,.55) 63%),
199
+ radial-gradient(ellipse at bottom,rgba(190,255,180,.2),transparent 60%);
200
+ border-radius:22px; overflow:hidden;
201
+ }}
202
+ .scene-stage span {{ position:absolute; line-height:1; }}
203
+ .tree-left {{ left:6%; bottom:18%; font-size:5rem; filter:drop-shadow(0 8px 12px rgba(0,0,0,.28)); }}
204
+ .tree-right {{ right:7%; bottom:20%; font-size:4.75rem; filter:drop-shadow(0 8px 12px rgba(0,0,0,.28)); }}
205
+ .grass-one {{ left:26%; bottom:14%; font-size:2.4rem; }}
206
+ .grass-two {{ right:28%;bottom:16%; font-size:2.2rem; }}
207
+ .sparkle-one {{ left:34%; top:18%; font-size:1.8rem; animation:twinkle 1.8s ease-in-out infinite; }}
208
+ .sparkle-two {{ right:33%;top:24%; font-size:1.6rem; animation:twinkle 2.2s ease-in-out infinite reverse; }}
209
+ @keyframes twinkle {{ 0%,100%{{opacity:.3;transform:scale(.85);}} 50%{{opacity:1;transform:scale(1.18);}} }}
210
+ .myco-player {{
211
+ font-size:4rem; z-index:2;
212
+ transition:left .32s cubic-bezier(.34,1.56,.64,1),bottom .32s cubic-bezier(.34,1.56,.64,1);
213
+ animation:myco-bob 2.4s ease-in-out infinite;
214
+ filter:drop-shadow(0 6px 14px rgba(255,92,92,.28));
215
+ }}
216
+ @keyframes myco-bob {{ 0%,100%{{transform:translateY(0);}} 50%{{transform:translateY(-.45rem);}} }}
217
+ .pos-0-0 .myco-player{{left:14%;bottom:62%;}} .pos-1-0 .myco-player{{left:41%;bottom:62%;}} .pos-2-0 .myco-player{{left:67%;bottom:62%;}}
218
+ .pos-0-1 .myco-player{{left:14%;bottom:36%;}} .pos-1-1 .myco-player{{left:41%;bottom:36%;}} .pos-2-1 .myco-player{{left:67%;bottom:36%;}}
219
+ .pos-0-2 .myco-player{{left:14%;bottom:13%;}} .pos-1-2 .myco-player{{left:41%;bottom:13%;}} .pos-2-2 .myco-player{{left:67%;bottom:13%;}}
220
+ .mushroom-sprite {{
221
+ right:33%; bottom:22%; font-size:3.6rem; z-index:2;
222
+ filter:drop-shadow(0 6px 14px rgba(0,0,0,.3));
223
+ }}
224
+ /* Roaming mushroom sprites β€” placed by grid cell */
225
+ .roam-sprite {{
226
+ font-size:2.2rem; z-index:2; transition:opacity .3s;
227
+ animation:roam-bob 2s ease-in-out infinite;
228
+ filter:drop-shadow(0 4px 8px rgba(0,0,0,.3));
229
+ }}
230
+ @keyframes roam-bob {{ 0%,100%{{transform:translateY(0);}} 50%{{transform:translateY(-.3rem);}} }}
231
+ .roam-0-0{{left:10%;bottom:58%;}} .roam-1-0{{left:37%;bottom:58%;}} .roam-2-0{{left:63%;bottom:58%;}}
232
+ .roam-0-1{{left:10%;bottom:32%;}} .roam-1-1{{left:37%;bottom:32%;}} .roam-2-1{{left:63%;bottom:32%;}}
233
+ .roam-0-2{{left:10%;bottom:9%;}} .roam-1-2{{left:37%;bottom:9%;}} .roam-2-2{{left:63%;bottom:9%;}}
234
+ .roam-poison {{ animation:roam-bob 2s ease-in-out infinite, poison-pulse 1.2s ease-in-out infinite; }}
235
+ @keyframes poison-pulse {{ 0%,100%{{filter:drop-shadow(0 0 10px rgba(255,62,91,.6));}} 50%{{filter:drop-shadow(0 0 28px rgba(255,62,91,1));}} }}
236
+ /* States */
237
+ .state-waiting .mushroom-sprite {{ opacity:0; }}
238
+ .state-discovered .mushroom-sprite {{ animation:shroom-popup 0.7s cubic-bezier(.34,1.56,.64,1) both; }}
239
+ .state-picked .mushroom-sprite {{ animation:shroom-catch 0.55s cubic-bezier(.34,1.56,.64,1) both; }}
240
+ .state-danger .mushroom-sprite {{ animation:shroom-popup 0.7s cubic-bezier(.34,1.56,.64,1) both,poison-pulse 1.2s ease-in-out infinite 0.7s; filter:drop-shadow(0 0 18px rgba(255,62,91,.9)); }}
241
+ .state-game-over {{ animation:screen-shake .45s ease both; background:radial-gradient(circle at 50% 72%,rgba(255,62,91,.35),transparent 8rem),linear-gradient(180deg,#3b0a0a 0%,#6b1a1a 54%,#2a0a0a 100%) !important; }}
242
+ @keyframes shroom-popup {{ 0%{{opacity:0;transform:translateY(3rem) scale(.2);}} 60%{{opacity:1;transform:translateY(-.4rem) scale(1.18);}} 100%{{opacity:1;transform:translateY(0) scale(1);}} }}
243
+ @keyframes shroom-catch {{ 0%{{opacity:1;transform:translateY(0) scale(1);}} 40%{{opacity:1;transform:translateY(-2.5rem) scale(1.3) rotate(15deg);}} 100%{{opacity:0;transform:translateY(-5rem) scale(.2) rotate(40deg);}} }}
244
+ @keyframes screen-shake {{ 0%,100%{{transform:translateX(0);}} 20%{{transform:translateX(-8px);}} 40%{{transform:translateX(8px);}} 60%{{transform:translateX(-5px);}} 80%{{transform:translateX(5px);}} }}
245
+ .rarity-rare .mushroom-sprite {{ filter:drop-shadow(0 0 18px rgba(138,220,255,.9)); }}
246
+ .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; }}
247
+ @keyframes legendary-pulse {{ 0%,100%{{filter:drop-shadow(0 0 18px rgba(255,215,0,.7));transform:scale(1);}} 50%{{filter:drop-shadow(0 0 36px rgba(255,215,0,1));transform:scale(1.1);}} }}
248
+ /* Grid map */
249
+ .forest-map {{ display:grid; grid-template-columns:repeat(3,1fr); gap:.3rem; margin:.4rem auto .6rem; max-width:9rem; padding:.4rem; border:1px solid rgba(255,255,255,.18); border-radius:14px; background:rgba(13,38,28,.58); }}
250
+ .map-tile {{ display:grid; min-height:1.7rem; place-items:center; border-radius:8px; background:rgba(255,255,255,.1); font-weight:900; }}
251
+ .map-tile.active {{ background:rgba(255,224,138,.92); color:#3d2c00!important; }}
252
+ .map-tile.has-mush {{ background:rgba(100,200,100,.25); }}
253
+ .map-tile.has-poison {{ background:rgba(200,60,60,.25); }}
254
+ /* Caption / score */
255
+ .scene-caption {{ display:flex; justify-content:space-between; gap:.6rem; padding:.55rem .8rem; border-radius:14px; background:rgba(13,38,28,.68); backdrop-filter:blur(6px); align-items:center; }}
256
+ .scene-caption span {{ color:#d9f4d4; }}
257
+ .score-burst {{ margin:.65rem auto 0; max-width:520px; padding:.5rem .85rem; border-radius:999px; background:rgba(255,224,112,.18); border:1px solid rgba(255,244,190,.36); color:#fff7d6; font-weight:900; text-align:center; animation:score-pop .56s ease both; }}
258
+ @keyframes score-pop {{ 0%{{transform:scale(.92);opacity:0;}} 45%{{transform:scale(1.06);opacity:1;}} 100%{{transform:scale(1);opacity:1);}} }}
259
+ .story-moment {{ margin:.75rem auto 0; max-width:760px; padding:.8rem 1rem; border:1px solid rgba(255,234,166,.3); border-radius:18px; background:rgba(25,18,45,.72); color:#fff7d6; box-shadow:0 0 24px rgba(165,111,255,.22); }}
260
+ .story-moment strong,.story-moment span {{ display:block; }}
261
+ .story-moment span {{ margin-top:.2rem; color:#f6e7b2; }}
262
+ .ai-tick-badge {{ display:inline-block; padding:.15rem .55rem; border-radius:999px; background:rgba(80,220,120,.22); border:1px solid rgba(80,220,120,.4); color:#90ffb8; font-size:.72rem; font-weight:800; animation:ai-pulse 2s ease-in-out infinite; }}
263
+ @keyframes ai-pulse {{ 0%,100%{{opacity:.6;}} 50%{{opacity:1;}} }}
264
+ .generating .forest-scene,.pending .forest-scene {{ opacity:.88!important; }}
265
+ .progress-level,.progress-level-inner {{ display:none!important; }}
266
+ </style>
267
  <div class="forest-scene rarity-{escape(rarity)} {pos_cls} {state_cls}" data-key="{anim_key}">
268
  <div class="scene-hud">
269
  <span>🧭 {escape(area.name)}</span>
 
282
  <span class="grass grass-two">πŸƒ</span>
283
  <span class="myco-player" title="Myco">πŸ„</span>
284
  <span class="mushroom-sprite" title="{escape(mushroom_name)}">{escape(sprite)}</span>
285
+ {active_sprites}
286
  <span class="sparkle sparkle-one">✨</span>
287
  <span class="sparkle sparkle-two">✦</span>
 
288
  </div>
289
 
290
  <div class="forest-map" aria-label="Forest grid">
291
+ {_movement_tiles(pos_x, pos_y, active_mushrooms)}
292
  </div>
293
 
294
  <div class="scene-caption">
 
303
  </div>'''
304
 
305
 
306
+ # ---------------------------------------------------------------------------
307
+ # Active mushroom sprites builder
308
+ # ---------------------------------------------------------------------------
309
+
310
+ def _build_active_sprites(active_mushrooms: list) -> str:
311
+ """Render each roaming mushroom as a positioned sprite on the scene stage."""
312
+ sprites = []
313
+ for m in active_mushrooms:
314
+ if not isinstance(m, dict):
315
+ continue
316
+ if m.get("picked") == "Yes":
317
+ continue
318
+ mx = int(m.get("mush_x", 1))
319
+ my = int(m.get("mush_y", 1))
320
+ mx = max(0, min(2, mx))
321
+ my = max(0, min(2, my))
322
+ is_poison = m.get("poison") == "Yes"
323
+ icon = "☠️" if is_poison else ("πŸ„β€πŸŸ«" if m.get("rarity") == "Legendary" else "πŸ„")
324
+ css_class = f"roam-sprite roam-{mx}-{my}" + (" roam-poison" if is_poison else "")
325
+ name = escape(str(m.get("name", "?")))
326
+ sprites.append(f'<span class="{css_class}" title="{name}">{icon}</span>')
327
+ return "\n ".join(sprites)
328
+
329
+
330
  # ---------------------------------------------------------------------------
331
  # Helpers
332
  # ---------------------------------------------------------------------------
 
341
  return (1, 1)
342
 
343
 
344
+ def _movement_tiles(active_x, active_y, active_mushrooms=None):
345
+ """Grid map tiles β€” marks player, mushrooms, and poison cells."""
346
  mush_coords = {}
347
+ for m in (active_mushrooms or []):
348
+ if not isinstance(m, dict):
349
+ continue
350
+ if m.get("picked") == "Yes":
351
+ continue
352
+ mx, my = int(m.get("mush_x", -1)), int(m.get("mush_y", -1))
353
+ if 0 <= mx <= 2 and 0 <= my <= 2:
354
+ mush_coords[(mx, my)] = m
 
 
 
 
 
 
 
 
 
 
 
355
 
356
  tiles = []
357
  for y in range(3):
358
  for x in range(3):
359
+ is_player = (x, y) == (int(active_x), int(active_y))
360
+ mush = mush_coords.get((x, y))
 
 
 
 
361
  if is_player:
362
+ css = "map-tile active"
363
+ icon = "πŸ„"
364
+ elif mush:
365
+ is_p = mush.get("poison") == "Yes"
366
+ css = "map-tile has-poison" if is_p else "map-tile has-mush"
367
+ icon = "☠️" if is_p else "✨"
368
  else:
369
+ css = "map-tile"
370
+ icon = "Β·"
371
+ tiles.append(f'<span class="{css}">{icon}</span>')
 
372
  return "".join(tiles)
373
 
374
 
 
383
  return "state-danger"
384
  return "state-discovered"
385
 
386
+
387
  def _safe_collection(collection):
388
  return list(collection or [])
389
 
 
416
  studied = current.get("studied") == "Yes"
417
  game_over = current.get("game_over") == "Yes"
418
  picked = current.get("picked") == "Yes"
 
419
  if game_over:
420
  objective = "**πŸ’€ GAME OVER** β€” press **Search Clearing** to start a new run."
421
  elif picked:
 
423
  else:
424
  next_step = "Collect it to preserve the clue" if studied else "Study it, then Collect or Pick"
425
  objective = f"Current objective: **{next_step}**."
 
426
  bloom_line = f"**Impossible bloom:** {_mystery_bloom_meter(count)}"
427
  score_line = (
428
  f"**Score:** {current.get('score_total','0')} spores Β· "
 
465
  f"### πŸ„β€πŸŸ« {mushroom.name}",
466
  f"**{mushroom.rarity} discovery** Β· found near **{mushroom.habitat}**",
467
  f"> {mushroom.lore}",
468
+ warning, "",
 
469
  f"* **Edible:** {mushroom.edible}",
470
  f"* **Magic:** {mushroom.magic}",
471
  f"* **Danger:** {mushroom.danger}",
 
486
 
487
 
488
  # ---------------------------------------------------------------------------
489
+ # World map / Dex / Progress
490
  # ---------------------------------------------------------------------------
491
 
492
  def world_map_markdown(collection: "CollectionState | None") -> str:
 
522
  icon = "πŸ”Ž" if unlocked else "β—‡"
523
  return f'<span class="achievement {state}">{icon} {escape(label)}</span>'
524
 
 
 
 
 
 
525
  def dex_markdown(collection: "CollectionState | None") -> str:
526
  current_collection = _safe_collection(collection)
527
  if not current_collection:
 
530
  for entry in current_collection:
531
  poison_flag = " ☠️" if entry.get("poison") == "Yes" else ""
532
  rows.append(
533
+ f"* πŸ„ **{entry.get('name','Unknown')}**{poison_flag} β€” "
534
  f"{entry.get('rarity','Unknown')} β€” "
535
  f"{entry.get('habitat','Unknown habitat')} β€” clue: {entry.get('clue','not studied yet')}"
536
  )
537
  return "\n".join(rows)
538
 
 
 
 
 
 
539
  def progress_markdown(collection: "CollectionState | None") -> str:
540
  count = len(_safe_collection(collection))
541
  active_area = current_area(count)
 
555
  if upcoming_mystery:
556
  rows.append(f"**Next secret:** {upcoming_mystery.required_discoveries - count} more to reveal **{upcoming_mystery.name}**.")
557
  else:
558
+ rows.append("**All current secrets found.**")
559
  return "\n\n".join(rows)
560
 
 
 
 
 
 
561
  def _mystery_goal_line(active_mystery, count):
562
  if active_mystery is None:
563
  return "**Mystery:** Every known clue is awake. Keep exploring for rare surprises."