comparison pytouhou/vm/msgrunner.py @ 403:9589a01e6edf

Move MSG faces management to pytouhou.game.game, they have nothing to do in the MSG VM.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 17 Feb 2013 15:20:30 +0100
parents 69ec72b990a4
children cae1ae9de430
comparison
equal deleted inserted replaced
402:88e2a2485b2b 403:9589a01e6edf
14 14
15 15
16 from pytouhou.utils.helpers import get_logger 16 from pytouhou.utils.helpers import get_logger
17 17
18 from pytouhou.vm.common import MetaRegistry, instruction 18 from pytouhou.vm.common import MetaRegistry, instruction
19 from pytouhou.game.face import Face
20 19
21 logger = get_logger(__name__) 20 logger = get_logger(__name__)
22 21
23 22
24 class NextStage(Exception): 23 class NextStage(Exception):
26 25
27 26
28 class MSGRunner(object): 27 class MSGRunner(object):
29 __metaclass__ = MetaRegistry 28 __metaclass__ = MetaRegistry
30 __slots__ = ('_msg', '_game', 'frame', 'sleep_time', 'allow_skip', 29 __slots__ = ('_msg', '_game', 'frame', 'sleep_time', 'allow_skip',
31 'skipping', 'frozen', 'faces', 'ended', 'instruction_pointer', 30 'skipping', 'frozen', 'ended', 'instruction_pointer',
32 'handlers') 31 'handlers')
33 32
34 def __init__(self, msg, script, game): 33 def __init__(self, msg, script, game):
35 self._msg = msg.msgs[script + 10 * (game.players[0].state.character // 2)] 34 self._msg = msg.msgs[script + 10 * (game.players[0].state.character // 2)]
36 self._game = game 35 self._game = game
38 self.frame = 0 37 self.frame = 0
39 self.sleep_time = 0 38 self.sleep_time = 0
40 self.allow_skip = True 39 self.allow_skip = True
41 self.skipping = False 40 self.skipping = False
42 self.frozen = False 41 self.frozen = False
43
44 self.faces = [None, None]
45 game.msg_sprites = self.objects
46 self.ended = False 42 self.ended = False
47 43
48 self.instruction_pointer = 0 44 self.instruction_pointer = 0
49
50
51 def objects(self):
52 return [face for face in self.faces if face] if not self.ended else []
53 45
54 46
55 def run_iteration(self): 47 def run_iteration(self):
56 while True: 48 while True:
57 if self.ended: 49 if self.ended:
80 if self.sleep_time > 0: 72 if self.sleep_time > 0:
81 self.sleep_time -= 1 73 self.sleep_time -= 1
82 else: 74 else:
83 self.frame += 1 75 self.frame += 1
84 76
85 for face in self.faces:
86 if face:
87 face.update()
88
89 return True 77 return True
90 78
91 79
92 def skip(self): 80 def skip(self):
93 self.sleep_time = 0 81 self.sleep_time = 0
106 self.end() 94 self.end()
107 95
108 96
109 @instruction(1) 97 @instruction(1)
110 def enter(self, side, effect): 98 def enter(self, side, effect):
111 self.faces[side] = Face(self._game.msg_anm_wrapper, effect, side) 99 self._game.new_face(side, effect)
112 100
113 101
114 @instruction(2) 102 @instruction(2)
115 def change_face(self, side, index): 103 def change_face(self, side, index):
116 face = self.faces[side] 104 face = self._game.faces[side]
117 if face: 105 if face:
118 face.load(index) 106 face.load(index)
119 107
120 108
121 @instruction(4) 109 @instruction(4)
124 self.sleep_time = duration 112 self.sleep_time = duration
125 113
126 114
127 @instruction(5) 115 @instruction(5)
128 def animate(self, side, effect): 116 def animate(self, side, effect):
129 face = self.faces[side] 117 face = self._game.faces[side]
130 if face: 118 if face:
131 face.animate(effect) 119 face.animate(effect)
132 120
133 121
134 @instruction(6) 122 @instruction(6)