annotate pytouhou/formats/anm0.py @ 23:444ac7bca7bc

Refacto ECL stuff, add support for a few instructions, and add some culling
author Thibaut Girka <thib@sitedethib.com>
date Fri, 12 Aug 2011 19:13:43 +0200
parents 66ce9bb440ac
children 9027692abd79
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
1 from struct import pack, unpack
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
2 from pytouhou.utils.helpers import read_string
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
3
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
4 #TODO: refactor/clean up
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
5
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
6
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
7 class Animations(object):
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
8 def __init__(self):
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
9 self.size = (0, 0)
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
10 self.first_name = None
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
11 self.secondary_name = None
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
12 self.sprites = {}
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
13 self.scripts = {}
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
14
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
15
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
16 @classmethod
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
17 def read(cls, file):
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
18 nb_sprites, nb_scripts, zero1 = unpack('<III', file.read(12))
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
19 width, height, format, zero2 = unpack('<IIII', file.read(16))
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
20 first_name_offset, unused, secondary_name_offset = unpack('<III', file.read(12))
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
21 version, unknown1, thtxoffset, hasdata, nextoffset = unpack('<IIIII', file.read(20))
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
22 if version != 0:
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
23 raise Exception #TODO
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
24 file.read(4) #TODO
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
25
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
26 sprite_offsets = [unpack('<I', file.read(4))[0] for i in range(nb_sprites)]
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
27 script_offsets = [unpack('<II', file.read(8)) for i in range(nb_scripts)]
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
28
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
29 anm = Animations()
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
30
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
31 anm.size = (width, height)
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
32
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
33 # Names
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
34 if first_name_offset:
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
35 file.seek(first_name_offset)
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
36 anm.first_name = read_string(file, 32, 'ascii') #TODO: 32, really?
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
37 if secondary_name_offset:
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
38 file.seek(secondary_name_offset)
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
39 anm.secondary_name = read_string(file, 32, 'ascii') #TODO: 32, really?
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
40
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
41
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
42 # Sprites
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
43 file.seek(64)
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
44 anm.sprites = {}
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
45 for offset in sprite_offsets:
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
46 file.seek(offset)
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
47 idx, x, y, width, height = unpack('<Iffff', file.read(20))
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
48 anm.sprites[idx] = x, y, width, height
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
49
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
50
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
51 # Scripts
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
52 anm.scripts = {}#[None] * nb_scripts
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
53 for i, offset in script_offsets:
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
54 anm.scripts[i] = []
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
55 file.seek(offset)
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
56 while True:
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
57 #TODO
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
58 time, instr_type, length = unpack('<HBB', file.read(4))
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
59 if instr_type == 0:
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
60 break
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
61 data = file.read(length)
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
62 anm.scripts[i].append((time, instr_type, data))
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
63 #TODO
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
64
16
66ce9bb440ac Refactor in order to support multiple textures
Thibaut Girka <thib@sitedethib.com>
parents: 2
diff changeset
65 return anm
2
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
66