Mercurial > touhou
comparison pytouhou/formats/anm0.py @ 236:741860192b56
Implement ANM0 interrupts
“Instruction” 22 is used as a label for interrupts.
If the normal animation is interrupted, it goes straight to the matched
instruction. Interrupt -1 matches all interrupts.
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sun, 01 Jan 2012 19:47:34 +0100 |
parents | 88361534c77e |
children | 901489c21d19 |
comparison
equal
deleted
inserted
replaced
235:e59bd7979ddc | 236:741860192b56 |
---|---|
27 logger = get_logger(__name__) | 27 logger = get_logger(__name__) |
28 | 28 |
29 #TODO: refactor/clean up | 29 #TODO: refactor/clean up |
30 | 30 |
31 | 31 |
32 class Script(list): | |
33 def __init__(self): | |
34 list.__init__(self) | |
35 self.interrupts = {} | |
36 | |
37 | |
38 | |
32 class Animations(object): | 39 class Animations(object): |
33 _instructions = {0: ('', 'delete'), | 40 _instructions = {0: ('', 'delete'), |
34 1: ('I', 'set_sprite'), | 41 1: ('I', 'set_sprite'), |
35 2: ('ff', 'set_scale'), | 42 2: ('ff', 'set_scale'), |
36 3: ('I', 'set_alpha'), | 43 3: ('I', 'set_alpha'), |
47 16: ('ii', 'set_random_sprite'), | 54 16: ('ii', 'set_random_sprite'), |
48 17: ('fff', 'set_3d_translation'), | 55 17: ('fff', 'set_3d_translation'), |
49 18: ('fffi', 'move_to_linear'), | 56 18: ('fffi', 'move_to_linear'), |
50 19: ('fffi', 'move_to_decel'), | 57 19: ('fffi', 'move_to_decel'), |
51 20: ('fffi', 'move_to_accel'), | 58 20: ('fffi', 'move_to_accel'), |
52 21: ('', None), | 59 21: ('', 'wait'), |
53 22: ('i', None), | 60 22: ('i', 'interrupt_label'), |
54 23: ('', 'set_corner_relative_placement'), | 61 23: ('', 'set_corner_relative_placement'), |
55 24: ('', None), | 62 24: ('', None), |
56 25: ('i', 'set_allow_offset'), #TODO: better name | 63 25: ('i', 'set_allow_offset'), #TODO: better name |
57 26: ('i', 'set_automatic_orientation'), | 64 26: ('i', 'set_automatic_orientation'), |
58 27: ('f', 'shift_texture_x'), | 65 27: ('f', 'shift_texture_x'), |
105 | 112 |
106 | 113 |
107 # Scripts | 114 # Scripts |
108 anm.scripts = {} | 115 anm.scripts = {} |
109 for i, offset in script_offsets: | 116 for i, offset in script_offsets: |
110 anm.scripts[i] = [] | 117 anm.scripts[i] = Script() |
111 instruction_offsets = [] | 118 instruction_offsets = [] |
112 file.seek(offset) | 119 file.seek(offset) |
113 while True: | 120 while True: |
114 #TODO | 121 #TODO |
115 instruction_offsets.append(file.tell() - offset) | 122 instruction_offsets.append(file.tell() - offset) |
123 | 130 |
124 anm.scripts[i].append((time, opcode, args)) | 131 anm.scripts[i].append((time, opcode, args)) |
125 if opcode == 0: | 132 if opcode == 0: |
126 break | 133 break |
127 | 134 |
128 # Translate offsets to instruction pointers | 135 # Translate offsets to instruction pointers and register interrupts |
129 for instr_offset, (j, instr) in zip(instruction_offsets, enumerate(anm.scripts[i])): | 136 for instr_offset, (j, instr) in zip(instruction_offsets, enumerate(anm.scripts[i])): |
130 time, opcode, args = instr | 137 time, opcode, args = instr |
131 if opcode == 5: | 138 if opcode == 5: |
132 args = (instruction_offsets.index(args[0]),) | 139 args = (instruction_offsets.index(args[0]),) |
140 if opcode == 22: | |
141 interrupt = args[0] | |
142 anm.scripts[i].interrupts[interrupt] = j + 1 | |
133 anm.scripts[i][j] = time, opcode, args | 143 anm.scripts[i][j] = time, opcode, args |
134 #TODO | 144 #TODO |
135 | 145 |
136 return anm | 146 return anm |
137 | 147 |