Spaces:
Sleeping
Sleeping
Deploy Myco from CI
Browse files- ui/renderers.py +377 -39
ui/renderers.py
CHANGED
|
@@ -1,7 +1,5 @@
|
|
| 1 |
"""Markdown renderers for the Myco Gradio interface."""
|
| 2 |
|
| 3 |
-
import hashlib
|
| 4 |
-
import time
|
| 5 |
from html import escape
|
| 6 |
from game.progression import (
|
| 7 |
AREA_UNLOCKS, current_area, next_area, next_mystery,
|
|
@@ -10,63 +8,384 @@ from game.progression import (
|
|
| 10 |
from game.state import CollectionState, EMPTY_DEX, MushroomState
|
| 11 |
from models.mushroom import Mushroom
|
| 12 |
|
|
|
|
|
|
|
| 13 |
POISONOUS_MUSHROOM_NAMES = {
|
| 14 |
"Ghost Gill", "Pepper Pixie", "Ruby Knuckle", "Clockwork Chanterelle",
|
| 15 |
}
|
| 16 |
|
| 17 |
-
# โโ
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
def hero_markdown() -> str:
|
| 39 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
def home_forest_markdown() -> str:
|
| 42 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
def play_hook_markdown() -> str:
|
| 45 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
def forest_scene(
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
pos_x, pos_y = _safe_position(position)
|
| 51 |
pos_cls = f"pos-{pos_x}-{pos_y}"
|
|
|
|
| 52 |
if current is None:
|
| 53 |
-
mushroom_name
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
else:
|
| 56 |
mushroom_name = current.get("name", "Mystery mushroom")
|
| 57 |
-
rarity
|
| 58 |
-
|
| 59 |
-
game_over
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
omen = "New field note unlocked." if studied else "Ask Myco what the forest is hiding."
|
| 66 |
-
if current.get("picked") == "Yes":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
anim_key = str(int(time.time() * 1000))[-6:]
|
| 68 |
-
return f'''{SCENE_STYLES}<div class="forest-scene rarity-{escape(rarity)} {pos_cls} {state_cls}" data-key="{anim_key}"><div class="scene-hud"><span>๐งญ {escape(area.name)}</span><span>๐ฎ ({pos_x+1},{pos_y+1})</span><span>๐ {count} found</span></div><div class="scene-stage"><span class="myco-player">๐</span><div class="mushroom-sprite">{sprite_html}</div></div></div>'''
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
def _safe_position(position):
|
| 72 |
if position is None:
|
|
@@ -272,4 +591,23 @@ def game_intro_markdown() -> str:
|
|
| 272 |
</p>
|
| 273 |
</div>
|
| 274 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,
|
|
|
|
| 8 |
from game.state import CollectionState, EMPTY_DEX, MushroomState
|
| 9 |
from models.mushroom import Mushroom
|
| 10 |
|
| 11 |
+
import hashlib
|
| 12 |
+
|
| 13 |
POISONOUS_MUSHROOM_NAMES = {
|
| 14 |
"Ghost Gill", "Pepper Pixie", "Ruby Knuckle", "Clockwork Chanterelle",
|
| 15 |
}
|
| 16 |
|
| 17 |
+
# โโ Inline CSS + keyframes injected once into the scene โโโโโโโโโโโโโโโโโโโโโโ
|
| 18 |
+
SCENE_STYLES = """
|
| 19 |
+
<style>
|
| 20 |
+
/* โโ Base scene โโ */
|
| 21 |
+
.forest-scene {
|
| 22 |
+
position: relative; isolation: isolate;
|
| 23 |
+
overflow: hidden; min-height: 20rem;
|
| 24 |
+
padding: 0.75rem; border-radius: 28px;
|
| 25 |
+
background:
|
| 26 |
+
radial-gradient(circle at 50% 72%, rgba(255,239,173,.26), transparent 8rem),
|
| 27 |
+
radial-gradient(circle at 18% 24%, rgba(134,225,153,.22), transparent 10rem),
|
| 28 |
+
linear-gradient(180deg,#123626 0%,#245c3c 54%,#523b20 100%);
|
| 29 |
+
border: 1px solid rgba(225,255,209,.25);
|
| 30 |
+
box-shadow: 0 18px 48px rgba(8,30,20,.26);
|
| 31 |
+
color: #f9ffe9;
|
| 32 |
+
}
|
| 33 |
|
| 34 |
+
/* โโ HUD bar โโ */
|
| 35 |
+
.scene-hud {
|
| 36 |
+
position: relative; z-index: 3;
|
| 37 |
+
display: flex; flex-wrap: wrap; gap: .4rem;
|
| 38 |
+
padding: .5rem .75rem; border-radius: 999px;
|
| 39 |
+
background: rgba(13,38,28,.72); backdrop-filter: blur(6px);
|
| 40 |
+
font-size: .8rem; font-weight: 800;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/* โโ Stage โโ */
|
| 44 |
+
.scene-stage {
|
| 45 |
+
position: relative; height: 13rem;
|
| 46 |
+
margin: .6rem 0;
|
| 47 |
+
background:
|
| 48 |
+
linear-gradient(transparent 62%, rgba(106,79,33,.55) 63%),
|
| 49 |
+
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 |
+
|
| 54 |
+
/* โโ Trees / grass โโ */
|
| 55 |
+
.tree-left { left:6%; bottom:18%; font-size:5rem; filter:drop-shadow(0 8px 12px rgba(0,0,0,.28)); }
|
| 56 |
+
.tree-right { right:7%; bottom:20%; font-size:4.75rem; filter:drop-shadow(0 8px 12px rgba(0,0,0,.28)); }
|
| 57 |
+
.grass-one { left:26%; bottom:14%; font-size:2.4rem; }
|
| 58 |
+
.grass-two { right:28%;bottom:16%; font-size:2.2rem; }
|
| 59 |
+
|
| 60 |
+
/* โโ Sparkles โโ */
|
| 61 |
+
.sparkle-one { left:34%; top:18%; font-size:1.8rem; animation:twinkle 1.8s ease-in-out infinite; }
|
| 62 |
+
.sparkle-two { right:33%; top:24%; font-size:1.6rem; animation:twinkle 2.2s ease-in-out infinite reverse; }
|
| 63 |
+
@keyframes twinkle {
|
| 64 |
+
0%,100%{opacity:.3;transform:scale(.85);}
|
| 65 |
+
50%{opacity:1;transform:scale(1.18);}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
/* โโ Myco player โ position grid โโ */
|
| 69 |
+
.myco-player {
|
| 70 |
+
font-size:4rem; z-index:2;
|
| 71 |
+
transition: left .32s cubic-bezier(.34,1.56,.64,1), bottom .32s cubic-bezier(.34,1.56,.64,1);
|
| 72 |
+
animation: myco-bob 2.4s ease-in-out infinite;
|
| 73 |
+
filter:drop-shadow(0 6px 14px rgba(255,92,92,.28));
|
| 74 |
+
}
|
| 75 |
+
@keyframes myco-bob {
|
| 76 |
+
0%,100%{transform:translateY(0);}
|
| 77 |
+
50%{transform:translateY(-.45rem);}
|
| 78 |
+
}
|
| 79 |
+
.pos-0-0 .myco-player{left:14%;bottom:62%;}
|
| 80 |
+
.pos-1-0 .myco-player{left:41%;bottom:62%;}
|
| 81 |
+
.pos-2-0 .myco-player{left:67%;bottom:62%;}
|
| 82 |
+
.pos-0-1 .myco-player{left:14%;bottom:36%;}
|
| 83 |
+
.pos-1-1 .myco-player{left:41%;bottom:36%;}
|
| 84 |
+
.pos-2-1 .myco-player{left:67%;bottom:36%;}
|
| 85 |
+
.pos-0-2 .myco-player{left:14%;bottom:13%;}
|
| 86 |
+
.pos-1-2 .myco-player{left:41%;bottom:13%;}
|
| 87 |
+
.pos-2-2 .myco-player{left:67%;bottom:13%;}
|
| 88 |
+
|
| 89 |
+
/* โโ Mushroom sprite โโ */
|
| 90 |
+
.mushroom-sprite {
|
| 91 |
+
right:33%; bottom:22%; font-size:3.6rem; z-index:2;
|
| 92 |
+
filter:drop-shadow(0 6px 14px rgba(0,0,0,.3));
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
/* โโ STATE: waiting (no mushroom) โโ */
|
| 96 |
+
.state-waiting .mushroom-sprite { opacity:0; }
|
| 97 |
+
|
| 98 |
+
/* โโ STATE: discovered โ mushroom pops up, Myco runs toward it โโ */
|
| 99 |
+
.state-discovered .mushroom-sprite {
|
| 100 |
+
animation: shroom-popup 0.7s cubic-bezier(.34,1.56,.64,1) both;
|
| 101 |
+
}
|
| 102 |
+
.state-discovered .myco-player {
|
| 103 |
+
animation: myco-bob 2.4s ease-in-out infinite,
|
| 104 |
+
myco-run-in 0.6s cubic-bezier(.34,1.56,.64,1) both;
|
| 105 |
+
}
|
| 106 |
+
@keyframes shroom-popup {
|
| 107 |
+
0% { opacity:0; transform:translateY(3rem) scale(.2); }
|
| 108 |
+
60% { opacity:1; transform:translateY(-.4rem) scale(1.18); }
|
| 109 |
+
100% { opacity:1; transform:translateY(0) scale(1); }
|
| 110 |
+
}
|
| 111 |
+
@keyframes myco-run-in {
|
| 112 |
+
0% { transform:translateX(-3rem) scaleX(-1); }
|
| 113 |
+
100% { transform:translateX(0) scaleX(1); }
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/* โโ STATE: picked โ mushroom flies up and disappears โโ */
|
| 117 |
+
.state-picked .mushroom-sprite {
|
| 118 |
+
animation: shroom-catch 0.55s cubic-bezier(.34,1.56,.64,1) both;
|
| 119 |
+
}
|
| 120 |
+
.state-picked .myco-player {
|
| 121 |
+
animation: myco-bob 2.4s ease-in-out infinite,
|
| 122 |
+
myco-catch-jump 0.55s ease both;
|
| 123 |
+
}
|
| 124 |
+
@keyframes shroom-catch {
|
| 125 |
+
0% { opacity:1; transform:translateY(0) scale(1); }
|
| 126 |
+
40% { opacity:1; transform:translateY(-2.5rem) scale(1.3) rotate(15deg); }
|
| 127 |
+
100% { opacity:0; transform:translateY(-5rem) scale(.2) rotate(40deg); }
|
| 128 |
+
}
|
| 129 |
+
@keyframes myco-catch-jump {
|
| 130 |
+
0%,100%{ transform:translateY(0); }
|
| 131 |
+
40% { transform:translateY(-1.4rem) scale(1.1); }
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
/* โโ STATE: danger (poison, not yet picked) โโ */
|
| 135 |
+
.state-danger .mushroom-sprite {
|
| 136 |
+
animation: shroom-popup 0.7s cubic-bezier(.34,1.56,.64,1) both,
|
| 137 |
+
poison-pulse 1.2s ease-in-out infinite 0.7s;
|
| 138 |
+
filter: drop-shadow(0 0 18px rgba(255,62,91,.9));
|
| 139 |
+
}
|
| 140 |
+
.state-danger .myco-player {
|
| 141 |
+
animation: myco-bob 2.4s ease-in-out infinite,
|
| 142 |
+
myco-recoil 0.5s ease both;
|
| 143 |
+
}
|
| 144 |
+
@keyframes poison-pulse {
|
| 145 |
+
0%,100%{ filter:drop-shadow(0 0 10px rgba(255,62,91,.6)); }
|
| 146 |
+
50% { filter:drop-shadow(0 0 28px rgba(255,62,91,1)); }
|
| 147 |
+
}
|
| 148 |
+
@keyframes myco-recoil {
|
| 149 |
+
0% { transform:translateX(0); }
|
| 150 |
+
30% { transform:translateX(-1.2rem); }
|
| 151 |
+
60% { transform:translateX(.4rem); }
|
| 152 |
+
100%{ transform:translateX(0); }
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
/* โโ STATE: game over โโ */
|
| 156 |
+
.state-game-over .forest-scene,
|
| 157 |
+
.state-game-over {
|
| 158 |
+
animation: screen-shake .45s ease both;
|
| 159 |
+
background:
|
| 160 |
+
radial-gradient(circle at 50% 72%, rgba(255,62,91,.35), transparent 8rem),
|
| 161 |
+
linear-gradient(180deg,#3b0a0a 0%,#6b1a1a 54%,#2a0a0a 100%) !important;
|
| 162 |
+
}
|
| 163 |
+
.state-game-over .mushroom-sprite {
|
| 164 |
+
animation: shroom-explode .6s ease both;
|
| 165 |
+
filter: drop-shadow(0 0 24px rgba(255,62,91,1));
|
| 166 |
+
}
|
| 167 |
+
.state-game-over .myco-player {
|
| 168 |
+
animation: myco-fall .6s ease both;
|
| 169 |
+
}
|
| 170 |
+
@keyframes screen-shake {
|
| 171 |
+
0%,100%{ transform:translateX(0); }
|
| 172 |
+
20% { transform:translateX(-8px); }
|
| 173 |
+
40% { transform:translateX(8px); }
|
| 174 |
+
60% { transform:translateX(-5px); }
|
| 175 |
+
80% { transform:translateX(5px); }
|
| 176 |
+
}
|
| 177 |
+
@keyframes shroom-explode {
|
| 178 |
+
0% { transform:scale(1) rotate(0); opacity:1; }
|
| 179 |
+
50% { transform:scale(1.8) rotate(20deg); opacity:.8; }
|
| 180 |
+
100%{ transform:scale(0) rotate(90deg); opacity:0; }
|
| 181 |
+
}
|
| 182 |
+
@keyframes myco-fall {
|
| 183 |
+
0% { transform:rotate(0) translateY(0); opacity:1; }
|
| 184 |
+
100%{ transform:rotate(-90deg) translateY(2rem); opacity:.4; }
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
/* โโ Rarity glows โโ */
|
| 188 |
+
.rarity-rare .mushroom-sprite { filter:drop-shadow(0 0 18px rgba(138,220,255,.9)); }
|
| 189 |
+
.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; }
|
| 190 |
+
@keyframes legendary-pulse {
|
| 191 |
+
0%,100%{ filter:drop-shadow(0 0 18px rgba(255,215,0,.7)); transform:scale(1); }
|
| 192 |
+
50% { filter:drop-shadow(0 0 36px rgba(255,215,0,1)); transform:scale(1.1); }
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
/* โโ Mini map grid โโ */
|
| 196 |
+
.forest-map {
|
| 197 |
+
display:grid; grid-template-columns:repeat(3,1fr);
|
| 198 |
+
gap:.3rem; margin:.4rem auto .6rem;
|
| 199 |
+
max-width:9rem; padding:.4rem;
|
| 200 |
+
border:1px solid rgba(255,255,255,.18); border-radius:14px;
|
| 201 |
+
background:rgba(13,38,28,.58);
|
| 202 |
+
}
|
| 203 |
+
.map-tile {
|
| 204 |
+
display:grid; min-height:1.7rem; place-items:center;
|
| 205 |
+
border-radius:8px; background:rgba(255,255,255,.1); font-weight:900;
|
| 206 |
+
}
|
| 207 |
+
.map-tile.active { background:rgba(255,224,138,.92); color:#3d2c00!important; }
|
| 208 |
+
|
| 209 |
+
/* โโ Caption โโ */
|
| 210 |
+
.scene-caption {
|
| 211 |
+
display:flex; justify-content:space-between; gap:.6rem;
|
| 212 |
+
padding:.55rem .8rem; border-radius:14px;
|
| 213 |
+
background:rgba(13,38,28,.68); backdrop-filter:blur(6px);
|
| 214 |
+
align-items:center;
|
| 215 |
+
}
|
| 216 |
+
.scene-caption span { color:#d9f4d4; }
|
| 217 |
+
|
| 218 |
+
/* โโ Score burst โโ */
|
| 219 |
+
.score-burst {
|
| 220 |
+
margin:.65rem auto 0; max-width:520px;
|
| 221 |
+
padding:.5rem .85rem; border-radius:999px;
|
| 222 |
+
background:rgba(255,224,112,.18); border:1px solid rgba(255,244,190,.36);
|
| 223 |
+
color:#fff7d6; font-weight:900; text-align:center;
|
| 224 |
+
animation:score-pop .56s ease both;
|
| 225 |
+
}
|
| 226 |
+
@keyframes score-pop {
|
| 227 |
+
0%{transform:scale(.92);opacity:0;}
|
| 228 |
+
45%{transform:scale(1.06);opacity:1;}
|
| 229 |
+
100%{transform:scale(1);opacity:1;}
|
| 230 |
+
}
|
| 231 |
+
.state-game-over .score-burst {
|
| 232 |
+
background:rgba(130,0,30,.45); border-color:rgba(255,120,140,.55);
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
/* โโ Story moment โโ */
|
| 236 |
+
.story-moment {
|
| 237 |
+
margin:.75rem auto 0; max-width:760px;
|
| 238 |
+
padding:.8rem 1rem; border:1px solid rgba(255,234,166,.3);
|
| 239 |
+
border-radius:18px; background:rgba(25,18,45,.72);
|
| 240 |
+
color:#fff7d6; box-shadow:0 0 24px rgba(165,111,255,.22);
|
| 241 |
+
}
|
| 242 |
+
.story-moment strong,.story-moment span { display:block; }
|
| 243 |
+
.story-moment span { margin-top:.2rem; color:#f6e7b2; }
|
| 244 |
+
|
| 245 |
+
/* โโ Suppress Gradio white flash โโ */
|
| 246 |
+
.generating .forest-scene, .pending .forest-scene { opacity:.88!important; }
|
| 247 |
+
.progress-level,.progress-level-inner { display:none!important; }
|
| 248 |
+
div.gradio-html { background:transparent!important; }
|
| 249 |
+
.wrap.default.pending,.wrap.default.generating { background:transparent!important; }
|
| 250 |
+
</style>
|
| 251 |
+
"""
|
| 252 |
|
| 253 |
def hero_markdown() -> str:
|
| 254 |
+
return """
|
| 255 |
+
<div class="myco-hero">
|
| 256 |
+
<div class="myco-mascot">๐</div>
|
| 257 |
+
<div>
|
| 258 |
+
<p class="eyebrow">Tiny AI forest game</p>
|
| 259 |
+
<h1>Myco</h1>
|
| 260 |
+
<p>Follow an AI mushroom companion through a glowing forest. Every discovery starts with Myco's intuition.</p>
|
| 261 |
+
</div>
|
| 262 |
+
</div>
|
| 263 |
+
"""
|
| 264 |
|
| 265 |
def home_forest_markdown() -> str:
|
| 266 |
+
return """
|
| 267 |
+
<div class="home-forest-postcard" aria-label="Animated Myco forest postcard">
|
| 268 |
+
<div class="home-sky">
|
| 269 |
+
<span class="home-milky-way" title="Milky Way">๐</span>
|
| 270 |
+
<span class="home-star star-one">โจ</span>
|
| 271 |
+
<span class="home-star star-two">โฆ</span>
|
| 272 |
+
<span class="home-star star-three">โง</span>
|
| 273 |
+
</div>
|
| 274 |
+
<div class="home-forest-floor">
|
| 275 |
+
<span class="home-tree left">๐ฒ</span>
|
| 276 |
+
<span class="home-grass grass-left">๐ฟ</span>
|
| 277 |
+
<span class="home-myco" title="Myco">๐</span>
|
| 278 |
+
<span class="home-brown-mushroom" title="Brown mushroom">๐โ๐ซ</span>
|
| 279 |
+
<span class="home-grass grass-right">๐</span>
|
| 280 |
+
<span class="home-tree right">๐ณ</span>
|
| 281 |
+
<span class="home-moon">๐</span>
|
| 282 |
+
</div>
|
| 283 |
+
<p><strong>The Milky Way is awake.</strong> Myco hears a brown mushroom whispering your first clue.</p>
|
| 284 |
+
<span class="home-whisper">"Tap Play. Let's find what the forest is hiding."</span>
|
| 285 |
+
</div>
|
| 286 |
+
"""
|
| 287 |
|
| 288 |
def play_hook_markdown() -> str:
|
| 289 |
+
return """
|
| 290 |
+
<div class="play-hook">
|
| 291 |
+
<p class="eyebrow">Mission</p>
|
| 292 |
+
<h2>Goal: follow clues until Myco remembers the Impossible Mushroom.</h2>
|
| 293 |
+
<div class="hook-steps">
|
| 294 |
+
<span>1 ยท Move through the forest</span>
|
| 295 |
+
<span>2 ยท Search Clearing โ mushroom pops up!</span>
|
| 296 |
+
<span>3 ยท Myco reacts ยท Pick, Study, or Follow Whisper</span>
|
| 297 |
+
</div>
|
| 298 |
+
<p>Every clue advances one mystery. Follow whispers to reveal why the MycoDex is regrowing a forest that vanished.</p>
|
| 299 |
+
</div>
|
| 300 |
+
"""
|
| 301 |
|
| 302 |
+
def forest_scene(
|
| 303 |
+
current: MushroomState | None,
|
| 304 |
+
collection: CollectionState | None,
|
| 305 |
+
position: tuple[int, int] | None = None,
|
| 306 |
+
) -> str:
|
| 307 |
+
count = len(_safe_collection(collection))
|
| 308 |
+
area = current_area(count)
|
| 309 |
pos_x, pos_y = _safe_position(position)
|
| 310 |
pos_cls = f"pos-{pos_x}-{pos_y}"
|
| 311 |
+
|
| 312 |
if current is None:
|
| 313 |
+
mushroom_name = "Hidden mushroom"
|
| 314 |
+
rarity = "common"
|
| 315 |
+
sprite = "โจ"
|
| 316 |
+
status = "The moss is listening. Click Search Clearing to wake the forest."
|
| 317 |
+
omen = "Myco is waiting to sense the first spore."
|
| 318 |
+
event_label = "๐ Dreaming Forest"
|
| 319 |
+
encounter = "The next clearing may reveal a memory, creature, or poison omen."
|
| 320 |
+
mystery_label = "The Wrong Memory"
|
| 321 |
+
score_total = "0"
|
| 322 |
+
health = "3"
|
| 323 |
+
reward_text = "Search a clearing to score spores."
|
| 324 |
+
state_cls = "state-waiting"
|
| 325 |
else:
|
| 326 |
mushroom_name = current.get("name", "Mystery mushroom")
|
| 327 |
+
rarity = current.get("rarity", "Common").lower()
|
| 328 |
+
sprite = "๐โ๐ซ"
|
| 329 |
+
game_over = current.get("game_over") == "Yes"
|
| 330 |
+
studied = current.get("studied") == "Yes"
|
| 331 |
+
event_label = f"{current.get('event_emoji','โจ')} {current.get('event_title','Strange Omen')}"
|
| 332 |
+
encounter = current.get("encounter", "The forest waits for Myco's reaction.")
|
| 333 |
+
mystery_label = current.get("mystery_title", "The Wrong Memory")
|
| 334 |
+
score_total = current.get("score_total", "0")
|
| 335 |
+
health = current.get("health", "3")
|
| 336 |
+
reward_text = current.get("reward_text", "Decide whether to risk the pickup.")
|
| 337 |
+
state_cls = _scene_state_class(current)
|
| 338 |
+
status = f"A {rarity} {mushroom_name} breaks through the moss!"
|
| 339 |
+
if game_over:
|
| 340 |
+
status = f"๐ GAME OVER: {mushroom_name} was poisonous!"
|
| 341 |
omen = "New field note unlocked." if studied else "Ask Myco what the forest is hiding."
|
| 342 |
+
if current.get("picked") == "Yes":
|
| 343 |
+
omen = "โ
Picked! Move to the next clearing."
|
| 344 |
+
if game_over:
|
| 345 |
+
omen = "Press Search Clearing to start a new run."
|
| 346 |
+
|
| 347 |
+
# Unique key forces browser to re-run CSS animations on every render
|
| 348 |
+
import time
|
| 349 |
anim_key = str(int(time.time() * 1000))[-6:]
|
|
|
|
| 350 |
|
| 351 |
+
return f'''{SCENE_STYLES}
|
| 352 |
+
<div class="forest-scene rarity-{escape(rarity)} {pos_cls} {state_cls}" data-key="{anim_key}">
|
| 353 |
+
<div class="scene-hud">
|
| 354 |
+
<span>๐งญ {escape(area.name)}</span>
|
| 355 |
+
<span>๐ฎ ({pos_x+1},{pos_y+1})</span>
|
| 356 |
+
<span>๐ {count} found</span>
|
| 357 |
+
<span>โญ {escape(score_total)}</span>
|
| 358 |
+
<span>โค๏ธ {escape(health)}/3</span>
|
| 359 |
+
<span>{escape(event_label)}</span>
|
| 360 |
+
<span>๐งฉ {escape(mystery_label)}</span>
|
| 361 |
+
</div>
|
| 362 |
+
|
| 363 |
+
<div class="scene-stage" aria-label="Magical forest scene">
|
| 364 |
+
<span class="tree tree-left">๐ฒ</span>
|
| 365 |
+
<span class="tree tree-right">๐ณ</span>
|
| 366 |
+
<span class="grass grass-one">๐ฟ</span>
|
| 367 |
+
<span class="grass grass-two">๐</span>
|
| 368 |
+
<span class="myco-player" title="Myco">๐</span>
|
| 369 |
+
<span class="mushroom-sprite" title="{escape(mushroom_name)}">{sprite if current else "โจ"}</span>
|
| 370 |
+
<span class="sparkle sparkle-one">โจ</span>
|
| 371 |
+
<span class="sparkle sparkle-two">โฆ</span>
|
| 372 |
+
</div>
|
| 373 |
+
|
| 374 |
+
<div class="forest-map" aria-label="Forest grid">
|
| 375 |
+
{_movement_tiles(pos_x, pos_y)}
|
| 376 |
+
</div>
|
| 377 |
+
|
| 378 |
+
<div class="scene-caption">
|
| 379 |
+
<strong>{escape(status)}</strong>
|
| 380 |
+
<span>{escape(omen)}</span>
|
| 381 |
+
</div>
|
| 382 |
+
<div class="score-burst" aria-live="polite">{escape(reward_text)}</div>
|
| 383 |
+
<div class="story-moment">
|
| 384 |
+
<strong>{escape(event_label)}</strong>
|
| 385 |
+
<span>{escape(encounter)}</span>
|
| 386 |
+
</div>
|
| 387 |
+
</div>
|
| 388 |
+
'''
|
| 389 |
|
| 390 |
def _safe_position(position):
|
| 391 |
if position is None:
|
|
|
|
| 591 |
</p>
|
| 592 |
</div>
|
| 593 |
"""
|
| 594 |
+
|
| 595 |
+
def get_emerging_mushroom_html(name: str) -> str:
|
| 596 |
+
"""
|
| 597 |
+
Generates a unique procedural mushroom sprite for the emerging state.
|
| 598 |
+
Uses the name hash to determine color and hue shift.
|
| 599 |
+
"""
|
| 600 |
+
hash_val = int(hashlib.md5(name.encode('utf-8')).hexdigest(), 16)
|
| 601 |
+
|
| 602 |
+
# Procedural color logic based on the name
|
| 603 |
+
hue = (hash_val % 360)
|
| 604 |
+
saturation = 60 + (hash_val % 30)
|
| 605 |
+
lightness = 40 + (hash_val % 20)
|
| 606 |
|
| 607 |
+
# This generates the HTML sprite using a CSS filter for consistent color variety
|
| 608 |
+
return (
|
| 609 |
+
f'<div class="mushroom-sprite" '
|
| 610 |
+
f'style="filter: hue-rotate({hue}deg) saturate({saturation}%) brightness({lightness}%); '
|
| 611 |
+
f'display: inline-block; transition: transform 0.3s ease;" '
|
| 612 |
+
f'title="{escape(name)}">๐</div>'
|
| 613 |
+
)
|