Spaces:
Sleeping
Sleeping
Deploy Myco from CI
Browse files- ui/renderers.py +27 -154
ui/renderers.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 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,
|
|
@@ -20,7 +21,6 @@ MATRIX_FLAT = [[0,0,1,1,1,1,1,1,0,0],[0,1,3,2,2,2,3,2,1,0],[1,2,2,2,3,2,2,2,2,1]
|
|
| 20 |
MATRIX_STAR = [[0,0,0,0,1,1,0,0,0,0],[0,1,0,1,2,2,1,0,1,0],[1,2,1,2,2,2,2,1,2,1],[0,1,2,3,2,2,3,2,1,0],[0,0,1,1,4,4,1,1,0,0],[0,0,0,1,4,4,1,0,0,0],[0,0,0,1,4,4,1,0,0,0],[0,0,0,1,1,1,1,0,0,0]]
|
| 21 |
|
| 22 |
def generate_mushroom_sprite(name: str) -> str:
|
| 23 |
-
"""Generates the procedural pixel mushroom visual."""
|
| 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)]
|
|
@@ -32,168 +32,41 @@ def generate_mushroom_sprite(name: str) -> str:
|
|
| 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 |
-
# โโ
|
| 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
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 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
|
| 140 |
-
sprite_html
|
| 141 |
-
game_over
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 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!
|
| 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:
|
|
|
|
| 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,
|
|
|
|
| 21 |
MATRIX_STAR = [[0,0,0,0,1,1,0,0,0,0],[0,1,0,1,2,2,1,0,1,0],[1,2,1,2,2,2,2,1,2,1],[0,1,2,3,2,2,3,2,1,0],[0,0,1,1,4,4,1,1,0,0],[0,0,0,1,4,4,1,0,0,0],[0,0,0,1,4,4,1,0,0,0],[0,0,0,1,1,1,1,0,0,0]]
|
| 22 |
|
| 23 |
def generate_mushroom_sprite(name: str) -> str:
|
|
|
|
| 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)]
|
|
|
|
| 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 |
+
# โโ SCENE STYLES โโ
|
| 36 |
+
SCENE_STYLES = """<style>.forest-scene { position: relative; isolation: isolate; overflow: hidden; min-height: 20rem; padding: 0.75rem; border-radius: 28px; 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%); border: 1px solid rgba(225,255,209,.25); box-shadow: 0 18px 48px rgba(8,30,20,.26); color: #f9ffe9; } .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; } .scene-stage { position: relative; height: 13rem; margin: .6rem 0; background: linear-gradient(transparent 62%, rgba(106,79,33,.55) 63%), radial-gradient(ellipse at bottom, rgba(190,255,180,.2), transparent 60%); border-radius: 22px; overflow: hidden; } .scene-stage span { position: absolute; line-height:1; } .tree-left { left:6%; bottom:18%; font-size:5rem; filter:drop-shadow(0 8px 12px rgba(0,0,0,.28)); } .tree-right { right:7%; bottom:20%; font-size:4.75rem; filter:drop-shadow(0 8px 12px rgba(0,0,0,.28)); } .grass-one { left:26%; bottom:14%; font-size:2.4rem; } .grass-two { right:28%; bottom:16%; font-size:2.2rem; } .sparkle-one { left:34%; top:18%; font-size:1.8rem; animation:twinkle 1.8s ease-in-out infinite; } .sparkle-two { right:33%; top:24%; font-size:1.6rem; animation:twinkle 2.2s ease-in-out infinite reverse; } @keyframes twinkle { 0%,100%{opacity:.3;transform:scale(.85);} 50%{opacity:1;transform:scale(1.18);} } .myco-player { font-size:4rem; z-index:2; transition: left .32s cubic-bezier(.34,1.56,.64,1), bottom .32s cubic-bezier(.34,1.56,.64,1); animation: myco-bob 2.4s ease-in-out infinite; filter:drop-shadow(0 6px 14px rgba(255,92,92,.28)); } @keyframes myco-bob { 0%,100%{transform:translateY(0);} 50%{transform:translateY(-.45rem);} } .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%;} .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%;} .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%;} .mushroom-sprite { position: absolute; right:33%; bottom:22%; z-index:2; filter:drop-shadow(0 6px 14px rgba(0,0,0,.3)); } .state-waiting .mushroom-sprite { opacity:0; } .state-discovered .mushroom-sprite { animation: shroom-popup 0.7s cubic-bezier(.34,1.56,.64,1) both; } .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; } @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); } } @keyframes myco-run-in { 0%{ transform:translateX(-3rem) scaleX(-1); } 100%{ transform:translateX(0) scaleX(1); } } .state-picked .mushroom-sprite { animation: shroom-catch 0.55s cubic-bezier(.34,1.56,.64,1) both; } .state-picked .myco-player { animation: myco-bob 2.4s ease-in-out infinite, myco-catch-jump 0.55s ease both; } @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); } } @keyframes myco-catch-jump { 0%,100%{ transform:translateY(0); } 40%{ transform:translateY(-1.4rem) scale(1.1); } } .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)); } .state-danger .myco-player { animation: myco-bob 2.4s ease-in-out infinite, myco-recoil 0.5s ease both; } @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)); } } @keyframes myco-recoil { 0%{ transform:translateX(0); } 30%{ transform:translateX(-1.2rem); } 60%{ transform:translateX(.4rem); } 100%{ transform:translateX(0); } } .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; } .state-game-over .mushroom-sprite { animation: shroom-explode .6s ease both; filter: drop-shadow(0 0 24px rgba(255,62,91,1)); } .state-game-over .myco-player { animation: myco-fall .6s ease both; } @keyframes screen-shake { 0%,100%{ transform:translateX(0); } 20%{ transform:translateX(-8px); } 40%{ transform:translateX(8px); } 60%{ transform:translateX(-5px); } 80%{ transform:translateX(5px); } } @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; } } @keyframes myco-fall { 0%{ transform:rotate(0) translateY(0); opacity:1; } 100%{ transform:rotate(-90deg) translateY(2rem); opacity:.4; } } .rarity-rare .mushroom-sprite { filter:drop-shadow(0 0 18px rgba(138,220,255,.9)); } .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; } @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); } } .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); } .map-tile { display:grid; min-height:1.7rem; place-items:center; border-radius:8px; background:rgba(255,255,255,.1); font-weight:900; } .map-tile.active { background:rgba(255,224,138,.92); color:#3d2c00!important; } .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; } .scene-caption span { color:#d9f4d4; } .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; } @keyframes score-pop { 0%{transform:scale(.92);opacity:0;} 45%{transform:scale(1.06);opacity:1;} 100%{transform:scale(1);opacity:1;} } .state-game-over .score-burst { background:rgba(130,0,30,.45); border-color:rgba(255,120,140,.55); } .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); } .story-moment strong,.story-moment span { display:block; } .story-moment span { margin-top:.2rem; color:#f6e7b2; } .generating .forest-scene, .pending .forest-scene { opacity:.88!important; } .progress-level,.progress-level-inner { display:none!important; } div.gradio-html { background:transparent!important; } .wrap.default.pending,.wrap.default.generating { background:transparent!important; }</style>"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
def hero_markdown() -> str:
|
| 39 |
+
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.</p></div></div>'
|
| 40 |
+
|
| 41 |
+
def home_forest_markdown() -> str:
|
| 42 |
+
return '<div class="home-forest-postcard"><p><strong>The Milky Way is awake.</strong> Myco hears a brown mushroom whispering your first clue.</p></div>'
|
| 43 |
+
|
| 44 |
+
def play_hook_markdown() -> str:
|
| 45 |
+
return '<div class="play-hook"><h2>Goal: follow clues until Myco remembers the Impossible Mushroom.</h2></div>'
|
| 46 |
+
|
| 47 |
+
def forest_scene(current: MushroomState | None, collection: CollectionState | None, position: tuple[int, int] | None = None) -> str:
|
| 48 |
+
count = len(_safe_collection(collection))
|
| 49 |
+
area = current_area(count)
|
| 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, rarity, sprite_html, status, omen = "Hidden mushroom", "common", "โจ", "The moss is listening.", "Myco is waiting."
|
| 54 |
+
event_label, encounter, mystery_label, score_total, health, reward_text, state_cls = "๐ Dreaming Forest", "...", "The Wrong Memory", "0", "3", "Search a clearing to score spores.", "state-waiting"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
else:
|
| 56 |
mushroom_name = current.get("name", "Mystery mushroom")
|
| 57 |
+
rarity = current.get("rarity", "Common").lower()
|
| 58 |
+
sprite_html = generate_mushroom_sprite(mushroom_name)
|
| 59 |
+
game_over, studied = current.get("game_over") == "Yes", current.get("studied") == "Yes"
|
| 60 |
+
event_label = f"{current.get('event_emoji','โจ')} {current.get('event_title','Strange Omen')}"
|
| 61 |
+
encounter, mystery_label = current.get("encounter", "..."), current.get("mystery_title", "The Wrong Memory")
|
| 62 |
+
score_total, health, reward_text = current.get("score_total", "0"), current.get("health", "3"), current.get("reward_text", "...")
|
| 63 |
+
state_cls = _scene_state_class(current)
|
| 64 |
+
status = f"A {rarity} {mushroom_name} breaks through the moss!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
omen = "New field note unlocked." if studied else "Ask Myco what the forest is hiding."
|
| 66 |
+
if current.get("picked") == "Yes": omen = "โ
Picked!"
|
|
|
|
|
|
|
|
|
|
| 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:
|