Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -258,6 +258,13 @@ class ScottPilgrimGame:
|
|
| 258 |
"""Return list of item names with price for UI dropdown."""
|
| 259 |
return [f"{name} - ${data['cost']}" for name, data in self.shop_items.items()]
|
| 260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
def buy_item(self, item_display_name):
|
| 262 |
"""Process purchasing an item given the dropdown display string."""
|
| 263 |
if not self.player:
|
|
@@ -312,8 +319,8 @@ def _format_log_html(game_state):
|
|
| 312 |
player_name = game_state.player.name if game_state.player else ""
|
| 313 |
enemy_name = game_state.current_enemy.name if game_state.current_enemy else ""
|
| 314 |
|
| 315 |
-
# Show only the last
|
| 316 |
-
recent_msgs = game_state.message_log[-
|
| 317 |
|
| 318 |
html_lines = []
|
| 319 |
for msg in recent_msgs:
|
|
@@ -442,7 +449,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 442 |
|
| 443 |
# --- Shop UI Components ---
|
| 444 |
with gr.Row(visible=False) as shop_row:
|
| 445 |
-
|
|
|
|
| 446 |
buy_btn = gr.Button("Buy")
|
| 447 |
|
| 448 |
# --- Event Handlers ---
|
|
|
|
| 258 |
"""Return list of item names with price for UI dropdown."""
|
| 259 |
return [f"{name} - ${data['cost']}" for name, data in self.shop_items.items()]
|
| 260 |
|
| 261 |
+
def get_shop_description_html(self):
|
| 262 |
+
"""Return an HTML string listing shop items with cost and effect."""
|
| 263 |
+
lines = ["<b>Shop Items:</b>"]
|
| 264 |
+
for name, data in self.shop_items.items():
|
| 265 |
+
lines.append(f"{name} (${data['cost']}) – {data['desc']}")
|
| 266 |
+
return "<br>".join(lines)
|
| 267 |
+
|
| 268 |
def buy_item(self, item_display_name):
|
| 269 |
"""Process purchasing an item given the dropdown display string."""
|
| 270 |
if not self.player:
|
|
|
|
| 319 |
player_name = game_state.player.name if game_state.player else ""
|
| 320 |
enemy_name = game_state.current_enemy.name if game_state.current_enemy else ""
|
| 321 |
|
| 322 |
+
# Show only the last 2 log messages: latest action and its outcome
|
| 323 |
+
recent_msgs = game_state.message_log[-2:]
|
| 324 |
|
| 325 |
html_lines = []
|
| 326 |
for msg in recent_msgs:
|
|
|
|
| 449 |
|
| 450 |
# --- Shop UI Components ---
|
| 451 |
with gr.Row(visible=False) as shop_row:
|
| 452 |
+
shop_desc = gr.HTML(game_instance.get_shop_description_html())
|
| 453 |
+
item_dropdown = gr.Dropdown(choices=game_instance.get_shop_choices(), label="Buy Item")
|
| 454 |
buy_btn = gr.Button("Buy")
|
| 455 |
|
| 456 |
# --- Event Handlers ---
|