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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Markdown + HTML 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 |
+
# ---------------------------------------------------------------------------
|
| 16 |
+
# LLM-driven scene signal maps
|
| 17 |
+
# ---------------------------------------------------------------------------
|
| 18 |
+
MOOD_BG: dict[str, str] = {
|
| 19 |
+
"normal": "radial-gradient(ellipse at bottom,rgba(190,255,180,.2),transparent 60%)",
|
| 20 |
+
"danger": "radial-gradient(ellipse at bottom,rgba(255,62,91,.35),transparent 60%)",
|
| 21 |
+
"legendary": "radial-gradient(ellipse at bottom,rgba(255,215,0,.3),transparent 60%)",
|
| 22 |
+
"rare": "radial-gradient(ellipse at bottom,rgba(138,220,255,.25),transparent 60%)",
|
| 23 |
+
"excited": "radial-gradient(ellipse at bottom,rgba(255,224,112,.3),transparent 60%)",
|
| 24 |
+
"afraid": "radial-gradient(ellipse at bottom,rgba(100,60,200,.2),transparent 60%)",
|
| 25 |
+
"wonder": "radial-gradient(ellipse at bottom,rgba(180,140,255,.3),transparent 60%)",
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
EMOTION_ANIMATION: dict[str, str] = {
|
| 29 |
+
"curious": "myco-bob 2.4s ease-in-out infinite",
|
| 30 |
+
"excited": "myco-bob 1.1s ease-in-out infinite",
|
| 31 |
+
"nervous": "myco-bob 1.8s ease-in-out infinite, myco-recoil 0.5s ease both",
|
| 32 |
+
"afraid": "myco-recoil 0.5s ease both",
|
| 33 |
+
"wonder": "myco-bob 3.2s ease-in-out infinite",
|
| 34 |
+
"proud": "myco-bob 2s ease-in-out infinite",
|
| 35 |
+
"sad": "myco-fall 0.6s ease both",
|
| 36 |
+
"scanning": "myco-bob 2.4s ease-in-out infinite, myco-scan 3s ease-in-out infinite",
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
MYCO_FILTER: dict[str, str] = {
|
| 40 |
+
"curious": "drop-shadow(0 6px 14px rgba(255,92,92,.28))",
|
| 41 |
+
"excited": "drop-shadow(0 6px 18px rgba(255,220,80,.5))",
|
| 42 |
+
"nervous": "drop-shadow(0 6px 14px rgba(200,100,255,.35))",
|
| 43 |
+
"afraid": "drop-shadow(0 6px 14px rgba(255,62,91,.5))",
|
| 44 |
+
"wonder": "drop-shadow(0 6px 18px rgba(140,100,255,.5))",
|
| 45 |
+
"proud": "drop-shadow(0 6px 14px rgba(100,255,160,.4))",
|
| 46 |
+
"sad": "drop-shadow(0 6px 14px rgba(100,100,180,.3))",
|
| 47 |
+
"scanning": "drop-shadow(0 6px 18px rgba(255,255,255,.5))",
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
SCENE_BG: dict[str, str] = {
|
| 51 |
+
"normal": "linear-gradient(180deg,#123626 0%,#245c3c 54%,#523b20 100%)",
|
| 52 |
+
"danger": "linear-gradient(180deg,#3b0a0a 0%,#6b1a1a 54%,#2a0a0a 100%)",
|
| 53 |
+
"legendary": "linear-gradient(180deg,#1a1200 0%,#3d2e00 54%,#1a1000 100%)",
|
| 54 |
+
"rare": "linear-gradient(180deg,#051525 0%,#0d3050 54%,#051020 100%)",
|
| 55 |
+
"excited": "linear-gradient(180deg,#1a2600 0%,#2d4a10 54%,#1a2000 100%)",
|
| 56 |
+
"afraid": "linear-gradient(180deg,#0a0520 0%,#1a1040 54%,#050010 100%)",
|
| 57 |
+
"wonder": "linear-gradient(180deg,#130a2a 0%,#2a1855 54%,#0d0520 100%)",
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
# โโ Inline CSS + keyframes โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 61 |
+
SCENE_STYLES = """<style>
|
| 62 |
+
.forest-scene { position: relative; isolation: isolate; overflow: hidden; min-height: 20rem; padding: 0.75rem; border-radius: 28px; border: 1px solid rgba(225,255,209,.25); box-shadow: 0 18px 48px rgba(8,30,20,.26); color: #f9ffe9; transition: background 0.8s ease; }
|
| 63 |
+
.scene-hud { position: relative; z-index: 3; display: flex; flex-wrap: wrap; gap: .4rem; padding: .5rem .75rem; border-radius: 999px; background: rgba(13,38,28,.72); backdrop-filter: blur(6px); font-size: .8rem; font-weight: 800; }
|
| 64 |
+
.scene-stage { position: relative; height: 13rem; margin: .6rem 0; border-radius: 22px; overflow: hidden; transition: background 0.8s ease; }
|
| 65 |
+
.scene-stage span { position: absolute; line-height:1; }
|
| 66 |
+
.tree-left { left:6%; bottom:18%; font-size:5rem; filter:drop-shadow(0 8px 12px rgba(0,0,0,.28)); }
|
| 67 |
+
.tree-right { right:7%; bottom:20%; font-size:4.75rem; filter:drop-shadow(0 8px 12px rgba(0,0,0,.28)); }
|
| 68 |
+
.grass-one { left:26%; bottom:14%; font-size:2.4rem; }
|
| 69 |
+
.grass-two { right:28%; bottom:16%; font-size:2.2rem; }
|
| 70 |
+
.sparkle-one { left:34%; top:18%; font-size:1.8rem; animation:twinkle 1.8s ease-in-out infinite; }
|
| 71 |
+
.sparkle-two { right:33%; top:24%; font-size:1.6rem; animation:twinkle 2.2s ease-in-out infinite reverse; }
|
| 72 |
+
@keyframes twinkle { 0%,100%{opacity:.3;transform:scale(.85);} 50%{opacity:1;transform:scale(1.18);} }
|
| 73 |
+
|
| 74 |
+
/* Myco Animation Logic */
|
| 75 |
+
.myco-player { font-size:4rem; z-index:2; display: inline-block; transition: left .32s cubic-bezier(.34,1.56,.64,1), bottom .32s cubic-bezier(.34,1.56,.64,1), filter .6s ease; }
|
| 76 |
+
@keyframes myco-bob { 0%,100%{transform:translateY(0);} 50%{transform:translateY(-.45rem);} }
|
| 77 |
+
@keyframes myco-recoil { 0%{transform:translateX(0);} 30%{transform:translateX(-1.2rem);} 60%{transform:translateX(.4rem);} 100%{transform:translateX(0);} }
|
| 78 |
+
@keyframes myco-run-in { 0%{transform:translateX(-3rem) scaleX(-1);} 100%{transform:translateX(0) scaleX(1);} }
|
| 79 |
+
@keyframes myco-fall { 0%{transform:rotate(0) translateY(0); opacity:1;} 100%{transform:rotate(-90deg) translateY(2rem); opacity:.4;} }
|
| 80 |
+
@keyframes myco-scan { 0%,100%{transform:rotateY(0deg) scaleX(1);} 30%{transform:rotateY(-25deg) scaleX(1);} 70%{transform:rotateY(25deg) scaleX(1);} }
|
| 81 |
+
|
| 82 |
+
/* Position Grid */
|
| 83 |
+
.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%;}
|
| 84 |
+
.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%;}
|
| 85 |
+
.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%;}
|
| 86 |
+
.mushroom-sprite { right:33%; bottom:22%; font-size:3.6rem; z-index:2; filter:drop-shadow(0 6px 14px rgba(0,0,0,.3)); transition: filter 0.6s ease; }
|
| 87 |
+
.state-waiting .mushroom-sprite { opacity:0; }
|
| 88 |
+
.state-discovered .mushroom-sprite { animation: shroom-popup 0.7s cubic-bezier(.34,1.56,.64,1) both; }
|
| 89 |
+
.state-discovered .myco-player { animation: myco-run-in 0.6s cubic-bezier(.34,1.56,.64,1) both; }
|
| 90 |
+
@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);} }
|
| 91 |
+
.state-picked .mushroom-sprite { animation: shroom-catch 0.55s cubic-bezier(.34,1.56,.64,1) both; }
|
| 92 |
+
@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);} }
|
| 93 |
+
.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; }
|
| 94 |
+
@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));} }
|
| 95 |
+
.state-game-over .mushroom-sprite { animation: shroom-explode .6s ease both; filter: drop-shadow(0 0 24px rgba(255,62,91,1)); }
|
| 96 |
+
.state-game-over .myco-player { animation: myco-fall .6s ease both; }
|
| 97 |
+
@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;} }
|
| 98 |
+
@keyframes screen-shake { 0%,100%{transform:translateX(0);} 20%{transform:translateX(-8px);} 40%{transform:translateX(8px);} 60%{transform:translateX(-5px);} 80%{transform:translateX(5px);} }
|
| 99 |
+
.state-game-over { animation: screen-shake .45s ease both; }
|
| 100 |
+
.rarity-rare .mushroom-sprite { filter:drop-shadow(0 0 18px rgba(138,220,255,.9)); }
|
| 101 |
+
.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; }
|
| 102 |
+
@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);} }
|
| 103 |
+
.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); }
|
| 104 |
+
.map-tile { display:grid; min-height:1.7rem; place-items:center; border-radius:8px; background:rgba(255,255,255,.1); font-weight:900; }
|
| 105 |
+
.map-tile.active { background:rgba(255,224,138,.92); color:#3d2c00!important; }
|
| 106 |
+
.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; }
|
| 107 |
+
.scene-caption span { color:#d9f4d4; }
|
| 108 |
+
.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; }
|
| 109 |
+
@keyframes score-pop { 0%{transform:scale(.92);opacity:0;} 45%{transform:scale(1.06);opacity:1;} 100%{transform:scale(1);opacity:1;} }
|
| 110 |
+
.state-game-over .score-burst { background:rgba(130,0,30,.45); border-color:rgba(255,120,140,.55); }
|
| 111 |
+
.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); }
|
| 112 |
+
.story-moment strong, .story-moment span { display:block; }
|
| 113 |
+
.story-moment span { margin-top:.2rem; color:#f6e7b2; }
|
| 114 |
+
.generating .forest-scene, .pending .forest-scene { opacity:.88!important; }
|
| 115 |
+
.progress-level,.progress-level-inner { display:none!important; }
|
| 116 |
+
div.gradio-html { background:transparent!important; }
|
| 117 |
+
.wrap.default.pending, .wrap.default.generating { background:transparent!important; }
|
| 118 |
+
</style>"""
|
| 119 |
+
|
| 120 |
+
# โโ Component Renderers โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 121 |
+
|
| 122 |
+
def hero_markdown() -> str:
|
| 123 |
+
return """<div class="myco-hero"> <div class="myco-mascot">๐</div> <div> <p class="eyebrow">Tiny AI forest game</p> <h1>Myco</h1> <p>Follow an AI mushroom companion through a glowing forest. Every discovery starts with Myco's intuition.</p> </div></div>"""
|
| 124 |
+
|
| 125 |
+
def home_forest_markdown() -> str:
|
| 126 |
+
return """<div class="home-forest-postcard" aria-label="Animated Myco forest postcard"> <div class="home-sky"> <span class="home-milky-way" title="Milky Way">๐</span> <span class="home-star star-one">โจ</span> <span class="home-star star-two">โฆ</span> <span class="home-star star-three">โง</span> </div> <div class="home-forest-floor"> <span class="home-tree left">๐ฒ</span> <span class="home-grass grass-left">๐ฟ</span> <span class="home-myco" title="Myco">๐</span> <span class="home-brown-mushroom" title="Brown mushroom">๐โ๐ซ</span> <span class="home-grass grass-right">๐</span> <span class="home-tree right">๐ณ</span> <span class="home-moon">๐</span> </div> <p><strong>The Milky Way is awake.</strong> Myco hears a brown mushroom whispering your first clue.</p> <span class="home-whisper">"Tap Play. Let's find what the forest is hiding."</span></div>"""
|
| 127 |
+
|
| 128 |
+
def play_hook_markdown() -> str:
|
| 129 |
+
return """<div class="play-hook"> <p class="eyebrow">Mission</p> <h2>Goal: follow clues until Myco remembers the Impossible Mushroom.</h2> <div class="hook-steps"> <span>1 ยท Move through the forest</span> <span>2 ยท Search Clearing โ mushroom pops up!</span> <span>3 ยท Myco reacts ยท Pick, Study, or Follow Whisper</span> </div> <p>Every clue advances one mystery. Follow whispers to reveal why the MycoDex is regrowing a forest that vanished.</p></div>"""
|
| 130 |
+
|
| 131 |
+
def forest_scene(
|
| 132 |
+
current: MushroomState | None,
|
| 133 |
+
collection: CollectionState | None,
|
| 134 |
+
position: tuple[int, int] | None = None,
|
| 135 |
+
) -> str:
|
| 136 |
+
count = len(_safe_collection(collection))
|
| 137 |
+
area = current_area(count)
|
| 138 |
+
pos_x, pos_y = _safe_position(position)
|
| 139 |
+
pos_cls = f"pos-{pos_x}-{pos_y}"
|
| 140 |
+
|
| 141 |
+
# โโ Read LLM-driven signals โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 142 |
+
scene_mood = (current or {}).get("scene_mood", "normal")
|
| 143 |
+
myco_emotion = (current or {}).get("myco_emotion", "curious")
|
| 144 |
+
|
| 145 |
+
if scene_mood not in MOOD_BG: scene_mood = "normal"
|
| 146 |
+
if myco_emotion not in EMOTION_ANIMATION: myco_emotion = "curious"
|
| 147 |
+
|
| 148 |
+
myco_anim = EMOTION_ANIMATION[myco_emotion]
|
| 149 |
+
myco_filt = MYCO_FILTER[myco_emotion]
|
| 150 |
+
outer_bg = SCENE_BG.get(scene_mood, SCENE_BG["normal"])
|
| 151 |
+
|
| 152 |
+
# โโ Handle state/sprite โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 153 |
+
if current is None:
|
| 154 |
+
mushroom_name = "Hidden mushroom"
|
| 155 |
+
rarity = "common"
|
| 156 |
+
sprite = "๐โ๐ซ"
|
| 157 |
+
status = "The moss is listening. Click Search Clearing to wake the forest."
|
| 158 |
+
reward_text = "Search a clearing to score spores."
|
| 159 |
+
state_cls = "state-waiting"
|
| 160 |
+
event_title = "Dreaming Forest"
|
| 161 |
+
encounter = "The next clearing may reveal a memory, creature, or poison omen."
|
| 162 |
+
else:
|
| 163 |
+
mushroom_name = current.get("name", "Mystery mushroom")
|
| 164 |
+
rarity = current.get("rarity", "Common").lower()
|
| 165 |
+
|
| 166 |
+
# Legendary
|
| 167 |
+
if rarity == "legendary":
|
| 168 |
+
sprite = """
|
| 169 |
+
<div style="position: relative; display: inline-block; line-height: 1;">
|
| 170 |
+
<span style="display: inline-block; filter: hue-rotate(45deg) brightness(1.2);">๐</span>
|
| 171 |
+
<span style="position: absolute; top: -30%; left: 50%; transform: translateX(-50%); font-size: 1.5em; z-index: 2;">๐</span>
|
| 172 |
+
</div>
|
| 173 |
+
"""
|
| 174 |
+
|
| 175 |
+
# Rare
|
| 176 |
+
elif rarity == "rare":
|
| 177 |
+
sprite = """
|
| 178 |
+
<div style="position: relative; display: inline-block; line-height: 1;">
|
| 179 |
+
<span style="display: inline-block; filter: hue-rotate(200deg) saturate(120%);">๐</span>
|
| 180 |
+
<span style="position: absolute; top: 15%; left: 50%; transform: translateX(-50%); font-size: 1em; z-index: 2;">๐</span>
|
| 181 |
+
</div>
|
| 182 |
+
"""
|
| 183 |
+
|
| 184 |
+
# Poison
|
| 185 |
+
elif current.get("poison") == "Yes":
|
| 186 |
+
sprite = """
|
| 187 |
+
<div style="position: relative; display: inline-block; line-height: 1;">
|
| 188 |
+
<span style="display: inline-block; filter: hue-rotate(280deg) saturate(150%);">๐โ๐ซ</span>
|
| 189 |
+
<span style="position: absolute; top: 10%; left: 50%; transform: translateX(-50%); font-size: 1.2em; z-index: 2;">โ ๏ธ</span>
|
| 190 |
+
</div>
|
| 191 |
+
"""
|
| 192 |
+
|
| 193 |
+
# Dream / Story mushrooms
|
| 194 |
+
elif "dream" in mushroom_name.lower():
|
| 195 |
+
sprite = """
|
| 196 |
+
<div style="position: relative; display: inline-block; line-height: 1;">
|
| 197 |
+
<span style="display: inline-block; filter: hue-rotate(300deg) opacity(0.85);">๐</span>
|
| 198 |
+
<span style="position: absolute; top: 5%; left: 50%; transform: translateX(-50%); font-size: 1.1em; z-index: 2;">๐</span>
|
| 199 |
+
</div>
|
| 200 |
+
"""
|
| 201 |
+
|
| 202 |
+
# Crystal mushrooms
|
| 203 |
+
elif "crystal" in mushroom_name.lower():
|
| 204 |
+
sprite = """
|
| 205 |
+
<div style="position: relative; display: inline-block; line-height: 1;">
|
| 206 |
+
<span style="display: inline-block; filter: hue-rotate(180deg) brightness(1.5) saturate(50%);">๐</span>
|
| 207 |
+
<span style="position: absolute; top: 20%; left: 50%; transform: translateX(-50%); font-size: 1.1em; z-index: 2;">๐ง</span>
|
| 208 |
+
</div>
|
| 209 |
+
"""
|
| 210 |
+
|
| 211 |
+
# Ghost mushrooms
|
| 212 |
+
elif "ghost" in mushroom_name.lower():
|
| 213 |
+
sprite = """
|
| 214 |
+
<div style="position: relative; display: inline-block; line-height: 1;">
|
| 215 |
+
<span style="display: inline-block; filter: grayscale(90%) brightness(1.5) opacity(0.7);">๐โ๐ซ</span>
|
| 216 |
+
<span style="position: absolute; top: 20%; left: 50%; transform: translateX(-50%); font-size: 1em; z-index: 2;">๐ป</span>
|
| 217 |
+
</div>
|
| 218 |
+
"""
|
| 219 |
+
|
| 220 |
+
# Common / Standard (Fallback)
|
| 221 |
+
else:
|
| 222 |
+
sprite = """
|
| 223 |
+
<div style="position: relative; display: inline-block; line-height: 1;">
|
| 224 |
+
<span style="display: inline-block;">๐โ๐ซ</span>
|
| 225 |
+
</div>
|
| 226 |
+
"""
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
import time
|
| 230 |
+
anim_key = str(int(time.time() * 1000))[-6:]
|
| 231 |
+
|
| 232 |
+
return f'''{SCENE_STYLES}
|
| 233 |
+
<div class="forest-scene rarity-{escape(rarity)} {pos_cls} {state_cls}"
|
| 234 |
+
data-key="{anim_key}" data-mood="{escape(scene_mood)}" data-emotion="{escape(myco_emotion)}"
|
| 235 |
+
style="background: radial-gradient(circle at 50% 72%,rgba(255,239,173,.18),transparent 8rem), radial-gradient(circle at 18% 24%,rgba(134,225,153,.15),transparent 10rem), {escape(outer_bg)}; border: 1px solid rgba(225,255,209,.25);">
|
| 236 |
+
|
| 237 |
+
<div class="scene-hud">
|
| 238 |
+
<span>๐งญ {escape(area.name)}</span>
|
| 239 |
+
<span>๐ฎ ({pos_x+1},{pos_y+1})</span>
|
| 240 |
+
<span>โญ {current.get('score_total', '0') if current else '0'}</span>
|
| 241 |
+
<span>โค๏ธ {current.get('health', '3') if current else '3'}/3</span>
|
| 242 |
+
</div>
|
| 243 |
+
|
| 244 |
+
<div class="scene-stage">
|
| 245 |
+
<span class="tree-left">๐ฒ</span>
|
| 246 |
+
<span class="tree-right">๐ณ</span>
|
| 247 |
+
<span class="grass-one">๐ฟ</span>
|
| 248 |
+
<span class="grass-two">๐</span>
|
| 249 |
+
<span class="myco-player" style="animation: {myco_anim}; filter: {myco_filt};" title="Myco">๐</span>
|
| 250 |
+
<span class="mushroom-sprite" title="{escape(mushroom_name)}">{sprite}</span>
|
| 251 |
+
</div>
|
| 252 |
+
|
| 253 |
+
<div class="forest-map">
|
| 254 |
+
{_movement_tiles(pos_x, pos_y)}
|
| 255 |
+
</div>
|
| 256 |
+
|
| 257 |
+
<div class="scene-caption">
|
| 258 |
+
<strong>{escape(status)}</strong>
|
| 259 |
+
</div>
|
| 260 |
+
<div class="score-burst">{escape(reward_text)}</div>
|
| 261 |
+
<div class="story-moment">
|
| 262 |
+
<strong>{escape(event_title)}</strong>
|
| 263 |
+
<span>{escape(encounter)}</span>
|
| 264 |
+
</div>
|
| 265 |
+
</div>'''
|
| 266 |
+
|
| 267 |
+
# โโ Helper Functions โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 268 |
+
|
| 269 |
+
def _safe_position(position):
|
| 270 |
+
if position is None: return (1, 1)
|
| 271 |
+
x, y = position
|
| 272 |
+
return (max(0, min(2, int(x))), max(0, min(2, int(y))))
|
| 273 |
+
|
| 274 |
+
def _movement_tiles(active_x, active_y):
|
| 275 |
+
tiles = []
|
| 276 |
+
for y in range(3):
|
| 277 |
+
for x in range(3):
|
| 278 |
+
active = " active" if (x, y) == (active_x, active_y) else ""
|
| 279 |
+
icon = "๐" if active else "ยท"
|
| 280 |
+
tiles.append(f'<span class="map-tile{active}">{icon}</span>')
|
| 281 |
+
return "".join(tiles)
|
| 282 |
+
|
| 283 |
+
def _scene_state_class(current):
|
| 284 |
+
if current.get("game_over") == "Yes": return "state-game-over"
|
| 285 |
+
if current.get("picked") == "Yes": return "state-picked"
|
| 286 |
+
if current.get("poison") == "Yes": return "state-danger"
|
| 287 |
+
return "state-discovered"
|
| 288 |
+
|
| 289 |
+
def _safe_collection(collection):
|
| 290 |
+
return list(collection or [])
|
| 291 |
+
|
| 292 |
+
def game_status_markdown(current: MushroomState | None, collection: CollectionState | None, position: tuple[int, int] | None = None) -> str:
|
| 293 |
+
count = len(_safe_collection(collection))
|
| 294 |
+
pos_x, pos_y = _safe_position(position)
|
| 295 |
+
active_mystery = next_mystery(count)
|
| 296 |
+
mystery_line = _mystery_goal_line(active_mystery, count)
|
| 297 |
+
|
| 298 |
+
if current is None:
|
| 299 |
+
objective = "Goal: solve **one mystery** โ why does Myco remember a vanished forest?"
|
| 300 |
+
discovery = "No active discovery yet. Move Myco, then Search Clearing."
|
| 301 |
+
ai_job = "Myco's job: notice clues you would miss alone."
|
| 302 |
+
event = "**Event:** waiting for the first omen"
|
| 303 |
+
clue_line = mystery_line
|
| 304 |
+
thread_line= "**Mystery thread:** The Wrong Memory โ search the first clearing."
|
| 305 |
+
bloom_line = f"**Impossible bloom:** {_mystery_bloom_meter(count)}"
|
| 306 |
+
score_line = "**Score:** 0 spores ยท **Health:** 3/3"
|
| 307 |
+
else:
|
| 308 |
+
name = current.get("name", "Mystery mushroom")
|
| 309 |
+
studied = current.get("studied") == "Yes"
|
| 310 |
+
next_step= "Collect it to preserve the clue" if studied else "Ask Myco, then Study or Follow Whisper"
|
| 311 |
+
if current.get("game_over") == "Yes":
|
| 312 |
+
objective = "**๐ GAME OVER** โ press **Search Clearing** to start a new run."
|
| 313 |
+
elif current.get("picked") == "Yes":
|
| 314 |
+
objective = "Current objective: **move to the next clearing and search again**."
|
| 315 |
+
else:
|
| 316 |
+
objective = f"Current objective: **{next_step}**."
|
| 317 |
+
bloom_line = f"**Impossible bloom:** {_mystery_bloom_meter(count)}"
|
| 318 |
+
score_line = (
|
| 319 |
+
f"**Score:** {current.get('score_total','0')} spores ยท "
|
| 320 |
+
f"**Health:** {current.get('health','3')}/3 ยท "
|
| 321 |
+
f"**Last:** {current.get('reward_text','โ')}"
|
| 322 |
+
)
|
| 323 |
+
discovery = f"Active discovery: **{name}** ยท Rarity: **{current.get('rarity','Unknown')}**"
|
| 324 |
+
event = f"**Event:** {current.get('event_emoji','โจ')} {current.get('event_title','Strange Omen')}"
|
| 325 |
+
clue_line = f"**Clue:** {current.get('clue','Myco is still listening.')}"
|
| 326 |
+
thread_line = (
|
| 327 |
+
f"**Mystery thread:** {current.get('mystery_title','The Wrong Memory')} โ "
|
| 328 |
+
f"Next: {current.get('mystery_next','follow the whisper.')}"
|
| 329 |
+
)
|
| 330 |
+
ai_job = "Myco's job: interpret clues, warn you away from danger, make discoveries feel alive."
|
| 331 |
+
|
| 332 |
+
return "\n".join((
|
| 333 |
+
"### ๐ฎ Quest Log",
|
| 334 |
+
f"**MycoDex:** {count} discoveries ยท **Map:** ({pos_x+1},{pos_y+1})",
|
| 335 |
+
discovery, objective, score_line, bloom_line,
|
| 336 |
+
event, clue_line, thread_line, mystery_line, ai_job,
|
| 337 |
+
))
|
| 338 |
+
|
| 339 |
+
def _mystery_bloom_meter(count):
|
| 340 |
+
filled = max(0, min(5, count))
|
| 341 |
+
petals = "".join("๐" if i < filled else "๐" for i in range(5))
|
| 342 |
+
if filled >= 5:
|
| 343 |
+
return f"{petals} Impossible Bloom visible"
|
| 344 |
+
return f"{petals} {5-filled} clue-whispers remain"
|
| 345 |
+
|
| 346 |
+
def mushroom_card(mushroom: Mushroom | None, clue: str | None = None, secret: str | None = None, state: MushroomState | None = None) -> str:
|
| 347 |
+
if mushroom is None: return "### ๐ฒ Forest Clearing\nClick **Search Clearing** โ watch Myco run toward the mushroom!"
|
| 348 |
+
s = state or {}
|
| 349 |
+
poison = mushroom.name in POISONOUS_MUSHROOM_NAMES
|
| 350 |
+
poison_warning = "\n> โ ๏ธ **Myco senses danger โ do NOT pick this without studying first!**" if poison else ""
|
| 351 |
+
return "\n".join((
|
| 352 |
+
f"### ๐โ๐ซ {mushroom.name}",
|
| 353 |
+
f"**{mushroom.rarity} discovery** ยท found near **{mushroom.habitat}**",
|
| 354 |
+
f"> {mushroom.lore}",
|
| 355 |
+
poison_warning,
|
| 356 |
+
"",
|
| 357 |
+
f"* **Edible:** {mushroom.edible}",
|
| 358 |
+
f"* **Magic:** {mushroom.magic}",
|
| 359 |
+
f"* **Danger:** {mushroom.danger}",
|
| 360 |
+
f"* **Value:** {_mushroom_value_label(mushroom.rarity)}",
|
| 361 |
+
f"* **Poison risk:** {_poison_risk_label(mushroom.name)}",
|
| 362 |
+
f"* **Event:** {s.get('event_emoji','โจ')} {s.get('event_title','Strange Omen')}",
|
| 363 |
+
f"* **Mystery:** {s.get('mystery_title','The Wrong Memory')}",
|
| 364 |
+
f"* **Clue:** {clue or 'Study with Myco to reveal the clue.'}",
|
| 365 |
+
f"* **Secret:** {secret or 'Collect it to see how the MycoDex reacts.'}",
|
| 366 |
+
))
|
| 367 |
+
|
| 368 |
+
def _mushroom_value_label(rarity):
|
| 369 |
+
if rarity == "Legendary": return "100 spores"
|
| 370 |
+
if rarity == "Rare": return "35 spores + special discovery"
|
| 371 |
+
return "10 spores"
|
| 372 |
+
|
| 373 |
+
def _poison_risk_label(name):
|
| 374 |
+
return "โ ๏ธ POISONOUS โ Game Over if picked!" if name in POISONOUS_MUSHROOM_NAMES else "No obvious poison"
|
| 375 |
+
|
| 376 |
+
def world_map_markdown(collection: CollectionState | None) -> str:
|
| 377 |
+
count = len(_safe_collection(collection))
|
| 378 |
+
cards = []
|
| 379 |
+
for area in AREA_UNLOCKS:
|
| 380 |
+
unlocked = count >= area.required_discoveries
|
| 381 |
+
state = "unlocked" if unlocked else "locked"
|
| 382 |
+
badge = "โ
Unlocked" if unlocked else f"๐ {area.required_discoveries - count} away"
|
| 383 |
+
cards.append("\n".join((
|
| 384 |
+
f'<div class="map-card {state}">',
|
| 385 |
+
' <div class="map-card-top">',
|
| 386 |
+
f' <strong>{escape(area.name)}</strong><span>{badge}</span>',
|
| 387 |
+
' </div>',
|
| 388 |
+
f' <p>{escape(area.description)}</p>',
|
| 389 |
+
'</div>',
|
| 390 |
+
)))
|
| 391 |
+
secrets = tuple(_secret_badge(t.name, count >= t.required_discoveries) for t in revealed_mysteries(count))
|
| 392 |
+
if not secrets: secrets = (_secret_badge("First Spore", False),)
|
| 393 |
+
return "\n".join((
|
| 394 |
+
'<div class="world-map-panel">',
|
| 395 |
+
' <div class="world-map-header"><p class="eyebrow">World Map</p>',
|
| 396 |
+
' <h2>Forest Atlas</h2>',
|
| 397 |
+
f' <p>{count} discoveries logged.</p></div>',
|
| 398 |
+
f' <div class="achievement-row">{"".join(secrets)}</div>',
|
| 399 |
+
f' <div class="map-grid">{"".join(cards)}</div>',
|
| 400 |
+
'</div>',
|
| 401 |
+
))
|
| 402 |
+
|
| 403 |
+
def _secret_badge(label, unlocked):
|
| 404 |
+
state = "earned" if unlocked else "pending"
|
| 405 |
+
icon = "๐" if unlocked else "โ"
|
| 406 |
+
return f'<span class="achievement {state}">{icon} {escape(label)}</span>'
|
| 407 |
+
|
| 408 |
+
def dex_markdown(collection: CollectionState | None) -> str:
|
| 409 |
+
current_collection = _safe_collection(collection)
|
| 410 |
+
if not current_collection: return EMPTY_DEX
|
| 411 |
+
rows = ["### ๐ MycoDex", ""]
|
| 412 |
+
for entry in current_collection:
|
| 413 |
+
rows.append(f"* ๐ **{entry['name']}** โ {entry['rarity']} โ {entry['habitat']} โ clue: {entry.get('clue','not studied yet')}")
|
| 414 |
+
return "\n".join(rows)
|
| 415 |
+
|
| 416 |
+
def progress_markdown(collection: CollectionState | None) -> str:
|
| 417 |
+
count = len(_safe_collection(collection))
|
| 418 |
+
active_area = current_area(count)
|
| 419 |
+
upcoming_area = next_area(count)
|
| 420 |
+
unlocked_names = ", ".join(a.name for a in unlocked_areas(count))
|
| 421 |
+
rows = [
|
| 422 |
+
"### โจ Forest Progress",
|
| 423 |
+
f"**MycoDex discoveries:** {count}",
|
| 424 |
+
f"**Current area:** {active_area.name} โ {active_area.description}",
|
| 425 |
+
f"**Unlocked:** {unlocked_names}",
|
| 426 |
+
]
|
| 427 |
+
upcoming_mystery = next_mystery(count)
|
| 428 |
+
if upcoming_area:
|
| 429 |
+
rows.append(f"**Next area:** {upcoming_area.required_discoveries - count} more to unlock **{upcoming_area.name}**.")
|
| 430 |
+
else:
|
| 431 |
+
rows.append(f"**All areas visible:** You reached **{AREA_UNLOCKS[-1].name}**.")
|
| 432 |
+
if upcoming_mystery:
|
| 433 |
+
rows.append(f"**Next secret:** {upcoming_mystery.required_discoveries - count} more to reveal **{upcoming_mystery.name}**.")
|
| 434 |
+
else:
|
| 435 |
+
rows.append("**All current secrets found.** Myco thinks the Elder is watching kindly.")
|
| 436 |
+
return "\n\n".join(rows)
|
| 437 |
+
|
| 438 |
+
def _mystery_goal_line(active_mystery, count):
|
| 439 |
+
if active_mystery is None:
|
| 440 |
+
return "**Mystery:** Every known clue is awake. Keep exploring for rare surprises."
|
| 441 |
+
remaining = active_mystery.required_discoveries - count
|
| 442 |
+
return f"**Mystery:** {remaining} clue discoveries until **{active_mystery.name}** โ {active_mystery.clue}"
|
| 443 |
+
|
| 444 |
+
def game_intro_markdown() -> str:
|
| 445 |
+
return """<div class="myco-hero-banner"><div class="floating-spores"><span>โจ</span><span>โฆ</span><span>โจ</span><span>โง</span><span>โจ</span></div><div class="myco-avatar">๐</div><h1>๐ฒ The Deep Forest ๐ฒ</h1><div class="highlight-line">๐ Myco wants to investigate <span>EVERY SINGLE ONE</span>.</div><div class="myco-thought">๐ญ โI know this forest... but I don't remember why.โ</div></div>"""
|
| 446 |
+
|