comparison pytouhou/formats/ecl.py @ 113:732c64662f87

Minor changes
author Thibaut Girka <thib@sitedethib.com>
date Wed, 07 Sep 2011 00:17:11 +0200
parents e544f9a7966d
children 7769ce7be03c
comparison
equal deleted inserted replaced
112:e544f9a7966d 113:732c64662f87
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of 10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details. 12 ## GNU General Public License for more details.
13 ## 13 ##
14 14
15 15 import struct
16 from struct import pack, unpack, calcsize 16 from struct import pack, unpack, calcsize
17 from pytouhou.utils.helpers import read_string 17 from pytouhou.utils.helpers import read_string
18 18
19 from pytouhou.utils.helpers import get_logger 19 from pytouhou.utils.helpers import get_logger
20 20
131 132: ('i', None), 131 132: ('i', None),
132 133: ('', None), 132 133: ('', None),
133 134: ('', None), 133 134: ('', None),
134 135: ('i', None)} #TODO 134 135: ('i', None)} #TODO
135 135
136 _main_instructions = {0: ('ffIhHHH', 'spawn_enemy'), 136 _main_instructions = {0: ('fffhHHH', 'spawn_enemy'),
137 2: ('ffIhHHH', 'spawn_enemy_mirrored'), 137 2: ('fffhHHH', 'spawn_enemy_mirrored'),
138 4: ('ffIhHHH', 'spawn_enemy_random'), 138 4: ('fffhHHH', 'spawn_enemy_random'),
139 6: ('ffIhHHH', 'spawn_enemy_mirrored_random'), 139 6: ('fffhHHH', 'spawn_enemy_mirrored_random'),
140 8: ('', None), 140 8: ('', None),
141 9: ('', None), 141 9: ('', None),
142 10: ('II', None), 142 10: ('II', None),
143 12: ('', None)} 143 12: ('', None)}
144 144
243 args[-1] = args[-1].encode('shift_jis') 243 args[-1] = args[-1].encode('shift_jis')
244 format = '%s%ds' % (format[:-1], len(args[-1])) 244 format = '%s%ds' % (format[:-1], len(args[-1]))
245 format = '<IHHHH%s' % format 245 format = '<IHHHH%s' % format
246 size = calcsize(format) 246 size = calcsize(format)
247 instruction_offsets.append((instruction_offsets[-1] + len(instruction_datas[-1])) if instruction_offsets else 0) 247 instruction_offsets.append((instruction_offsets[-1] + len(instruction_datas[-1])) if instruction_offsets else 0)
248 instruction_datas.append(pack(format, time, opcode, size, rank_mask, param_mask, *args)) 248 try:
249 instruction_datas.append(pack(format, time, opcode, size, rank_mask, param_mask, *args))
250 except struct.error:
251 logger.error('Failed to assemble opcode %d' % opcode)
252 raise
249 253
250 #TODO: clean up this mess 254 #TODO: clean up this mess
251 for instruction, data, offset in zip(sub, instruction_datas, instruction_offsets): 255 for instruction, data, offset in zip(sub, instruction_datas, instruction_offsets):
252 time, opcode, rank_mask, param_mask, args = instruction 256 time, opcode, rank_mask, param_mask, args = instruction
253 if opcode in (2, 29, 30, 31, 32, 33, 34): # relative_jump 257 if opcode in (2, 29, 30, 31, 32, 33, 34): # relative_jump