changeset 378:11d895b6c0dc

Add the debug feature to start a game at the end of a replay.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 29 Aug 2012 18:38:29 +0200
parents 70e2ed71b09c
children e0e284fcb288
files eosd pytouhou/ui/gamerunner.py
diffstat 2 files changed, 33 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/eosd
+++ b/eosd
@@ -63,8 +63,8 @@ class EoSDGameBossRush(EoSDGame):
 
 
 def main(path, data, stage_num, rank, character, replay, save_filename,
-         boss_rush, fps_limit, single_buffer, debug, fixed_pipeline,
-         display_background):
+         skip_replay, boss_rush, fps_limit, single_buffer, debug,
+         fixed_pipeline, display_background):
 
     resource_loader = Loader(path)
 
@@ -104,7 +104,7 @@ def main(path, data, stage_num, rank, ch
 
     game_class = EoSDGameBossRush if boss_rush else EoSDGame
 
-    runner = GameRunner(resource_loader, fps_limit=fps_limit, double_buffer=(not single_buffer), fixed_pipeline=fixed_pipeline)
+    runner = GameRunner(resource_loader, fps_limit=fps_limit, double_buffer=(not single_buffer), fixed_pipeline=fixed_pipeline, skip=skip_replay)
     while True:
         if replay:
             level = replay.levels[stage_num - 1]
@@ -194,6 +194,7 @@ parser.add_argument('-r', '--rank', meta
 parser.add_argument('-c', '--character', metavar='CHARACTER', type=int, default=0, help='Select the character to use, from 0 (ReimuA, default) to 3 (MarisaB).')
 parser.add_argument('--replay', metavar='REPLAY', help='Select a replay')
 parser.add_argument('--save-replay', metavar='REPLAY', help='Save the upcoming game into a replay file')
+parser.add_argument('--skip-replay', action='store_true', help='Skip the replay and start to play when it’s finished')
 parser.add_argument('-b', '--boss-rush', action='store_true', help='Fight only bosses')
 parser.add_argument('--single-buffer', action='store_true', help='Disable double buffering')
 parser.add_argument('--fps-limit', metavar='FPS', default=60, type=int, help='Set fps limit')
@@ -204,5 +205,6 @@ parser.add_argument('--no-background', a
 args = parser.parse_args()
 
 main(args.path, tuple(args.data), args.stage, args.rank, args.character,
-     args.replay, args.save_replay, args.boss_rush, args.fps_limit,
-     args.single_buffer, args.debug, args.fixed_pipeline, args.no_background)
+     args.replay, args.save_replay, args.skip_replay, args.boss_rush,
+     args.fps_limit, args.single_buffer, args.debug, args.fixed_pipeline,
+     args.no_background)
--- a/pytouhou/ui/gamerunner.py
+++ b/pytouhou/ui/gamerunner.py
@@ -37,7 +37,7 @@ logger = get_logger(__name__)
 
 
 class GameRunner(pyglet.window.Window, GameRenderer):
-    def __init__(self, resource_loader, game=None, background=None, replay=None, double_buffer=True, fps_limit=60, fixed_pipeline=False):
+    def __init__(self, resource_loader, game=None, background=None, replay=None, double_buffer=True, fps_limit=60, fixed_pipeline=False, skip=False):
         GameRenderer.__init__(self, resource_loader, game, background)
 
         config = pyglet.gl.Config(double_buffer=double_buffer)
@@ -49,6 +49,7 @@ class GameRunner(pyglet.window.Window, G
         self.fps_limit = fps_limit
         self.use_fixed_pipeline = fixed_pipeline
         self.replay_level = None
+        self.skip = skip
 
         if not self.use_fixed_pipeline:
             self.game_shader = GameShader()
@@ -63,13 +64,8 @@ class GameRunner(pyglet.window.Window, G
 
     def load_game(self, game=None, background=None, bgms=None, replay=None, save_keystates=None):
         GameRenderer.load_game(self, game, background)
-        self.replay_level = None
-        if not replay or not replay.levels[game.stage-1]:
-            self.keys = pyglet.window.key.KeyStateHandler()
-            self.push_handlers(self.keys)
-        else:
-            self.replay_level = replay.levels[game.stage-1]
-            self.keys = self.replay_level.iter_keystates()
+        self.set_input(replay)
+        if replay and replay.levels[game.stage - 1]:
             game.players[0].state.lives = self.replay_level.lives
             game.players[0].state.power = self.replay_level.power
             game.players[0].state.bombs = self.replay_level.bombs
@@ -84,6 +80,16 @@ class GameRunner(pyglet.window.Window, G
         game.enemy_sfx = SFXPlayer(game.resource_loader)
 
 
+    def set_input(self, replay=None):
+        if not replay or not replay.levels[self.game.stage-1]:
+            self.keys = pyglet.window.key.KeyStateHandler()
+            self.push_handlers(self.keys)
+            self.replay_level = None
+        else:
+            self.replay_level = replay.levels[self.game.stage-1]
+            self.keys = self.replay_level.iter_keystates()
+
+
     def start(self, width=None, height=None):
         width = width or (self.game.interface.width if self.game else 640)
         height = height or (self.game.interface.height if self.game else 480)
@@ -108,12 +114,15 @@ class GameRunner(pyglet.window.Window, G
         if self.fps_limit > 0:
             pyglet.clock.set_fps_limit(self.fps_limit)
         while not self.has_exit:
-            pyglet.clock.tick()
-            self.dispatch_events()
-            self.update()
-            self.render_game()
-            self.render_interface()
-            self.flip()
+            if not self.skip:
+                pyglet.clock.tick()
+                self.dispatch_events()
+                self.update()
+                self.render_game()
+                self.render_interface()
+                self.flip()
+            else:
+                self.update()
 
 
     def _event_text_symbol(self, ev):
@@ -165,6 +174,9 @@ class GameRunner(pyglet.window.Window, G
                     keystate = self.keys.next()
                 except StopIteration:
                     keystate = 0
+                    if self.skip:
+                        self.set_input()
+                        self.skip = False
 
             if self.save_keystates is not None:
                 self.save_keystates.append(keystate)