diff pytouhou/ui/gamerunner.py @ 374:6a63fd3deb76

Use an iterator to get the keystates from a replay.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 05 Aug 2012 18:19:42 +0200
parents 6deab6ad8be8
children 11d895b6c0dc
line wrap: on
line diff
--- a/pytouhou/ui/gamerunner.py
+++ b/pytouhou/ui/gamerunner.py
@@ -68,8 +68,8 @@ class GameRunner(pyglet.window.Window, G
             self.keys = pyglet.window.key.KeyStateHandler()
             self.push_handlers(self.keys)
         else:
-            self.keys = 0
             self.replay_level = replay.levels[game.stage-1]
+            self.keys = self.replay_level.iter_keystates()
             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
@@ -161,12 +161,10 @@ class GameRunner(pyglet.window.Window, G
                 if self.keys[pyglet.window.key.LCTRL]:
                     keystate |= 256
             else:
-                keystate = 0
-                for frame, _keystate, unknown in self.replay_level.keys:
-                    if self.game.frame < frame:
-                        break
-                    else:
-                        keystate = _keystate
+                try:
+                    keystate = self.keys.next()
+                except StopIteration:
+                    keystate = 0
 
             if self.save_keystates is not None:
                 self.save_keystates.append(keystate)