Spaces:
Sleeping
Sleeping
Deploy Myco from CI
Browse files- ui/scene_renderers.py +382 -13
ui/scene_renderers.py
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
|
|
|
|
|
| 1 |
import hashlib
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
# โโ 8-BIT MATRIX BLUEPRINTS โโ
|
| 4 |
MATRIX_DOME = [[0,0,0,1,1,1,1,0,0,0],[0,0,1,2,2,3,2,1,0,0],[0,1,2,2,3,2,2,2,1,0],[1,2,3,2,2,2,3,2,2,1],[1,1,1,1,1,4,1,1,1,1],[0,0,0,0,1,4,1,0,0,0],[0,0,0,0,1,4,1,0,0,0],[0,0,0,0,1,1,1,0,0,0]]
|
|
@@ -11,23 +24,379 @@ def generate_mushroom_sprite(name: str) -> str:
|
|
| 11 |
hash_val = int(hashlib.md5(name.encode('utf-8')).hexdigest(), 16)
|
| 12 |
shapes = [MATRIX_DOME, MATRIX_SKULL, MATRIX_FLAT, MATRIX_STAR]
|
| 13 |
matrix = shapes[hash_val % len(shapes)]
|
| 14 |
-
|
| 15 |
palettes = [("#d62828", "#f77f00", "#fcbf49"), ("#00f2fe", "#ff007f", "#25003e"), ("#ffb703", "#ffffff", "#fb8500")]
|
| 16 |
c_cap, c_spot, c_stem = palettes[hash_val % len(palettes)]
|
| 17 |
-
|
| 18 |
color_map = {1: "#121214", 2: c_cap, 3: c_spot, 4: c_stem}
|
| 19 |
-
|
| 20 |
px_scale = 5
|
| 21 |
shadows = [f"{c*px_scale}px {r*px_scale}px 0 {color_map[v]}"
|
| 22 |
for r, row in enumerate(matrix) for c, v in enumerate(row) if v in color_map]
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
|
|
|
| 1 |
+
"""Markdown renderers for the Myco Gradio interface."""
|
| 2 |
+
|
| 3 |
import hashlib
|
| 4 |
+
from html import escape
|
| 5 |
+
from game.progression import (
|
| 6 |
+
AREA_UNLOCKS, current_area, next_area, next_mystery,
|
| 7 |
+
revealed_mysteries, unlocked_areas,
|
| 8 |
+
)
|
| 9 |
+
from game.state import CollectionState, EMPTY_DEX, MushroomState
|
| 10 |
+
from models.mushroom import Mushroom
|
| 11 |
+
|
| 12 |
+
POISONOUS_MUSHROOM_NAMES = {
|
| 13 |
+
"Ghost Gill", "Pepper Pixie", "Ruby Knuckle", "Clockwork Chanterelle",
|
| 14 |
+
}
|
| 15 |
|
| 16 |
# โโ 8-BIT MATRIX BLUEPRINTS โโ
|
| 17 |
MATRIX_DOME = [[0,0,0,1,1,1,1,0,0,0],[0,0,1,2,2,3,2,1,0,0],[0,1,2,2,3,2,2,2,1,0],[1,2,3,2,2,2,3,2,2,1],[1,1,1,1,1,4,1,1,1,1],[0,0,0,0,1,4,1,0,0,0],[0,0,0,0,1,4,1,0,0,0],[0,0,0,0,1,1,1,0,0,0]]
|
|
|
|
| 24 |
hash_val = int(hashlib.md5(name.encode('utf-8')).hexdigest(), 16)
|
| 25 |
shapes = [MATRIX_DOME, MATRIX_SKULL, MATRIX_FLAT, MATRIX_STAR]
|
| 26 |
matrix = shapes[hash_val % len(shapes)]
|
|
|
|
| 27 |
palettes = [("#d62828", "#f77f00", "#fcbf49"), ("#00f2fe", "#ff007f", "#25003e"), ("#ffb703", "#ffffff", "#fb8500")]
|
| 28 |
c_cap, c_spot, c_stem = palettes[hash_val % len(palettes)]
|
|
|
|
| 29 |
color_map = {1: "#121214", 2: c_cap, 3: c_spot, 4: c_stem}
|
|
|
|
| 30 |
px_scale = 5
|
| 31 |
shadows = [f"{c*px_scale}px {r*px_scale}px 0 {color_map[v]}"
|
| 32 |
for r, row in enumerate(matrix) for c, v in enumerate(row) if v in color_map]
|
| 33 |
+
return f'<div style="width:{px_scale}px; height:{px_scale}px; box-shadow: {", ".join(shadows)}; margin: 0 auto; transform: scale(1.4);"></div>'
|
| 34 |
+
|
| 35 |
+
# โโ Inline CSS + keyframes injected once into the scene โโโโโโโโโโโโโโโโโโโโโโ
|
| 36 |
+
SCENE_STYLES = """
|
| 37 |
+
<style>
|
| 38 |
+
.forest-scene {
|
| 39 |
+
position: relative; isolation: isolate; overflow: hidden; min-height: 20rem; padding: 0.75rem; border-radius: 28px;
|
| 40 |
+
background: radial-gradient(circle at 50% 72%, rgba(255,239,173,.26), transparent 8rem), radial-gradient(circle at 18% 24%, rgba(134,225,153,.22), transparent 10rem), linear-gradient(180deg,#123626 0%,#245c3c 54%,#523b20 100%);
|
| 41 |
+
border: 1px solid rgba(225,255,209,.25); box-shadow: 0 18px 48px rgba(8,30,20,.26); color: #f9ffe9;
|
| 42 |
+
}
|
| 43 |
+
.scene-hud {
|
| 44 |
+
position: relative; z-index: 3; display: flex; flex-wrap: wrap; gap: .4rem; padding: .5rem .75rem; border-radius: 999px;
|
| 45 |
+
background: rgba(13,38,28,.72); backdrop-filter: blur(6px); font-size: .8rem; font-weight: 800;
|
| 46 |
+
}
|
| 47 |
+
.scene-stage {
|
| 48 |
+
position: relative; height: 13rem; margin: .6rem 0;
|
| 49 |
+
background: linear-gradient(transparent 62%, rgba(106,79,33,.55) 63%), radial-gradient(ellipse at bottom, rgba(190,255,180,.2), transparent 60%);
|
| 50 |
+
border-radius: 22px; overflow: hidden;
|
| 51 |
+
}
|
| 52 |
+
.scene-stage span { position: absolute; line-height:1; }
|
| 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 |
+
.sparkle-one { left:34%; top:18%; font-size:1.8rem; animation:twinkle 1.8s ease-in-out infinite; }
|
| 58 |
+
.sparkle-two { right:33%; top:24%; font-size:1.6rem; animation:twinkle 2.2s ease-in-out infinite reverse; }
|
| 59 |
+
@keyframes twinkle { 0%,100%{opacity:.3;transform:scale(.85);} 50%{opacity:1;transform:scale(1.18);} }
|
| 60 |
+
.myco-player {
|
| 61 |
+
font-size:4rem; z-index:2;
|
| 62 |
+
transition: left .32s cubic-bezier(.34,1.56,.64,1), bottom .32s cubic-bezier(.34,1.56,.64,1);
|
| 63 |
+
animation: myco-bob 2.4s ease-in-out infinite;
|
| 64 |
+
filter:drop-shadow(0 6px 14px rgba(255,92,92,.28));
|
| 65 |
+
}
|
| 66 |
+
@keyframes myco-bob { 0%,100%{transform:translateY(0);} 50%{transform:translateY(-.45rem);} }
|
| 67 |
+
.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%;}
|
| 68 |
+
.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%;}
|
| 69 |
+
.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%;}
|
| 70 |
+
.mushroom-sprite {
|
| 71 |
+
position: absolute; right:33%; bottom:22%; z-index:2;
|
| 72 |
+
filter:drop-shadow(0 6px 14px rgba(0,0,0,.3));
|
| 73 |
+
}
|
| 74 |
+
.state-waiting .mushroom-sprite { opacity:0; }
|
| 75 |
+
.state-discovered .mushroom-sprite { animation: shroom-popup 0.7s cubic-bezier(.34,1.56,.64,1) both; }
|
| 76 |
+
.state-discovered .myco-player { animation: myco-bob 2.4s ease-in-out infinite, myco-run-in 0.6s cubic-bezier(.34,1.56,.64,1) both; }
|
| 77 |
+
@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); } }
|
| 78 |
+
@keyframes myco-run-in { 0%{ transform:translateX(-3rem) scaleX(-1); } 100%{ transform:translateX(0) scaleX(1); } }
|
| 79 |
+
.state-picked .mushroom-sprite { animation: shroom-catch 0.55s cubic-bezier(.34,1.56,.64,1) both; }
|
| 80 |
+
.state-picked .myco-player { animation: myco-bob 2.4s ease-in-out infinite, myco-catch-jump 0.55s ease both; }
|
| 81 |
+
@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); } }
|
| 82 |
+
@keyframes myco-catch-jump { 0%,100%{ transform:translateY(0); } 40%{ transform:translateY(-1.4rem) scale(1.1); } }
|
| 83 |
+
.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)); }
|
| 84 |
+
.state-danger .myco-player { animation: myco-bob 2.4s ease-in-out infinite, myco-recoil 0.5s ease both; }
|
| 85 |
+
@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)); } }
|
| 86 |
+
@keyframes myco-recoil { 0%{ transform:translateX(0); } 30%{ transform:translateX(-1.2rem); } 60%{ transform:translateX(.4rem); } 100%{ transform:translateX(0); } }
|
| 87 |
+
.state-game-over .forest-scene, .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; }
|
| 88 |
+
.state-game-over .mushroom-sprite { animation: shroom-explode .6s ease both; filter: drop-shadow(0 0 24px rgba(255,62,91,1)); }
|
| 89 |
+
.state-game-over .myco-player { animation: myco-fall .6s ease both; }
|
| 90 |
+
@keyframes screen-shake { 0%,100%{ transform:translateX(0); } 20%{ transform:translateX(-8px); } 40%{ transform:translateX(8px); } 60%{ transform:translateX(-5px); } 80%{ transform:translateX(5px); } }
|
| 91 |
+
@keyframes shroom-explode { 0%{ transform:scale(1) rotate(0); opacity:1; } 50%{ transform:scale(1.8) rotate(20deg); opacity:.8; } 100%{ transform:scale(0) rotate(90deg); opacity:0; } }
|
| 92 |
+
@keyframes myco-fall { 0%{ transform:rotate(0) translateY(0); opacity:1; } 100%{ transform:rotate(-90deg) translateY(2rem); opacity:.4; } }
|
| 93 |
+
.rarity-rare .mushroom-sprite { filter:drop-shadow(0 0 18px rgba(138,220,255,.9)); }
|
| 94 |
+
.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; }
|
| 95 |
+
@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); } }
|
| 96 |
+
.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); }
|
| 97 |
+
.map-tile { display:grid; min-height:1.7rem; place-items:center; border-radius:8px; background:rgba(255,255,255,.1); font-weight:900; }
|
| 98 |
+
.map-tile.active { background:rgba(255,224,138,.92); color:#3d2c00!important; }
|
| 99 |
+
.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; }
|
| 100 |
+
.scene-caption span { color:#d9f4d4; }
|
| 101 |
+
.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; }
|
| 102 |
+
@keyframes score-pop { 0%{transform:scale(.92);opacity:0;} 45%{transform:scale(1.06);opacity:1;} 100%{transform:scale(1);opacity:1;} }
|
| 103 |
+
.state-game-over .score-burst { background:rgba(130,0,30,.45); border-color:rgba(255,120,140,.55); }
|
| 104 |
+
.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); }
|
| 105 |
+
.story-moment strong,.story-moment span { display:block; }
|
| 106 |
+
.story-moment span { margin-top:.2rem; color:#f6e7b2; }
|
| 107 |
+
.generating .forest-scene, .pending .forest-scene { opacity:.88!important; }
|
| 108 |
+
.progress-level,.progress-level-inner { display:none!important; }
|
| 109 |
+
div.gradio-html { background:transparent!important; }
|
| 110 |
+
.wrap.default.pending,.wrap.default.generating { background:transparent!important; }
|
| 111 |
+
</style>
|
| 112 |
+
"""
|
| 113 |
+
|
| 114 |
+
def forest_scene(
|
| 115 |
+
current: MushroomState | None,
|
| 116 |
+
collection: CollectionState | None,
|
| 117 |
+
position: tuple[int, int] | None = None,
|
| 118 |
+
) -> str:
|
| 119 |
+
count = len(_safe_collection(collection))
|
| 120 |
+
area = current_area(count)
|
| 121 |
+
pos_x, pos_y = _safe_position(position)
|
| 122 |
+
pos_cls = f"pos-{pos_x}-{pos_y}"
|
| 123 |
+
|
| 124 |
+
if current is None:
|
| 125 |
+
mushroom_name = "Hidden mushroom"
|
| 126 |
+
rarity = "common"
|
| 127 |
+
sprite_html = "โจ"
|
| 128 |
+
status = "The moss is listening. Click Search Clearing to wake the forest."
|
| 129 |
+
omen = "Myco is waiting to sense the first spore."
|
| 130 |
+
event_label = "๐ Dreaming Forest"
|
| 131 |
+
encounter = "The next clearing may reveal a memory, creature, or poison omen."
|
| 132 |
+
mystery_label = "The Wrong Memory"
|
| 133 |
+
score_total = "0"
|
| 134 |
+
health = "3"
|
| 135 |
+
reward_text = "Search a clearing to score spores."
|
| 136 |
+
state_cls = "state-waiting"
|
| 137 |
+
else:
|
| 138 |
+
mushroom_name = current.get("name", "Mystery mushroom")
|
| 139 |
+
rarity = current.get("rarity", "Common").lower()
|
| 140 |
+
sprite_html = generate_mushroom_sprite(mushroom_name)
|
| 141 |
+
game_over = current.get("game_over") == "Yes"
|
| 142 |
+
studied = current.get("studied") == "Yes"
|
| 143 |
+
event_label = f"{current.get('event_emoji','โจ')} {current.get('event_title','Strange Omen')}"
|
| 144 |
+
encounter = current.get("encounter", "The forest waits for Myco's reaction.")
|
| 145 |
+
mystery_label = current.get("mystery_title", "The Wrong Memory")
|
| 146 |
+
score_total = current.get("score_total", "0")
|
| 147 |
+
health = current.get("health", "3")
|
| 148 |
+
reward_text = current.get("reward_text", "Decide whether to risk the pickup.")
|
| 149 |
+
state_cls = _scene_state_class(current)
|
| 150 |
+
status = f"A {rarity} {mushroom_name} breaks through the moss!"
|
| 151 |
+
if game_over: status = f"๐ GAME OVER: {mushroom_name} was poisonous!"
|
| 152 |
+
omen = "New field note unlocked." if studied else "Ask Myco what the forest is hiding."
|
| 153 |
+
if current.get("picked") == "Yes": omen = "โ
Picked! Move to the next clearing."
|
| 154 |
+
if game_over: omen = "Press Search Clearing to start a new run."
|
| 155 |
+
|
| 156 |
+
import time
|
| 157 |
+
anim_key = str(int(time.time() * 1000))[-6:]
|
| 158 |
+
|
| 159 |
+
return f'''{SCENE_STYLES}
|
| 160 |
+
<div class="forest-scene rarity-{escape(rarity)} {pos_cls} {state_cls}" data-key="{anim_key}">
|
| 161 |
+
<div class="scene-hud">
|
| 162 |
+
<span>๐งญ {escape(area.name)}</span>
|
| 163 |
+
<span>๐ฎ ({pos_x+1},{pos_y+1})</span>
|
| 164 |
+
<span>๐ {count} found</span>
|
| 165 |
+
<span>โญ {escape(score_total)}</span>
|
| 166 |
+
<span>โค๏ธ {escape(health)}/3</span>
|
| 167 |
+
<span>{escape(event_label)}</span>
|
| 168 |
+
<span>๐งฉ {escape(mystery_label)}</span>
|
| 169 |
+
</div>
|
| 170 |
+
|
| 171 |
+
<div class="scene-stage" aria-label="Magical forest scene">
|
| 172 |
+
<span class="tree tree-left">๐ฒ</span>
|
| 173 |
+
<span class="tree tree-right">๐ณ</span>
|
| 174 |
+
<span class="grass grass-one">๐ฟ</span>
|
| 175 |
+
<span class="grass grass-two">๐</span>
|
| 176 |
+
<span class="myco-player" title="Myco">๐</span>
|
| 177 |
+
<div class="mushroom-sprite" title="{escape(mushroom_name)}">{sprite_html}</div>
|
| 178 |
+
<span class="sparkle sparkle-one">โจ</span>
|
| 179 |
+
<span class="sparkle sparkle-two">โฆ</span>
|
| 180 |
+
</div>
|
| 181 |
+
|
| 182 |
+
<div class="forest-map" aria-label="Forest grid">
|
| 183 |
+
{_movement_tiles(pos_x, pos_y)}
|
| 184 |
+
</div>
|
| 185 |
+
|
| 186 |
+
<div class="scene-caption">
|
| 187 |
+
<strong>{escape(status)}</strong>
|
| 188 |
+
<span>{escape(omen)}</span>
|
| 189 |
+
</div>
|
| 190 |
+
<div class="score-burst" aria-live="polite">{escape(reward_text)}</div>
|
| 191 |
+
<div class="story-moment">
|
| 192 |
+
<strong>{escape(event_label)}</strong>
|
| 193 |
+
<span>{escape(encounter)}</span>
|
| 194 |
+
</div>
|
| 195 |
+
</div>
|
| 196 |
+
'''
|
| 197 |
+
|
| 198 |
+
def _safe_position(position):
|
| 199 |
+
if position is None:
|
| 200 |
+
return (1, 1)
|
| 201 |
+
x, y = position
|
| 202 |
+
return (max(0, min(2, int(x))), max(0, min(2, int(y))))
|
| 203 |
+
|
| 204 |
+
def _movement_tiles(active_x, active_y):
|
| 205 |
+
tiles = []
|
| 206 |
+
for y in range(3):
|
| 207 |
+
for x in range(3):
|
| 208 |
+
active = " active" if (x, y) == (active_x, active_y) else ""
|
| 209 |
+
icon = "๐" if active else "ยท"
|
| 210 |
+
tiles.append(f'<span class="map-tile{active}">{icon}</span>')
|
| 211 |
+
return "".join(tiles)
|
| 212 |
+
|
| 213 |
+
def _scene_state_class(current):
|
| 214 |
+
if current.get("game_over") == "Yes":
|
| 215 |
+
return "state-game-over"
|
| 216 |
+
if current.get("picked") == "Yes":
|
| 217 |
+
return "state-picked"
|
| 218 |
+
if current.get("poison") == "Yes":
|
| 219 |
+
return "state-danger"
|
| 220 |
+
return "state-discovered"
|
| 221 |
+
|
| 222 |
+
def game_status_markdown(
|
| 223 |
+
current: MushroomState | None,
|
| 224 |
+
collection: CollectionState | None,
|
| 225 |
+
position: tuple[int, int] | None = None,
|
| 226 |
+
) -> str:
|
| 227 |
+
count = len(_safe_collection(collection))
|
| 228 |
+
pos_x, pos_y = _safe_position(position)
|
| 229 |
+
active_mystery = next_mystery(count)
|
| 230 |
+
mystery_line = _mystery_goal_line(active_mystery, count)
|
| 231 |
+
|
| 232 |
+
if current is None:
|
| 233 |
+
objective = "Goal: solve **one mystery** โ why does Myco remember a vanished forest?"
|
| 234 |
+
discovery = "No active discovery yet. Move Myco, then Search Clearing."
|
| 235 |
+
ai_job = "Myco's job: notice clues you would miss alone."
|
| 236 |
+
event = "**Event:** waiting for the first omen"
|
| 237 |
+
clue_line = mystery_line
|
| 238 |
+
thread_line= "**Mystery thread:** The Wrong Memory โ search the first clearing."
|
| 239 |
+
bloom_line = f"**Impossible bloom:** {_mystery_bloom_meter(count)}"
|
| 240 |
+
score_line = "**Score:** 0 spores ยท **Health:** 3/3"
|
| 241 |
+
else:
|
| 242 |
+
name = current.get("name", "Mystery mushroom")
|
| 243 |
+
studied = current.get("studied") == "Yes"
|
| 244 |
+
next_step= "Collect it to preserve the clue" if studied else "Ask Myco, then Study or Follow Whisper"
|
| 245 |
+
if current.get("game_over") == "Yes":
|
| 246 |
+
objective = "**๐ GAME OVER** โ press **Search Clearing** to start a new run."
|
| 247 |
+
elif current.get("picked") == "Yes":
|
| 248 |
+
objective = "Current objective: **move to the next clearing and search again**."
|
| 249 |
+
else:
|
| 250 |
+
objective = f"Current objective: **{next_step}**."
|
| 251 |
+
bloom_line = f"**Impossible bloom:** {_mystery_bloom_meter(count)}"
|
| 252 |
+
score_line = (
|
| 253 |
+
f"**Score:** {current.get('score_total','0')} spores ยท "
|
| 254 |
+
f"**Health:** {current.get('health','3')}/3 ยท "
|
| 255 |
+
f"**Last:** {current.get('reward_text','โ')}"
|
| 256 |
+
)
|
| 257 |
+
discovery = f"Active discovery: **{name}** ยท Rarity: **{current.get('rarity','Unknown')}**"
|
| 258 |
+
event = f"**Event:** {current.get('event_emoji','โจ')} {current.get('event_title','Strange Omen')}"
|
| 259 |
+
clue_line = f"**Clue:** {current.get('clue','Myco is still listening.')}"
|
| 260 |
+
thread_line = (
|
| 261 |
+
f"**Mystery thread:** {current.get('mystery_title','The Wrong Memory')} โ "
|
| 262 |
+
f"Next: {current.get('mystery_next','follow the whisper.')}"
|
| 263 |
+
)
|
| 264 |
+
ai_job = "Myco's job: interpret clues, warn you away from danger, make discoveries feel alive."
|
| 265 |
+
|
| 266 |
+
return "\n".join((
|
| 267 |
+
"### ๐ฎ Quest Log",
|
| 268 |
+
f"**MycoDex:** {count} discoveries ยท **Map:** ({pos_x+1},{pos_y+1})",
|
| 269 |
+
discovery, objective, score_line, bloom_line,
|
| 270 |
+
event, clue_line, thread_line, mystery_line, ai_job,
|
| 271 |
+
))
|
| 272 |
+
|
| 273 |
+
def _mystery_bloom_meter(count):
|
| 274 |
+
filled = max(0, min(5, count))
|
| 275 |
+
petals = "".join("๐" if i < filled else "๐" for i in range(5))
|
| 276 |
+
if filled >= 5:
|
| 277 |
+
return f"{petals} Impossible Bloom visible"
|
| 278 |
+
return f"{petals} {5-filled} clue-whispers remain"
|
| 279 |
+
|
| 280 |
+
def mushroom_card(
|
| 281 |
+
mushroom: Mushroom | None,
|
| 282 |
+
clue: str | None = None,
|
| 283 |
+
secret: str | None = None,
|
| 284 |
+
state: MushroomState | None = None,
|
| 285 |
+
) -> str:
|
| 286 |
+
if mushroom is None:
|
| 287 |
+
return "### ๐ฒ Forest Clearing\nClick **Search Clearing** โ watch Myco run toward the mushroom!"
|
| 288 |
+
s = state or {}
|
| 289 |
+
poison = mushroom.name in POISONOUS_MUSHROOM_NAMES
|
| 290 |
+
poison_warning = "\n> โ ๏ธ **Myco senses danger โ do NOT pick this without studying first!**" if poison else ""
|
| 291 |
+
return "\n".join((
|
| 292 |
+
f"### ๐โ๐ซ {mushroom.name}",
|
| 293 |
+
f"**{mushroom.rarity} discovery** ยท found near **{mushroom.habitat}**",
|
| 294 |
+
f"> {mushroom.lore}",
|
| 295 |
+
poison_warning,
|
| 296 |
+
"",
|
| 297 |
+
f"* **Edible:** {mushroom.edible}",
|
| 298 |
+
f"* **Magic:** {mushroom.magic}",
|
| 299 |
+
f"* **Danger:** {mushroom.danger}",
|
| 300 |
+
f"* **Value:** {_mushroom_value_label(mushroom.rarity)}",
|
| 301 |
+
f"* **Poison risk:** {_poison_risk_label(mushroom.name)}",
|
| 302 |
+
f"* **Event:** {s.get('event_emoji','โจ')} {s.get('event_title','Strange Omen')}",
|
| 303 |
+
f"* **Mystery:** {s.get('mystery_title','The Wrong Memory')}",
|
| 304 |
+
f"* **Clue:** {clue or 'Study with Myco to reveal the clue.'}",
|
| 305 |
+
f"* **Secret:** {secret or 'Collect it to see how the MycoDex reacts.'}",
|
| 306 |
+
))
|
| 307 |
+
|
| 308 |
+
def _mushroom_value_label(rarity):
|
| 309 |
+
if rarity == "Legendary": return "100 spores"
|
| 310 |
+
if rarity == "Rare": return "35 spores + special discovery"
|
| 311 |
+
return "10 spores"
|
| 312 |
+
|
| 313 |
+
def _poison_risk_label(name):
|
| 314 |
+
return "โ ๏ธ POISONOUS โ Game Over if picked!" if name in POISONOUS_MUSHROOM_NAMES else "No obvious poison"
|
| 315 |
+
|
| 316 |
+
def world_map_markdown(collection: CollectionState | None) -> str:
|
| 317 |
+
count = len(_safe_collection(collection))
|
| 318 |
+
cards = []
|
| 319 |
+
for area in AREA_UNLOCKS:
|
| 320 |
+
unlocked = count >= area.required_discoveries
|
| 321 |
+
state = "unlocked" if unlocked else "locked"
|
| 322 |
+
badge = "โ
Unlocked" if unlocked else f"๐ {area.required_discoveries - count} away"
|
| 323 |
+
cards.append("\n".join((
|
| 324 |
+
f'<div class="map-card {state}">',
|
| 325 |
+
' <div class="map-card-top">',
|
| 326 |
+
f' <strong>{escape(area.name)}</strong><span>{badge}</span>',
|
| 327 |
+
' </div>',
|
| 328 |
+
f' <p>{escape(area.description)}</p>',
|
| 329 |
+
'</div>',
|
| 330 |
+
)))
|
| 331 |
+
secrets = tuple(_secret_badge(t.name, count >= t.required_discoveries) for t in revealed_mysteries(count))
|
| 332 |
+
if not secrets:
|
| 333 |
+
secrets = (_secret_badge("First Spore", False),)
|
| 334 |
+
return "\n".join((
|
| 335 |
+
'<div class="world-map-panel">',
|
| 336 |
+
' <div class="world-map-header"><p class="eyebrow">World Map</p>',
|
| 337 |
+
' <h2>Forest Atlas</h2>',
|
| 338 |
+
f' <p>{count} discoveries logged.</p></div>',
|
| 339 |
+
f' <div class="achievement-row">{"".join(secrets)}</div>',
|
| 340 |
+
f' <div class="map-grid">{"".join(cards)}</div>',
|
| 341 |
+
'</div>',
|
| 342 |
+
))
|
| 343 |
+
|
| 344 |
+
def _secret_badge(label, unlocked):
|
| 345 |
+
state = "earned" if unlocked else "pending"
|
| 346 |
+
icon = "๐" if unlocked else "โ"
|
| 347 |
+
return f'<span class="achievement {state}">{icon} {escape(label)}</span>'
|
| 348 |
+
|
| 349 |
+
def dex_markdown(collection: CollectionState | None) -> str:
|
| 350 |
+
current_collection = _safe_collection(collection)
|
| 351 |
+
if not current_collection:
|
| 352 |
+
return EMPTY_DEX
|
| 353 |
+
rows = ["### ๐ MycoDex", ""]
|
| 354 |
+
for entry in current_collection:
|
| 355 |
+
rows.append(
|
| 356 |
+
f"* ๐ **{entry['name']}** โ {entry['rarity']} โ {entry['habitat']} "
|
| 357 |
+
f"โ clue: {entry.get('clue','not studied yet')}"
|
| 358 |
+
)
|
| 359 |
+
return "\n".join(rows)
|
| 360 |
+
|
| 361 |
+
def _safe_collection(collection):
|
| 362 |
+
return list(collection or [])
|
| 363 |
+
|
| 364 |
+
def progress_markdown(collection: CollectionState | None) -> str:
|
| 365 |
+
count = len(_safe_collection(collection))
|
| 366 |
+
active_area = current_area(count)
|
| 367 |
+
upcoming_area = next_area(count)
|
| 368 |
+
unlocked_names= ", ".join(a.name for a in unlocked_areas(count))
|
| 369 |
+
rows = [
|
| 370 |
+
"### โจ Forest Progress",
|
| 371 |
+
f"**MycoDex discoveries:** {count}",
|
| 372 |
+
f"**Current area:** {active_area.name} โ {active_area.description}",
|
| 373 |
+
f"**Unlocked:** {unlocked_names}",
|
| 374 |
+
]
|
| 375 |
+
upcoming_mystery = next_mystery(count)
|
| 376 |
+
if upcoming_area:
|
| 377 |
+
rows.append(f"**Next area:** {upcoming_area.required_discoveries - count} more to unlock **{upcoming_area.name}**.")
|
| 378 |
+
else:
|
| 379 |
+
rows.append(f"**All areas visible:** You reached **{AREA_UNLOCKS[-1].name}**.")
|
| 380 |
+
if upcoming_mystery:
|
| 381 |
+
rows.append(f"**Next secret:** {upcoming_mystery.required_discoveries - count} more to reveal **{upcoming_mystery.name}**.")
|
| 382 |
+
else:
|
| 383 |
+
rows.append("**All current secrets found.** Myco thinks the Elder is watching kindly.")
|
| 384 |
+
return "\n\n".join(rows)
|
| 385 |
+
|
| 386 |
+
def _mystery_goal_line(active_mystery, count):
|
| 387 |
+
if active_mystery is None:
|
| 388 |
+
return "**Mystery:** Every known clue is awake. Keep exploring for rare surprises."
|
| 389 |
+
remaining = active_mystery.required_discoveries - count
|
| 390 |
+
return f"**Mystery:** {remaining} clue discoveries until **{active_mystery.name}** โ {active_mystery.clue}"
|
| 391 |
+
|
| 392 |
+
def game_intro_markdown() -> str:
|
| 393 |
+
return """
|
| 394 |
+
<div style="text-align:center;margin-bottom:.75rem;">
|
| 395 |
+
<h3>๐ฒ The Deep Forest</h3>
|
| 396 |
+
<p style="color:#666;font-size:.9em;">
|
| 397 |
+
You step into the glowing undergrowth. Myco hops off your shoulder, its cap faintly pulsing.<br>
|
| 398 |
+
Click <strong>Search Clearing</strong> โ watch Myco run toward whatever pops up.
|
| 399 |
+
</p>
|
| 400 |
+
</div>
|
| 401 |
+
"""
|
| 402 |
|