byte-vortex commited on
Commit
bcd6797
·
verified ·
1 Parent(s): 660f34a

Deploy Myco from CI

Browse files
Files changed (4) hide show
  1. tests/test_myco_core.py +10 -1
  2. ui/gradio_app.py +69 -18
  3. ui/renderers.py +38 -3
  4. ui/styles.py +35 -0
tests/test_myco_core.py CHANGED
@@ -19,7 +19,7 @@ from game.engine import (
19
  study_current,
20
  )
21
  from game.progression import current_area, next_area
22
- from ui.gradio_app import build_app
23
  from ui.renderers import (
24
  dex_markdown,
25
  forest_scene,
@@ -202,6 +202,15 @@ class MycoCoreTests(unittest.TestCase):
202
  self.assertNotEqual(studied["magic"], "Unknown")
203
  self.assertIn("blocks", eat_history[-1]["content"])
204
 
 
 
 
 
 
 
 
 
 
205
  def test_progress_and_dex_markdown_handle_empty_and_collected_state(self):
206
  _mushroom, current, _history = discover_mushroom([])
207
 
 
19
  study_current,
20
  )
21
  from game.progression import current_area, next_area
22
+ from ui.gradio_app import build_app, move_player
23
  from ui.renderers import (
24
  dex_markdown,
25
  forest_scene,
 
202
  self.assertNotEqual(studied["magic"], "Unknown")
203
  self.assertIn("blocks", eat_history[-1]["content"])
204
 
205
+ def test_movement_updates_forest_scene_position(self):
206
+ _mushroom, current, _history = discover_mushroom([])
207
+ position, scene, status = move_player((1, 1), "north", current, [])
208
+
209
+ self.assertEqual(position, (1, 0))
210
+ self.assertIn("pos-1-0", scene)
211
+ self.assertIn("Forest movement grid", scene)
212
+ self.assertIn("Map position", status)
213
+
214
  def test_progress_and_dex_markdown_handle_empty_and_collected_state(self):
215
  _mushroom, current, _history = discover_mushroom([])
216
 
ui/gradio_app.py CHANGED
@@ -26,6 +26,7 @@ from ui.renderers import (
26
  )
27
 
28
  EMPTY_COLLECTION = None
 
29
 
30
  HOME_MARKDOWN = """
31
  ## Welcome to the Myco forest
@@ -41,10 +42,10 @@ GUIDE_MARKDOWN = """
41
  ## How to play
42
 
43
  1. Go to **🎮 Play**.
44
- 2. Click **Start Exploring** to reveal a mushroom in the forest scene.
45
- 3. Ask Myco about the mushroom.
46
- 4. Choose **Study** for a safer hint, **Collect** for the MycoDex, or **Eat** to see Myco stop you.
47
- 5. Check **📖 MycoDex** to track discoveries and area unlocks.
48
  """
49
 
50
 
@@ -55,12 +56,13 @@ def mushroom_card_from_state(current):
55
  return mushroom_card(Mushroom.from_dict(current))
56
 
57
 
58
- def search_forest(collection):
59
  """Explore the forest and refresh every visible gameplay panel."""
60
  mushroom, current, history = discover_mushroom(collection)
 
61
  return (
62
- forest_scene(current, collection),
63
- game_status_markdown(current, collection),
64
  mushroom_card(mushroom),
65
  current,
66
  history,
@@ -74,13 +76,14 @@ def ask_companion(message, history, current):
74
  return myco_reply(message, history, current)
75
 
76
 
77
- def collect_discovery(current, collection, history):
78
  """Collect the active mushroom and refresh collection-dependent panels."""
79
  updated_collection, updated_history = collect_current(current, collection, history)
 
80
  return (
81
  updated_collection,
82
- forest_scene(current, updated_collection),
83
- game_status_markdown(current, updated_collection),
84
  dex_markdown(updated_collection),
85
  world_map_markdown(updated_collection),
86
  updated_history,
@@ -88,18 +91,46 @@ def collect_discovery(current, collection, history):
88
  )
89
 
90
 
91
- def study_discovery(current, history, collection):
92
  """Study the active mushroom and refresh the discovery card."""
93
  updated_current, updated_history = study_current(current, history)
 
94
  return (
95
  updated_current,
96
- forest_scene(updated_current, collection),
97
- game_status_markdown(updated_current, collection),
98
  mushroom_card_from_state(updated_current),
99
  updated_history,
100
  )
101
 
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  def block_unsafe_eating(current, history):
104
  """Let Myco prevent unsafe eating while preserving chat state."""
105
  return eat_current(current, history)
@@ -110,6 +141,7 @@ def build_app():
110
  with gr.Blocks(title="Myco") as demo:
111
  current_mushroom = gr.State(None)
112
  collection = gr.State([])
 
113
  gr.HTML(hero_markdown())
114
 
115
  with gr.Tabs():
@@ -119,9 +151,9 @@ def build_app():
119
 
120
  with gr.Tab("🎮 Play"):
121
  gr.HTML(play_hook_markdown())
122
- scene = gr.HTML(forest_scene(None, EMPTY_COLLECTION))
123
  status = gr.Markdown(
124
- game_status_markdown(None, EMPTY_COLLECTION),
125
  elem_id="quest-log",
126
  )
127
  with gr.Row():
@@ -131,6 +163,13 @@ def build_app():
131
  elem_id="discovery-card",
132
  )
133
  search_button = gr.Button("🌲 Explore the Forest", variant="primary")
 
 
 
 
 
 
 
134
  with gr.Row():
135
  eat_button = gr.Button("🍽️ Eat?")
136
  collect_button = gr.Button("📖 Collect")
@@ -169,7 +208,7 @@ def build_app():
169
 
170
  search_button.click(
171
  search_forest,
172
- inputs=(collection,),
173
  outputs=(scene, status, discovery, current_mushroom, chat, dex, progress),
174
  )
175
  ask_button.click(
@@ -177,6 +216,18 @@ def build_app():
177
  inputs=(prompt, chat, current_mushroom),
178
  outputs=(prompt, chat),
179
  )
 
 
 
 
 
 
 
 
 
 
 
 
180
  prompt.submit(
181
  ask_companion,
182
  inputs=(prompt, chat, current_mushroom),
@@ -184,12 +235,12 @@ def build_app():
184
  )
185
  collect_button.click(
186
  collect_discovery,
187
- inputs=(current_mushroom, collection, chat),
188
  outputs=(collection, scene, status, dex, world_map, chat, progress),
189
  )
190
  study_button.click(
191
  study_discovery,
192
- inputs=(current_mushroom, chat, collection),
193
  outputs=(current_mushroom, scene, status, discovery, chat),
194
  )
195
  eat_button.click(
 
26
  )
27
 
28
  EMPTY_COLLECTION = None
29
+ START_POSITION = (1, 1)
30
 
31
  HOME_MARKDOWN = """
32
  ## Welcome to the Myco forest
 
42
  ## How to play
43
 
44
  1. Go to **🎮 Play**.
45
+ 2. Use the arrow buttons to move Myco around the 3x3 forest grid.
46
+ 3. Click **Explore the Forest** to reveal a mushroom in the current clearing.
47
+ 4. Ask Myco what it senses, then choose **Study**, **Collect**, or **Eat?**
48
+ 5. Check **📖 MycoDex** and **🗺️ World Map** to track discoveries and area unlocks.
49
  """
50
 
51
 
 
56
  return mushroom_card(Mushroom.from_dict(current))
57
 
58
 
59
+ def search_forest(collection, position):
60
  """Explore the forest and refresh every visible gameplay panel."""
61
  mushroom, current, history = discover_mushroom(collection)
62
+ player_position = _safe_position(position)
63
  return (
64
+ forest_scene(current, collection, player_position),
65
+ game_status_markdown(current, collection, player_position),
66
  mushroom_card(mushroom),
67
  current,
68
  history,
 
76
  return myco_reply(message, history, current)
77
 
78
 
79
+ def collect_discovery(current, collection, history, position):
80
  """Collect the active mushroom and refresh collection-dependent panels."""
81
  updated_collection, updated_history = collect_current(current, collection, history)
82
+ player_position = _safe_position(position)
83
  return (
84
  updated_collection,
85
+ forest_scene(current, updated_collection, player_position),
86
+ game_status_markdown(current, updated_collection, player_position),
87
  dex_markdown(updated_collection),
88
  world_map_markdown(updated_collection),
89
  updated_history,
 
91
  )
92
 
93
 
94
+ def study_discovery(current, history, collection, position):
95
  """Study the active mushroom and refresh the discovery card."""
96
  updated_current, updated_history = study_current(current, history)
97
+ player_position = _safe_position(position)
98
  return (
99
  updated_current,
100
+ forest_scene(updated_current, collection, player_position),
101
+ game_status_markdown(updated_current, collection, player_position),
102
  mushroom_card_from_state(updated_current),
103
  updated_history,
104
  )
105
 
106
 
107
+ def move_player(position, direction, current, collection):
108
+ """Move Myco on a tiny 3x3 forest grid and refresh the scene."""
109
+ x, y = _safe_position(position)
110
+ if direction == "north":
111
+ y -= 1
112
+ elif direction == "south":
113
+ y += 1
114
+ elif direction == "west":
115
+ x -= 1
116
+ elif direction == "east":
117
+ x += 1
118
+ next_position = _safe_position((x, y))
119
+ return (
120
+ next_position,
121
+ forest_scene(current, collection, next_position),
122
+ game_status_markdown(current, collection, next_position),
123
+ )
124
+
125
+
126
+ def _safe_position(position):
127
+ """Return a valid 3x3 player position for Gradio state."""
128
+ if position is None:
129
+ return START_POSITION
130
+ x, y = position
131
+ return (max(0, min(2, int(x))), max(0, min(2, int(y))))
132
+
133
+
134
  def block_unsafe_eating(current, history):
135
  """Let Myco prevent unsafe eating while preserving chat state."""
136
  return eat_current(current, history)
 
141
  with gr.Blocks(title="Myco") as demo:
142
  current_mushroom = gr.State(None)
143
  collection = gr.State([])
144
+ player_position = gr.State(START_POSITION)
145
  gr.HTML(hero_markdown())
146
 
147
  with gr.Tabs():
 
151
 
152
  with gr.Tab("🎮 Play"):
153
  gr.HTML(play_hook_markdown())
154
+ scene = gr.HTML(forest_scene(None, EMPTY_COLLECTION, START_POSITION))
155
  status = gr.Markdown(
156
+ game_status_markdown(None, EMPTY_COLLECTION, START_POSITION),
157
  elem_id="quest-log",
158
  )
159
  with gr.Row():
 
163
  elem_id="discovery-card",
164
  )
165
  search_button = gr.Button("🌲 Explore the Forest", variant="primary")
166
+ with gr.Row():
167
+ north_button = gr.Button("▲")
168
+ with gr.Row():
169
+ west_button = gr.Button("◀")
170
+ east_button = gr.Button("▶")
171
+ with gr.Row():
172
+ south_button = gr.Button("▼")
173
  with gr.Row():
174
  eat_button = gr.Button("🍽️ Eat?")
175
  collect_button = gr.Button("📖 Collect")
 
208
 
209
  search_button.click(
210
  search_forest,
211
+ inputs=(collection, player_position),
212
  outputs=(scene, status, discovery, current_mushroom, chat, dex, progress),
213
  )
214
  ask_button.click(
 
216
  inputs=(prompt, chat, current_mushroom),
217
  outputs=(prompt, chat),
218
  )
219
+
220
+ for direction, button in (
221
+ ("north", north_button),
222
+ ("south", south_button),
223
+ ("west", west_button),
224
+ ("east", east_button),
225
+ ):
226
+ button.click(
227
+ move_player,
228
+ inputs=(player_position, gr.State(direction), current_mushroom, collection),
229
+ outputs=(player_position, scene, status),
230
+ )
231
  prompt.submit(
232
  ask_companion,
233
  inputs=(prompt, chat, current_mushroom),
 
235
  )
236
  collect_button.click(
237
  collect_discovery,
238
+ inputs=(current_mushroom, collection, chat, player_position),
239
  outputs=(collection, scene, status, dex, world_map, chat, progress),
240
  )
241
  study_button.click(
242
  study_discovery,
243
+ inputs=(current_mushroom, chat, collection, player_position),
244
  outputs=(current_mushroom, scene, status, discovery, chat),
245
  )
246
  eat_button.click(
ui/renderers.py CHANGED
@@ -37,10 +37,16 @@ def play_hook_markdown() -> str:
37
  """
38
 
39
 
40
- def forest_scene(current: MushroomState | None, collection: CollectionState | None) -> str:
 
 
 
 
41
  """Render a game-like forest scene for the current discovery."""
42
  count = len(_safe_collection(collection))
43
  area = current_area(count)
 
 
44
 
45
  if current is None:
46
  mushroom_name = "Hidden mushroom"
@@ -57,9 +63,10 @@ def forest_scene(current: MushroomState | None, collection: CollectionState | No
57
  omen = "New field note unlocked." if studied else "Ask Myco what the forest is hiding."
58
 
59
  return f'''
60
- <div class="forest-scene rarity-{escape(rarity.lower())}">
61
  <div class="scene-hud">
62
  <span>🧭 {escape(area.name)}</span>
 
63
  <span>📖 {count} MycoDex finds</span>
64
  </div>
65
  <div class="scene-stage" aria-label="Magical forest scene">
@@ -72,6 +79,9 @@ def forest_scene(current: MushroomState | None, collection: CollectionState | No
72
  <span class="sparkle sparkle-one">✨</span>
73
  <span class="sparkle sparkle-two">✦</span>
74
  </div>
 
 
 
75
  <div class="scene-caption">
76
  <strong>{escape(status)}</strong>
77
  <span>{escape(omen)}</span>
@@ -80,6 +90,25 @@ def forest_scene(current: MushroomState | None, collection: CollectionState | No
80
  '''
81
 
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  def _mushroom_sprite(rarity: str) -> str:
84
  """Return a simple scene sprite based on rarity."""
85
  if rarity == "Legendary":
@@ -89,9 +118,14 @@ def _mushroom_sprite(rarity: str) -> str:
89
  return "🍄"
90
 
91
 
92
- def game_status_markdown(current: MushroomState | None, collection: CollectionState | None) -> str:
 
 
 
 
93
  """Render the current objective like a compact game quest log."""
94
  count = len(_safe_collection(collection))
 
95
  if current is None:
96
  objective = "Click **Explore the Forest**. The first surprise should happen immediately."
97
  discovery = "No active discovery yet."
@@ -108,6 +142,7 @@ def game_status_markdown(current: MushroomState | None, collection: CollectionSt
108
  (
109
  "### 🎮 Quest Log",
110
  f"**MycoDex:** {count} discoveries",
 
111
  discovery,
112
  objective,
113
  ai_job,
 
37
  """
38
 
39
 
40
+ def forest_scene(
41
+ current: MushroomState | None,
42
+ collection: CollectionState | None,
43
+ position: tuple[int, int] | None = None,
44
+ ) -> str:
45
  """Render a game-like forest scene for the current discovery."""
46
  count = len(_safe_collection(collection))
47
  area = current_area(count)
48
+ pos_x, pos_y = _safe_position(position)
49
+ position_class = f"pos-{pos_x}-{pos_y}"
50
 
51
  if current is None:
52
  mushroom_name = "Hidden mushroom"
 
63
  omen = "New field note unlocked." if studied else "Ask Myco what the forest is hiding."
64
 
65
  return f'''
66
+ <div class="forest-scene rarity-{escape(rarity.lower())} {position_class}">
67
  <div class="scene-hud">
68
  <span>🧭 {escape(area.name)}</span>
69
+ <span>🎮 Myco: ({pos_x + 1}, {pos_y + 1})</span>
70
  <span>📖 {count} MycoDex finds</span>
71
  </div>
72
  <div class="scene-stage" aria-label="Magical forest scene">
 
79
  <span class="sparkle sparkle-one">✨</span>
80
  <span class="sparkle sparkle-two">✦</span>
81
  </div>
82
+ <div class="forest-map" aria-label="Forest movement grid">
83
+ {_movement_tiles(pos_x, pos_y)}
84
+ </div>
85
  <div class="scene-caption">
86
  <strong>{escape(status)}</strong>
87
  <span>{escape(omen)}</span>
 
90
  '''
91
 
92
 
93
+ def _safe_position(position: tuple[int, int] | None) -> tuple[int, int]:
94
+ """Return a clamped 3x3 forest-grid position."""
95
+ if position is None:
96
+ return (1, 1)
97
+ x, y = position
98
+ return (max(0, min(2, int(x))), max(0, min(2, int(y))))
99
+
100
+
101
+ def _movement_tiles(active_x: int, active_y: int) -> str:
102
+ """Render the tiny forest movement grid inside the scene."""
103
+ tiles = []
104
+ for y in range(3):
105
+ for x in range(3):
106
+ active = " active" if (x, y) == (active_x, active_y) else ""
107
+ icon = "🍄" if active else "·"
108
+ tiles.append(f'<span class="map-tile{active}">{icon}</span>')
109
+ return "".join(tiles)
110
+
111
+
112
  def _mushroom_sprite(rarity: str) -> str:
113
  """Return a simple scene sprite based on rarity."""
114
  if rarity == "Legendary":
 
118
  return "🍄"
119
 
120
 
121
+ def game_status_markdown(
122
+ current: MushroomState | None,
123
+ collection: CollectionState | None,
124
+ position: tuple[int, int] | None = None,
125
+ ) -> str:
126
  """Render the current objective like a compact game quest log."""
127
  count = len(_safe_collection(collection))
128
+ pos_x, pos_y = _safe_position(position)
129
  if current is None:
130
  objective = "Click **Explore the Forest**. The first surprise should happen immediately."
131
  discovery = "No active discovery yet."
 
142
  (
143
  "### 🎮 Quest Log",
144
  f"**MycoDex:** {count} discoveries",
145
+ f"**Map position:** ({pos_x + 1}, {pos_y + 1})",
146
  discovery,
147
  objective,
148
  ai_job,
ui/styles.py CHANGED
@@ -244,8 +244,18 @@ APP_CSS = """
244
  left: 42%;
245
  bottom: 15%;
246
  font-size: 4rem;
 
247
  animation: myco-bob 2.4s ease-in-out infinite;
248
  }
 
 
 
 
 
 
 
 
 
249
  .mushroom-sprite {
250
  right: 37%;
251
  bottom: 24%;
@@ -268,6 +278,31 @@ APP_CSS = """
268
  .rarity-legendary .mushroom-sprite {
269
  text-shadow: 0 0 24px rgba(193, 247, 255, 0.9);
270
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  .scene-caption {
272
  align-items: center;
273
  border-radius: 18px;
 
244
  left: 42%;
245
  bottom: 15%;
246
  font-size: 4rem;
247
+ transition: left 0.28s ease, bottom 0.28s ease;
248
  animation: myco-bob 2.4s ease-in-out infinite;
249
  }
250
+ .pos-0-0 .myco-player { left: 16%; bottom: 64%; }
251
+ .pos-1-0 .myco-player { left: 42%; bottom: 64%; }
252
+ .pos-2-0 .myco-player { left: 68%; bottom: 64%; }
253
+ .pos-0-1 .myco-player { left: 16%; bottom: 38%; }
254
+ .pos-1-1 .myco-player { left: 42%; bottom: 38%; }
255
+ .pos-2-1 .myco-player { left: 68%; bottom: 38%; }
256
+ .pos-0-2 .myco-player { left: 16%; bottom: 15%; }
257
+ .pos-1-2 .myco-player { left: 42%; bottom: 15%; }
258
+ .pos-2-2 .myco-player { left: 68%; bottom: 15%; }
259
  .mushroom-sprite {
260
  right: 37%;
261
  bottom: 24%;
 
278
  .rarity-legendary .mushroom-sprite {
279
  text-shadow: 0 0 24px rgba(193, 247, 255, 0.9);
280
  }
281
+
282
+ .forest-map {
283
+ display: grid;
284
+ grid-template-columns: repeat(3, 1fr);
285
+ gap: 0.35rem;
286
+ margin: 0.5rem auto 0.75rem;
287
+ max-width: 10rem;
288
+ padding: 0.45rem;
289
+ border: 1px solid rgba(255, 255, 255, 0.18);
290
+ border-radius: 16px;
291
+ background: rgba(13, 38, 28, 0.58);
292
+ }
293
+ .map-tile {
294
+ display: grid;
295
+ min-height: 1.8rem;
296
+ place-items: center;
297
+ border-radius: 10px;
298
+ background: rgba(255, 255, 255, 0.1);
299
+ font-weight: 900;
300
+ }
301
+ .map-tile.active {
302
+ background: rgba(255, 224, 138, 0.92);
303
+ color: #3d2c00 !important;
304
+ }
305
+
306
  .scene-caption {
307
  align-items: center;
308
  border-radius: 18px;