comparison pytouhou/resource/anmwrapper.py @ 282:dbb1a86c0235

Rename Animations to ANM0 and prepare AnmWrapper for dialogs and interface.
author Thibaut Girka <thib@sitedethib.com>
date Sat, 11 Feb 2012 16:43:54 +0100
parents ac2e5e1c2c3c
children 2100276c289d
comparison
equal deleted inserted replaced
281:13dcde917083 282:dbb1a86c0235
1 from itertools import izip, chain, repeat
2
3
1 class AnmWrapper(object): 4 class AnmWrapper(object):
2 def __init__(self, anm_files): 5 def __init__(self, anm_files, offsets=()):
3 self.anm_files = list(anm_files) 6 self.scripts = {}
7 self.sprites = {}
8
9 for anm, offset in izip(anm_files, chain(offsets, repeat(0))):
10 for script_id, script in anm.scripts.iteritems():
11 self.scripts[script_id + offset] = (anm, script) #TODO: check
12 for sprite_id, sprite in anm.sprites.iteritems():
13 self.sprites[sprite_id + offset] = (anm, sprite)
4 14
5 15
6 def get_sprite(self, sprite_index): 16 def get_sprite(self, sprite_index):
7 for anm in self.anm_files: 17 return self.sprites[sprite_index]
8 if sprite_index in anm.sprites:
9 return anm, anm.sprites[sprite_index]
10 raise IndexError
11 18
12 19
13 def get_script(self, script_index): 20 def get_script(self, script_index):
14 for anm in self.anm_files: 21 return self.scripts[script_index]
15 if script_index in anm.scripts: 22
16 return anm, anm.scripts[script_index]
17 raise IndexError