changeset 336:72ef7e24b373

Fix MSG skipping.
author Thibaut Girka <thib@sitedethib.com>
date Sun, 01 Jul 2012 18:06:11 +0200
parents 2350147cf043
children bc162f60f0a0
files pytouhou/game/game.py pytouhou/vm/msgrunner.py
diffstat 2 files changed, 6 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/game.py
+++ b/pytouhou/game/game.py
@@ -258,10 +258,9 @@ class Game(object):
 
 
     def update_msg(self, keystate):
-        if keystate & 1 and not self.last_keystate & 1:
+        if any((keystate & k and not self.last_keystate & k) for k in (1, 256)):
             self.msg_runner.skip()
-        if keystate & 256 and self.msg_runner.allow_skip:
-            self.msg_runner.skip()
+        self.msg_runner.skipping = bool(keystate & 256)
         self.last_keystate = keystate
         self.msg_runner.run_iteration()
 
--- a/pytouhou/vm/msgrunner.py
+++ b/pytouhou/vm/msgrunner.py
@@ -28,7 +28,7 @@ class NextStage(Exception):
 class MSGRunner(object):
     __metaclass__ = MetaRegistry
     __slots__ = ('_msg', '_game', 'frame', 'sleep_time', 'allow_skip',
-                 'frozen', 'faces', 'ended', 'instruction_pointer')
+                 'skipping', 'frozen', 'faces', 'ended', 'instruction_pointer')
 
     def __init__(self, msg, script, game):
         self._msg = msg.msgs[script + 10 * (game.players[0].state.character // 2)]
@@ -36,6 +36,7 @@ class MSGRunner(object):
         self.frame = 0
         self.sleep_time = 0
         self.allow_skip = True
+        self.skipping = False
         self.frozen = False
 
         self.faces = [None, None]
@@ -117,7 +118,8 @@ class MSGRunner(object):
 
     @instruction(4)
     def pause(self, duration):
-        self.sleep_time = duration
+        if not (self.skipping and self.allow_skip):
+            self.sleep_time = duration
 
 
     @instruction(5)