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