naman1102 commited on
Commit
30641da
·
1 Parent(s): b4a7776
app.py CHANGED
@@ -142,10 +142,12 @@ class ScottPilgrimGame:
142
  self.player = ScottPilgrim()
143
  self.current_ex_list = list(self.scott_exes) # Use a copy of the list
144
  self.add_message("You chose to play as Scott Pilgrim! Get ready to face Ramona's Evil Exes!")
 
145
  elif character_choice == "Play as Ramona Flowers":
146
  self.player = RamonaFlowers()
147
  self.current_ex_list = list(self.ramona_exes) # Use a copy of the list
148
  self.add_message("You chose to play as Ramona Flowers! It's time to deal with Scott's complicated past!")
 
149
  else:
150
  self.add_message("Invalid character choice. Please select Scott or Ramona.")
151
  return
@@ -304,6 +306,10 @@ class ScottPilgrimGame:
304
  # Confirm purchase
305
  self.add_message(f"You bought {item_name} for ${cost}. Remaining money: ${self.player.money}.")
306
 
 
 
 
 
307
  # --- Gradio Interface Logic ---
308
 
309
  # Create a single game instance to be managed by gr.State
@@ -378,6 +384,8 @@ def update_ui(game_state):
378
 
379
  log_html = _format_log_html(game_state)
380
  status_html = _format_status_html(game_state)
 
 
381
 
382
  # Configure visibility for each game phase
383
  char_buttons_visible = (phase == "start")
@@ -385,9 +393,14 @@ def update_ui(game_state):
385
  play_again_visible = (phase in ["game_over", "win"])
386
  shop_visible = (phase == "combat")
387
 
 
 
388
  return (
389
  log_html,
390
  status_html,
 
 
 
391
  gr.update(visible=char_buttons_visible),
392
  gr.update(visible=action_buttons_visible),
393
  gr.update(visible=play_again_visible),
@@ -434,9 +447,15 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
434
  game_state = gr.State(game_instance)
435
 
436
  # UI Components
 
437
  game_output = gr.HTML(label="Game Log")
438
  status_output = gr.HTML(label="Current Status")
439
 
 
 
 
 
 
440
  with gr.Row(visible=True) as character_selection_buttons:
441
  scott_btn = gr.Button("Play as Scott Pilgrim")
442
  ramona_btn = gr.Button("Play as Ramona Flowers")
@@ -455,7 +474,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
455
 
456
  # --- Event Handlers ---
457
  # Define a list of all UI components that need to be updated, including the state
458
- outputs = [game_output, status_output, character_selection_buttons, game_action_buttons, play_again_btn, shop_row, game_state]
459
 
460
  # Connect buttons to their callback functions
461
  scott_btn.click(choose_character, inputs=[scott_btn, game_state], outputs=outputs)
 
142
  self.player = ScottPilgrim()
143
  self.current_ex_list = list(self.scott_exes) # Use a copy of the list
144
  self.add_message("You chose to play as Scott Pilgrim! Get ready to face Ramona's Evil Exes!")
145
+ self.player_image_path = "characters/Scott_idle.webp"
146
  elif character_choice == "Play as Ramona Flowers":
147
  self.player = RamonaFlowers()
148
  self.current_ex_list = list(self.ramona_exes) # Use a copy of the list
149
  self.add_message("You chose to play as Ramona Flowers! It's time to deal with Scott's complicated past!")
150
+ self.player_image_path = "characters/Ramona_Angry.webp"
151
  else:
152
  self.add_message("Invalid character choice. Please select Scott or Ramona.")
153
  return
 
306
  # Confirm purchase
307
  self.add_message(f"You bought {item_name} for ${cost}. Remaining money: ${self.player.money}.")
308
 
309
+ def get_player_image(self):
310
+ """Returns current player image path if set."""
311
+ return getattr(self, "player_image_path", None)
312
+
313
  # --- Gradio Interface Logic ---
314
 
315
  # Create a single game instance to be managed by gr.State
 
384
 
385
  log_html = _format_log_html(game_state)
386
  status_html = _format_status_html(game_state)
387
+ hero_img_path = game_state.get_player_image()
388
+ hero_visible = hero_img_path is not None
389
 
390
  # Configure visibility for each game phase
391
  char_buttons_visible = (phase == "start")
 
393
  play_again_visible = (phase in ["game_over", "win"])
394
  shop_visible = (phase == "combat")
395
 
396
+ preview_visible = (phase == "start")
397
+
398
  return (
399
  log_html,
400
  status_html,
401
+ gr.update(value=hero_img_path, visible=hero_visible),
402
+ gr.update(visible=preview_visible), # Scott preview
403
+ gr.update(visible=preview_visible), # Ramona preview
404
  gr.update(visible=char_buttons_visible),
405
  gr.update(visible=action_buttons_visible),
406
  gr.update(visible=play_again_visible),
 
447
  game_state = gr.State(game_instance)
448
 
449
  # UI Components
450
+ hero_img = gr.Image(label="Hero", width=200, height=200, visible=False)
451
  game_output = gr.HTML(label="Game Log")
452
  status_output = gr.HTML(label="Current Status")
453
 
454
+ # Preview images shown before character selection
455
+ with gr.Row(visible=True) as preview_row:
456
+ scott_preview_img = gr.Image(value="characters/Scott_idle.webp", label="Scott", width=140, height=140, visible=True)
457
+ ramona_preview_img = gr.Image(value="characters/Ramona_Angry.webp", label="Ramona", width=140, height=140, visible=True)
458
+
459
  with gr.Row(visible=True) as character_selection_buttons:
460
  scott_btn = gr.Button("Play as Scott Pilgrim")
461
  ramona_btn = gr.Button("Play as Ramona Flowers")
 
474
 
475
  # --- Event Handlers ---
476
  # Define a list of all UI components that need to be updated, including the state
477
+ outputs = [game_output, status_output, hero_img, scott_preview_img, ramona_preview_img, character_selection_buttons, game_action_buttons, play_again_btn, shop_row, game_state]
478
 
479
  # Connect buttons to their callback functions
480
  scott_btn.click(choose_character, inputs=[scott_btn, game_state], outputs=outputs)
characters/Ramona_Angry.webp ADDED
characters/Ramona_attack.webp ADDED
characters/Ramona_attack2.webp ADDED
characters/Scott_Attack.webp ADDED
characters/Scott_angry.webp ADDED
characters/Scott_idle.webp ADDED