comparison pytouhou/formats/anm0.py @ 377:70e2ed71b09c

Add meaningful exceptions in format parsing.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 29 Aug 2012 18:34:28 +0200
parents da53bc29b94a
children 88e2a2485b2b
comparison
equal deleted inserted replaced
376:69ec72b990a4 377:70e2ed71b09c
20 Almost everything rendered in the game is described by an ANM0 file. 20 Almost everything rendered in the game is described by an ANM0 file.
21 """ 21 """
22 22
23 from struct import pack, unpack 23 from struct import pack, unpack
24 from pytouhou.utils.helpers import read_string, get_logger 24 from pytouhou.utils.helpers import read_string, get_logger
25
26 from pytouhou.formats import WrongFormatError
25 27
26 28
27 logger = get_logger(__name__) 29 logger = get_logger(__name__)
28 30
29 #TODO: refactor/clean up 31 #TODO: refactor/clean up
82 nb_sprites, nb_scripts, zero1 = unpack('<III', file.read(12)) 84 nb_sprites, nb_scripts, zero1 = unpack('<III', file.read(12))
83 width, height, format, unknown1 = unpack('<IIII', file.read(16)) 85 width, height, format, unknown1 = unpack('<IIII', file.read(16))
84 first_name_offset, unused, secondary_name_offset = unpack('<III', file.read(12)) 86 first_name_offset, unused, secondary_name_offset = unpack('<III', file.read(12))
85 version, unknown2, thtxoffset, hasdata, nextoffset, zero2 = unpack('<IIIIII', file.read(24)) 87 version, unknown2, thtxoffset, hasdata, nextoffset, zero2 = unpack('<IIIIII', file.read(24))
86 if version != 0: 88 if version != 0:
87 raise Exception #TODO 89 raise WrongFormatError(version)
88 if (zero1, zero2) != (0, 0): 90 assert (zero1, zero2) == (0, 0)
89 raise Exception #TODO
90 91
91 sprite_offsets = [unpack('<I', file.read(4))[0] for i in range(nb_sprites)] 92 sprite_offsets = [unpack('<I', file.read(4))[0] for i in range(nb_sprites)]
92 script_offsets = [unpack('<II', file.read(8)) for i in range(nb_scripts)] 93 script_offsets = [unpack('<II', file.read(8)) for i in range(nb_scripts)]
93 94
94 self = cls() 95 self = cls()