comparison pytouhou/formats/anm0.py @ 38:cb5b27011044

Small refactoring and proper anm0's instruction 5 handling
author Thibaut Girka <thib@sitedethib.com>
date Sun, 14 Aug 2011 18:08:45 +0200
parents 9027692abd79
children 93c8dc2de923
comparison
equal deleted inserted replaced
37:a10e3f44a883 38:cb5b27011044
47 idx, x, y, width, height = unpack('<Iffff', file.read(20)) 47 idx, x, y, width, height = unpack('<Iffff', file.read(20))
48 anm.sprites[idx] = x, y, width, height 48 anm.sprites[idx] = x, y, width, height
49 49
50 50
51 # Scripts 51 # Scripts
52 anm.scripts = {}#[None] * nb_scripts 52 anm.scripts = {}
53 for i, offset in script_offsets: 53 for i, offset in script_offsets:
54 anm.scripts[i] = [] 54 anm.scripts[i] = []
55 instruction_offsets = []
55 file.seek(offset) 56 file.seek(offset)
56 while True: 57 while True:
57 #TODO 58 #TODO
59 instruction_offsets.append(file.tell() - offset)
58 time, instr_type, length = unpack('<HBB', file.read(4)) 60 time, instr_type, length = unpack('<HBB', file.read(4))
59 data = file.read(length) 61 data = file.read(length)
60 anm.scripts[i].append((time, instr_type, data)) 62 if instr_type == 1: # set_sprite
63 args = unpack('<I', data)
64 elif instr_type == 2: # set_scale
65 args = unpack('<ff', data)
66 elif instr_type == 3: # set_alpha
67 args = unpack('<I', data)
68 elif instr_type == 5: # jump
69 # Translate offset to instruction index
70 args = (instruction_offsets.index(unpack('<I', data)[0]),)
71 elif instr_type == 9: # set_3d_rotation
72 args = unpack('<fff', data)
73 elif instr_type == 10: # set_3d_rotation_speed
74 args = unpack('<fff', data)
75 else:
76 args = (data,)
77 anm.scripts[i].append((time, instr_type, args))
61 if instr_type == 0: 78 if instr_type == 0:
62 break 79 break
63 #TODO 80 #TODO
64 81
65 return anm 82 return anm