kwabs22 commited on
Commit
d9f8b8b
·
1 Parent(s): 984e889

Load game supports media now?

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -503,13 +503,18 @@ class GameSession:
503
  state = all_states[self.current_location][self.current_state]
504
  choices = [f"{idx + 1}. {choice}" for idx, choice in enumerate(state['choices'])]
505
  return state['description'], choices, "\n".join(self.game_log)
 
 
 
 
 
506
 
507
  def start_game(starting_location='village', starting_state='start'):
508
  game_session = GameSession(starting_location, starting_state)
509
  description, choices, game_log = game_session.get_current_state_info()
510
  return description, choices, game_log, game_session
511
 
512
- def make_choice(choice, game_session): #Calls the nested make choice function in the game session class
513
  if not choice:
514
  description, choices, game_log = game_session.get_current_state_info()
515
  return description, choices, "Please select a choice before proceeding.", game_session
@@ -517,7 +522,11 @@ def make_choice(choice, game_session): #Calls the nested make choice function in
517
  choice_index = int(choice.split('.')[0]) - 1
518
  result = game_session.make_choice(choice_index)
519
 
520
- return result[0], gr.update(choices=result[1]), result[2], game_session
 
 
 
 
521
 
522
  # def load_game(custom_config=None, with_media=False):
523
  # global all_states
@@ -739,8 +748,8 @@ with gr.Blocks() as demo:
739
  def dynamic_with_media(media_items):
740
  print(media_items)
741
  with gr.Group() as wamediagrouping:
742
- gr.HTML("Placeholder to load all media tests")
743
- if not media_items:
744
  gr.Markdown("No media items to display.")
745
  else:
746
  for item in media_items:
@@ -754,8 +763,8 @@ with gr.Blocks() as demo:
754
  wagame_session = gr.State(value=initgameinfo[3])
755
  wasubmit_btn.click(
756
  make_choice,
757
- inputs=[wachoices, wagame_session],
758
- outputs=[wadescription, wachoices, wagame_log, wagame_session]
759
  )
760
  with gr.Column(scale=1):
761
  gr.Markdown("# Debugging")
 
503
  state = all_states[self.current_location][self.current_state]
504
  choices = [f"{idx + 1}. {choice}" for idx, choice in enumerate(state['choices'])]
505
  return state['description'], choices, "\n".join(self.game_log)
506
+
507
+ def get_current_state_media(self):
508
+ media = all_states[self.current_location][self.current_state]['media']
509
+ return media
510
+
511
 
512
  def start_game(starting_location='village', starting_state='start'):
513
  game_session = GameSession(starting_location, starting_state)
514
  description, choices, game_log = game_session.get_current_state_info()
515
  return description, choices, game_log, game_session
516
 
517
+ def make_choice(choice, game_session, with_media=False): #Calls the nested make choice function in the game session class
518
  if not choice:
519
  description, choices, game_log = game_session.get_current_state_info()
520
  return description, choices, "Please select a choice before proceeding.", game_session
 
522
  choice_index = int(choice.split('.')[0]) - 1
523
  result = game_session.make_choice(choice_index)
524
 
525
+ if with_media:
526
+ media = game_session.get_current_state_media()
527
+ return result[0], gr.update(choices=result[1]), result[2], game_session, media
528
+ else:
529
+ return result[0], gr.update(choices=result[1]), result[2], game_session
530
 
531
  # def load_game(custom_config=None, with_media=False):
532
  # global all_states
 
748
  def dynamic_with_media(media_items):
749
  print(media_items)
750
  with gr.Group() as wamediagrouping:
751
+ gr.HTML("Placeholder to load all media tests - still need to test clearing media on ")
752
+ if media_items == []:
753
  gr.Markdown("No media items to display.")
754
  else:
755
  for item in media_items:
 
763
  wagame_session = gr.State(value=initgameinfo[3])
764
  wasubmit_btn.click(
765
  make_choice,
766
+ inputs=[wachoices, wagame_session, wamediabool],
767
+ outputs=[wadescription, wachoices, wagame_log, wagame_session, wamedia]
768
  )
769
  with gr.Column(scale=1):
770
  gr.Markdown("# Debugging")