comparison pytouhou/resource/anmwrapper.py @ 285:2100276c289d

Document some AnmWrapper related functions.
author Thibaut Girka <thib@sitedethib.com>
date Sun, 12 Feb 2012 15:51:00 +0100
parents dbb1a86c0235
children 40d5f3083ebc
comparison
equal deleted inserted replaced
284:91eb0afcb1e3 285:2100276c289d
1 from itertools import izip, chain, repeat 1 # -*- encoding: utf-8 -*-
2 ##
3 ## Copyright (C) 2012 Thibaut Girka <thib@sitedethib.com>
4 ##
5 ## This program is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published
7 ## by the Free Software Foundation; version 3 only.
8 ##
9 ## This program is distributed in the hope that it will be useful,
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details.
13 ##
14
15 from itertools import repeat
2 16
3 17
4 class AnmWrapper(object): 18 class AnmWrapper(object):
5 def __init__(self, anm_files, offsets=()): 19 def __init__(self, anm_files, offsets=None):
20 """Wrapper for scripts and sprites described in “anm_files”.
21
22 The optional “offsets” argument specifies a list of offsets to be added
23 to script and sprite numbers of each file described in “anm_files”.
24
25 That is, if anm_files[0] and anm_files[1] each have only one sprite,
26 numbered 0 in both cases, and offsets=(0, 1), the first file's sprite
27 will be numbered 0 and the second file's will be numbered 1.
28 """
6 self.scripts = {} 29 self.scripts = {}
7 self.sprites = {} 30 self.sprites = {}
8 31
9 for anm, offset in izip(anm_files, chain(offsets, repeat(0))): 32 if not offsets:
33 offsets = repeat(0) # “offsets” defaults to zeroes
34
35 for anm, offset in zip(anm_files, offsets):
10 for script_id, script in anm.scripts.iteritems(): 36 for script_id, script in anm.scripts.iteritems():
11 self.scripts[script_id + offset] = (anm, script) #TODO: check 37 self.scripts[script_id + offset] = (anm, script) #TODO: check
12 for sprite_id, sprite in anm.sprites.iteritems(): 38 for sprite_id, sprite in anm.sprites.iteritems():
13 self.sprites[sprite_id + offset] = (anm, sprite) 39 self.sprites[sprite_id + offset] = (anm, sprite)
14 40