Spaces:
Sleeping
Sleeping
Deploy Myco from CI
Browse files- ui/scene_renderers.py +38 -338
ui/scene_renderers.py
CHANGED
|
@@ -1,350 +1,50 @@
|
|
| 1 |
-
"""
|
| 2 |
-
|
| 3 |
-
|
| 4 |
"""
|
| 5 |
|
| 6 |
-
from html import escape
|
| 7 |
import hashlib
|
| 8 |
-
from models.mushroom import Mushroom
|
| 9 |
-
|
| 10 |
-
POISONOUS_MUSHROOM_NAMES = {
|
| 11 |
-
"Ghost Gill", "Pepper Pixie", "Ruby Knuckle", "Clockwork Chanterelle",
|
| 12 |
-
}
|
| 13 |
|
| 14 |
# ── 8-BIT MATRIX BLUEPRINTS ──
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
[
|
| 24 |
-
|
| 25 |
-
[0,1,2,2,3,2,2,2,1,0], # Mid Cap
|
| 26 |
-
[1,2,3,2,2,2,3,2,2,1], # Wide Base
|
| 27 |
-
[1,1,1,1,1,4,1,1,1,1], # Cap Rim meeting Stem
|
| 28 |
-
[0,0,0,0,1,4,1,0,0,0], # Stem Trunk
|
| 29 |
-
[0,0,0,0,1,4,1,0,0,0], # Stem Trunk
|
| 30 |
-
[0,0,0,0,1,1,1,0,0,0] # Ground Base Outline
|
| 31 |
-
]
|
| 32 |
-
|
| 33 |
-
# Visualizing MATRIX_SKULL: Creates an eerie, hollow-eyed toxic mushroom shape
|
| 34 |
-
MATRIX_SKULL = [
|
| 35 |
-
[0,0,1,1,1,1,1,1,0,0],
|
| 36 |
-
[0,1,2,2,2,2,2,2,1,0],
|
| 37 |
-
[1,2,1,2,2,2,1,2,2,1], # Hollow eye slots (1) inside the cap
|
| 38 |
-
[1,2,1,2,2,2,1,2,2,1],
|
| 39 |
-
[0,1,2,2,1,1,2,2,1,0], # Tapering cheek bone shapes
|
| 40 |
-
[0,0,1,2,1,1,2,1,0,0],
|
| 41 |
-
[0,0,1,4,4,4,4,1,0,0], # Thick interlocking root stem
|
| 42 |
-
[0,0,0,1,1,1,1,0,0,0]
|
| 43 |
-
]
|
| 44 |
-
|
| 45 |
-
# Visualizing MATRIX_FLAT: Creates a wide, umbrella-like shelf fungus profile
|
| 46 |
-
MATRIX_FLAT = [
|
| 47 |
-
[0,0,1,1,1,1,1,1,0,0],
|
| 48 |
-
[0,1,3,2,2,2,3,2,1,0],
|
| 49 |
-
[1,2,2,2,3,2,2,2,2,1], # Wide, stretched horizontal frame
|
| 50 |
-
[1,1,1,1,4,4,1,1,1,1],
|
| 51 |
-
[0,0,0,1,4,4,1,0,0,0],
|
| 52 |
-
[0,0,0,1,4,4,1,0,0,0],
|
| 53 |
-
[0,0,1,4,4,4,4,1,0,0],
|
| 54 |
-
[0,0,1,1,1,1,1,1,0,0]
|
| 55 |
-
]
|
| 56 |
-
|
| 57 |
-
# Visualizing MATRIX_STAR: Creates a spiky, geometric magical star-cap shape
|
| 58 |
-
MATRIX_STAR = [
|
| 59 |
-
[0,0,0,0,1,1,0,0,0,0], # Star apex point
|
| 60 |
-
[0,1,0,1,2,2,1,0,1,0], # Spire flares
|
| 61 |
-
[1,2,1,2,2,2,2,1,2,1], # Wide lateral points
|
| 62 |
-
[0,1,2,3,2,2,3,2,1,0],
|
| 63 |
-
[0,0,1,1,4,4,1,1,0,0],
|
| 64 |
-
[0,0,0,1,4,4,1,0,0,0],
|
| 65 |
-
[0,0,0,1,4,4,1,0,0,0],
|
| 66 |
-
[0,0,0,1,1,1,1,0,0,0]
|
| 67 |
-
]
|
| 68 |
-
|
| 69 |
-
# Structural Sprite Mapping Directory
|
| 70 |
-
MUSHROOM_SPRITES = {
|
| 71 |
-
"poison": [MATRIX_SKULL, MATRIX_DOME, MATRIX_FLAT],
|
| 72 |
-
"legendary": [MATRIX_STAR, MATRIX_DOME, MATRIX_STAR],
|
| 73 |
-
"rare": [MATRIX_DOME, MATRIX_FLAT, MATRIX_DOME],
|
| 74 |
-
"cyberpunk": [MATRIX_FLAT, MATRIX_SKULL, MATRIX_DOME],
|
| 75 |
-
"pixel": [MATRIX_DOME, MATRIX_FLAT, MATRIX_DOME],
|
| 76 |
-
"common": ["🍄", "🍄🟫"] # Kept as clean text emojis as requested
|
| 77 |
-
}
|
| 78 |
-
|
| 79 |
-
SCENE_STYLES = """
|
| 80 |
-
<style>
|
| 81 |
-
/* ── Base Scene Container ── */
|
| 82 |
-
.forest-scene {
|
| 83 |
-
position: relative; isolation: isolate; overflow: hidden;
|
| 84 |
-
min-height: 22rem; padding: .75rem; border-radius: 28px;
|
| 85 |
-
transition: all 0.5s ease;
|
| 86 |
-
contain: layout style;
|
| 87 |
-
color: #f9ffe9;
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
/* ── STYLE 1: DEFAULT ORGANIC FOREST ── */
|
| 91 |
-
.theme-organic {
|
| 92 |
-
background:
|
| 93 |
-
radial-gradient(circle at 50% 72%, rgba(255,239,173,.26), transparent 8rem),
|
| 94 |
-
radial-gradient(circle at 18% 24%, rgba(134,225,153,.22), transparent 10rem),
|
| 95 |
-
linear-gradient(180deg, #123626 0%, #245c3c 54%, #523b20 100%);
|
| 96 |
-
border: 1px solid rgba(225,255,209,.25);
|
| 97 |
-
box-shadow: 0 18px 48px rgba(8,30,20,.26);
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
/* ── STYLE 2: CYBERPUNK NEON ── */
|
| 101 |
-
.theme-cyberpunk {
|
| 102 |
-
background: linear-gradient(180deg, #0d0116 0%, #1a0b2e 60%, #05000a 100%) !important;
|
| 103 |
-
border: 2px solid #ff007f !important;
|
| 104 |
-
box-shadow: 0 0 20px rgba(255, 0, 127, 0.4), inset 0 0 20px rgba(0, 242, 254, 0.2) !important;
|
| 105 |
-
font-family: 'Courier New', monospace;
|
| 106 |
-
}
|
| 107 |
-
.theme-cyberpunk .scene-hud { background: rgba(255, 0, 127, 0.2) !important; border: 1px solid #00f2fe; color: #00f2fe !important; }
|
| 108 |
-
.theme-cyberpunk .shroom-art-wrap { filter: drop-shadow(0 0 15px #00f2fe) drop-shadow(0 0 30px #ff007f) !important; }
|
| 109 |
-
|
| 110 |
-
/* ── STYLE 3: 8-BIT PIXEL ART ── */
|
| 111 |
-
.theme-pixel {
|
| 112 |
-
background: repeating-conic-gradient(#2a2a2a 0% 25%, #1f1f1f 0% 50%) 50% / 20px 20px !important;
|
| 113 |
-
border: 4px dashed #ffcc00 !important;
|
| 114 |
-
}
|
| 115 |
-
.theme-pixel * { font-family: 'Courier New', monospace; font-weight: bold; }
|
| 116 |
-
.theme-pixel .shroom-art-wrap {
|
| 117 |
-
transform: scale(1.4);
|
| 118 |
-
filter: drop-shadow(5px 5px 0px #000);
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
/* ── STYLE 4: GLITCH ART ── */
|
| 122 |
-
.theme-glitch {
|
| 123 |
-
background: linear-gradient(45deg, #111, #221a2b, #0a1c1c) !important;
|
| 124 |
-
border: 2px solid #00ffcc !important;
|
| 125 |
-
}
|
| 126 |
-
.theme-glitch .shroom-art-wrap {
|
| 127 |
-
animation: glitch-anim 1s linear infinite alternate !important;
|
| 128 |
-
}
|
| 129 |
-
@keyframes glitch-anim {
|
| 130 |
-
0% { transform: skew(0deg) scale(1); filter: hue-rotate(0deg); }
|
| 131 |
-
30% { transform: skew(-4deg) scale(1.05); filter: hue-rotate(90deg); }
|
| 132 |
-
70% { transform: skew(5deg) scale(0.95); filter: contrast(1.5); }
|
| 133 |
-
100% { transform: skew(0deg) scale(1); }
|
| 134 |
-
}
|
| 135 |
-
|
| 136 |
-
/* ── STYLE 5: SYNTHWAVE RETRO ── */
|
| 137 |
-
.theme-synthwave {
|
| 138 |
-
background:
|
| 139 |
-
linear-gradient(0deg, rgba(255, 105, 180, 0.15) 1px, transparent 1px),
|
| 140 |
-
linear-gradient(90deg, rgba(255, 105, 180, 0.15) 1px, transparent 1px),
|
| 141 |
-
linear-gradient(180deg, #2b003a 0%, #0c0014 100%) !important;
|
| 142 |
-
background-size: 20px 20px, 20px 20px, auto;
|
| 143 |
-
border: 1px solid #ff69b4 !important;
|
| 144 |
-
}
|
| 145 |
-
.theme-synthwave .shroom-art-wrap { animation: float-wave 3s ease-in-out infinite !important; }
|
| 146 |
-
@keyframes float-wave {
|
| 147 |
-
0%, 100% { transform: translateY(0px) rotate(-3deg); }
|
| 148 |
-
50% { transform: translateY(-8px) rotate(3deg); }
|
| 149 |
-
}
|
| 150 |
-
|
| 151 |
-
/* ── Core Layout Modules ── */
|
| 152 |
-
.scene-hud {
|
| 153 |
-
position: relative; z-index: 3;
|
| 154 |
-
display: flex; flex-wrap: wrap; gap: .4rem;
|
| 155 |
-
padding: .5rem .75rem; border-radius: 999px;
|
| 156 |
-
background: rgba(13,38,28,.72); backdrop-filter: blur(6px);
|
| 157 |
-
font-size: .78rem; font-weight: 800;
|
| 158 |
-
}
|
| 159 |
-
.scene-stage {
|
| 160 |
-
position: relative; height: 14rem; margin: .6rem 0;
|
| 161 |
-
background: radial-gradient(ellipse at bottom, rgba(190,255,180,.12), transparent 70%);
|
| 162 |
-
border-radius: 22px; overflow: hidden;
|
| 163 |
-
}
|
| 164 |
-
.scene-stage > * { position: absolute; line-height: 1; }
|
| 165 |
-
.ground-strip {
|
| 166 |
-
bottom: 0; left: 0; right: 0; height: 35%;
|
| 167 |
-
background: linear-gradient(180deg, rgba(80,50,15,0) 0%, rgba(20,15,30,0.4) 100%);
|
| 168 |
-
border-radius: 0 0 22px 22px;
|
| 169 |
-
}
|
| 170 |
-
|
| 171 |
-
/* Decor elements */
|
| 172 |
-
.tree-left { left: 4%; bottom: 30%; font-size: 5rem; opacity: 0.2; z-index: 1; }
|
| 173 |
-
.tree-right { right: 5%; bottom: 32%; font-size: 4.6rem; opacity: 0.2; z-index: 1; }
|
| 174 |
-
.myco-player {
|
| 175 |
-
font-size: 4.2rem; z-index: 5; bottom: 28%;
|
| 176 |
-
transition: left .38s cubic-bezier(.34,1.56,.64,1), bottom .38s cubic-bezier(.34,1.56,.64,1);
|
| 177 |
-
animation: myco-bob 2.4s ease-in-out infinite;
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
-
/* Positioning systems */
|
| 181 |
-
.pos-0-0 .myco-player{left:12%;bottom:55%;} .pos-1-0 .myco-player{left:40%;bottom:55%;} .pos-2-0 .myco-player{left:66%;bottom:55%;}
|
| 182 |
-
.pos-0-1 .myco-player{left:12%;bottom:40%;} .pos-1-1 .myco-player{left:40%;bottom:40%;} .pos-2-1 .myco-player{left:66%;bottom:40%;}
|
| 183 |
-
.pos-0-2 .myco-player{left:12%;bottom:26%;} .pos-1-2 .myco-player{left:40%;bottom:26%;} .pos-2-2 .myco-player{left:66%;bottom:26%;}
|
| 184 |
-
|
| 185 |
-
@keyframes myco-bob { 0%,100%{transform:translateY(0);} 50%{transform:translateY(-.4rem);} }
|
| 186 |
-
|
| 187 |
-
/* Mushroom Spot Architecture */
|
| 188 |
-
.mushroom-spot { z-index: 4; display: flex; flex-direction: column; align-items: center; right: 30%; bottom: 34%; }
|
| 189 |
-
.shroom-art-wrap { display: inline-block; image-rendering: pixelated; image-rendering: crisp-edges; }
|
| 190 |
-
.shroom-emoji-fallback { font-size: 2.8rem; line-height: 1; }
|
| 191 |
-
|
| 192 |
-
/* State Modifications */
|
| 193 |
-
.state-waiting .mushroom-spot { display: none; }
|
| 194 |
-
.state-picked .shroom-art-wrap, .state-picked .shroom-emoji-fallback { animation: shroom-fly .6s ease both; }
|
| 195 |
-
@keyframes shroom-fly { 100% { transform: translateY(-10rem) scale(0); opacity: 0; } }
|
| 196 |
-
|
| 197 |
-
.state-game-over { filter: grayscale(0.8) contrast(1.2); background: #220000 !important; }
|
| 198 |
-
</style>
|
| 199 |
-
"""
|
| 200 |
-
|
| 201 |
-
def render_matrix_to_pixels(matrix: list[list[int]], cap_color: str, spot_color: str, stem_color: str) -> str:
|
| 202 |
-
"""Processes numerical 2D array mappings into rendering coordinate data strings."""
|
| 203 |
-
color_map = {
|
| 204 |
-
1: "#121214", # Outer outline values
|
| 205 |
-
2: cap_color, # Active surface cap hex color
|
| 206 |
-
3: spot_color, # Active dot accent hex color
|
| 207 |
-
4: stem_color # Main foot stem hex color
|
| 208 |
-
}
|
| 209 |
|
| 210 |
-
|
| 211 |
-
|
| 212 |
|
| 213 |
-
|
| 214 |
-
for c_idx, val in enumerate(row):
|
| 215 |
-
if val in color_map:
|
| 216 |
-
# Math Translation: column * width, row * height offsets mapping out shapes
|
| 217 |
-
shadow_layers.append(f"{c_idx * px_scale}px {r_idx * px_scale}px 0 {color_map[val]}")
|
| 218 |
-
|
| 219 |
-
width = len(matrix[0]) * px_scale
|
| 220 |
-
height = len(matrix) * px_scale
|
| 221 |
-
return f'<div style="width:{px_scale}px; height:{px_scale}px; margin-right:{width}px; margin-bottom:{height}px; background:transparent; box-shadow:{", ".join(shadow_layers)};"></div>'
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
def get_art_theme(mushroom_name: str) -> tuple[str, str, str, str, str]:
|
| 225 |
-
"""Resolves background themes and color hex codes based on the unique mushroom name."""
|
| 226 |
-
if not mushroom_name:
|
| 227 |
-
return "theme-organic", "Organic Form", "#e63946", "#ffffff", "#f1faee"
|
| 228 |
-
|
| 229 |
-
hash_val = int(hashlib.md5(mushroom_name.encode('utf-8')).hexdigest(), 16)
|
| 230 |
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
("theme-cyberpunk", "⚡ Neon Cyberpunk", "#00f2fe", "#ff007f", "#25003e"),
|
| 235 |
-
("theme-pixel", "🕹️ 8-Bit Pixel", "#ffb703", "#ffffff", "#fb8500"),
|
| 236 |
-
("theme-glitch", "👾 Glitch Art", "#00ffcc", "#ff0055", "#111111"),
|
| 237 |
-
("theme-synthwave", "🌌 Synthwave Retro", "#ff007f", "#7209b7", "#4cc9f0")
|
| 238 |
-
]
|
| 239 |
-
return themes[hash_val % len(themes)]
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
def forest_scene(current, collection, position):
|
| 243 |
-
"""Assembles and generates the final viewable HTML interface snippet."""
|
| 244 |
-
px, py = position if position else (1, 1)
|
| 245 |
-
|
| 246 |
-
state_class = "state-waiting"
|
| 247 |
-
theme_class = "theme-organic"
|
| 248 |
-
style_title = "Organic"
|
| 249 |
|
| 250 |
-
cap_hex, spot_hex, stem_hex = "#d62828", "#fcbf49", "#eae2b7"
|
| 251 |
-
markup_out = ""
|
| 252 |
-
|
| 253 |
-
if current:
|
| 254 |
-
name = current.get("name", "")
|
| 255 |
-
is_poison = name in POISONOUS_MUSHROOM_NAMES or current.get("poison") == "Yes"
|
| 256 |
-
is_picked = current.get("picked") == "Yes"
|
| 257 |
-
is_game_over = current.get("game_over") == "Yes"
|
| 258 |
-
rarity = current.get("rarity", "Common").lower()
|
| 259 |
-
|
| 260 |
-
# 1. Resolve theme information
|
| 261 |
-
theme_class, style_title, cap_hex, spot_hex, stem_hex = get_art_theme(name)
|
| 262 |
-
|
| 263 |
-
if is_game_over:
|
| 264 |
-
state_class = "state-game-over"
|
| 265 |
-
cap_hex, spot_hex, stem_hex = "#2b2b2b", "#1a1a1a", "#444444"
|
| 266 |
-
elif is_picked:
|
| 267 |
-
state_class = "state-picked"
|
| 268 |
-
else:
|
| 269 |
-
state_class = "state-discovered"
|
| 270 |
-
|
| 271 |
-
if is_poison:
|
| 272 |
-
cap_hex, spot_hex, stem_hex = "#7a0010", "#ff3333", "#3a0007"
|
| 273 |
-
style_title += " (⚠️ TOXIC DETECTED)"
|
| 274 |
-
|
| 275 |
-
# 2. Select targeted key mapping category
|
| 276 |
-
if is_poison:
|
| 277 |
-
pool_key = "poison"
|
| 278 |
-
elif theme_class == "theme-cyberpunk":
|
| 279 |
-
pool_key = "cyberpunk"
|
| 280 |
-
elif theme_class == "theme-pixel":
|
| 281 |
-
pool_key = "pixel"
|
| 282 |
-
else:
|
| 283 |
-
pool_key = rarity if rarity in MUSHROOM_SPRITES else "common"
|
| 284 |
-
|
| 285 |
-
# 3. Translate lookups directly into output markup
|
| 286 |
-
pool_variants = MUSHROOM_SPRITES.get(pool_key, MUSHROOM_SPRITES["common"])
|
| 287 |
-
name_hash = int(hashlib.md5(name.encode('utf-8')).hexdigest(), 16)
|
| 288 |
-
chosen_variant = pool_variants[name_hash % len(pool_variants)]
|
| 289 |
-
|
| 290 |
-
if isinstance(chosen_variant, list):
|
| 291 |
-
# If our sprite registry contains a list matrix, send it to the processing loop
|
| 292 |
-
pixel_data = render_matrix_to_pixels(chosen_variant, cap_hex, spot_hex, stem_hex)
|
| 293 |
-
markup_out = f'<div class="shroom-art-wrap">{pixel_data}</div>'
|
| 294 |
-
else:
|
| 295 |
-
# Fallback directly to text strings for basic standard variations
|
| 296 |
-
markup_out = f'<div class="shroom-emoji-fallback">{chosen_variant}</div>'
|
| 297 |
-
|
| 298 |
return f"""
|
| 299 |
-
{
|
| 300 |
-
<
|
| 301 |
-
<div class="scene-hud">
|
| 302 |
-
<span>📍 Region: X:{px} Y:{py}</span>
|
| 303 |
-
<span>Render Engine: {style_title}</span>
|
| 304 |
-
<span>{"🍄 Matrix Assembly Active" if state_class != "state-waiting" else "🌿 Scanning clearing..."}</span>
|
| 305 |
-
</div>
|
| 306 |
-
<div class="scene-stage">
|
| 307 |
-
<span class="tree-left">🌲</span>
|
| 308 |
-
<span class="tree-right">🌳</span>
|
| 309 |
-
<div class="ground-strip"></div>
|
| 310 |
-
|
| 311 |
-
<div class="myco-player">🍄</div>
|
| 312 |
-
|
| 313 |
-
<div class="mushroom-spot">
|
| 314 |
-
{markup_out}
|
| 315 |
-
</div>
|
| 316 |
-
</div>
|
| 317 |
-
</div>
|
| 318 |
"""
|
| 319 |
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
if not
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
def progress_markdown(collection):
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
def
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
score = sum(int(e.get("score_delta", 10)) for e in collection) if collection else 0
|
| 338 |
-
return f"**Score:** {score} Spores"
|
| 339 |
-
|
| 340 |
-
def hero_markdown():
|
| 341 |
-
return "<div style='font-size:24px; text-align:center; font-weight:bold; margin-bottom: 20px;'>🌲 Myco's Forest 🌲</div>"
|
| 342 |
-
|
| 343 |
-
def home_forest_markdown():
|
| 344 |
-
return "<div style='text-align:center; font-size:40px; margin: 20px 0;'>🍄 🌲 🍄</div>"
|
| 345 |
-
|
| 346 |
-
def game_intro_markdown():
|
| 347 |
-
return "### 🌿 Step into the clearing and search for magic..."
|
| 348 |
-
|
| 349 |
-
def play_hook_markdown():
|
| 350 |
-
return "What will Myco discover next?"
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Myco Engine: Mushroom Emergence System.
|
| 3 |
+
Provides rendering primitives for the game interface.
|
| 4 |
"""
|
| 5 |
|
|
|
|
| 6 |
import hashlib
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# ── 8-BIT MATRIX BLUEPRINTS ──
|
| 9 |
+
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]]
|
| 10 |
+
MATRIX_SKULL = [[0,0,1,1,1,1,1,1,0,0],[0,1,2,2,2,2,2,2,1,0],[1,2,1,2,2,2,1,2,2,1],[1,2,1,2,2,2,1,2,2,1],[0,1,2,2,1,1,2,2,1,0],[0,0,1,2,1,1,2,1,0,0],[0,0,1,4,4,4,4,1,0,0],[0,0,0,1,1,1,1,0,0,0]]
|
| 11 |
+
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],[1,1,1,1,4,4,1,1,1,1],[0,0,0,1,4,4,1,0,0,0],[0,0,0,1,4,4,1,0,0,0],[0,0,1,4,4,4,4,1,0,0],[0,0,1,1,1,1,1,1,0,0]]
|
| 12 |
+
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]]
|
| 13 |
+
|
| 14 |
+
def generate_mushroom_sprite(name: str) -> str:
|
| 15 |
+
"""Core function to generate the pixel mushroom visual."""
|
| 16 |
+
hash_val = int(hashlib.md5(name.encode('utf-8')).hexdigest(), 16)
|
| 17 |
+
shapes = [MATRIX_DOME, MATRIX_SKULL, MATRIX_FLAT, MATRIX_STAR]
|
| 18 |
+
matrix = shapes[hash_val % len(shapes)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
palettes = [("#d62828", "#f77f00", "#fcbf49"), ("#00f2fe", "#ff007f", "#25003e"), ("#ffb703", "#ffffff", "#fb8500")]
|
| 21 |
+
c_cap, c_spot, c_stem = palettes[hash_val % len(palettes)]
|
| 22 |
|
| 23 |
+
color_map = {1: "#121214", 2: c_cap, 3: c_spot, 4: c_stem}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
px_scale = 8
|
| 26 |
+
shadows = [f"{c*px_scale}px {r*px_scale}px 0 {color_map[v]}"
|
| 27 |
+
for r, row in enumerate(matrix) for c, v in enumerate(row) if v in color_map]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
return f"""
|
| 30 |
+
<div style="width:{px_scale}px; height:{px_scale}px; box-shadow: {', '.join(shadows)}; margin: 50px auto; animation: emerge 1s ease-out;"></div>
|
| 31 |
+
<style>@keyframes emerge {{ 0% {{ transform: scale(0) rotate(-45deg); opacity: 0; }} 100% {{ transform: scale(1) rotate(0deg); opacity: 1; }} }}</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
"""
|
| 33 |
|
| 34 |
+
def render_mushroom_stage(current, collection, position):
|
| 35 |
+
"""Renamed primary scene renderer."""
|
| 36 |
+
if not current:
|
| 37 |
+
return "<div style='text-align:center; padding:50px;'>Searching for growth...</div>"
|
| 38 |
+
return generate_mushroom_sprite(current.get("name", "Unknown"))
|
| 39 |
+
|
| 40 |
+
# ── Legacy/Support functions preserved for app compatibility ──
|
| 41 |
+
def mushroom_card(mush_obj, *args, **kwargs): return f"**{mush_obj.name}** emerging..."
|
| 42 |
+
def dex_markdown(collection): return "Dex updated."
|
| 43 |
+
def progress_markdown(collection): return "Growth detected."
|
| 44 |
+
def world_map_markdown(collection): return "Map locked."
|
| 45 |
+
def game_status_markdown(*args): return "Engine: Online"
|
| 46 |
+
def hero_markdown(): return ""
|
| 47 |
+
def home_forest_markdown(): return ""
|
| 48 |
+
def game_intro_markdown(): return ""
|
| 49 |
+
def play_hook_markdown(): return ""
|
| 50 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|