changeset 285:2100276c289d

Document some AnmWrapper related functions.
author Thibaut Girka <thib@sitedethib.com>
date Sun, 12 Feb 2012 15:51:00 +0100
parents 91eb0afcb1e3
children 4838e9bab0f9
files pytouhou/resource/anmwrapper.py pytouhou/resource/loader.py
diffstat 2 files changed, 55 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/resource/anmwrapper.py
+++ b/pytouhou/resource/anmwrapper.py
@@ -1,12 +1,38 @@
-from itertools import izip, chain, repeat
+# -*- encoding: utf-8 -*-
+##
+## Copyright (C) 2012 Thibaut Girka <thib@sitedethib.com>
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published
+## by the Free Software Foundation; version 3 only.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+
+from itertools import repeat
 
 
 class AnmWrapper(object):
-    def __init__(self, anm_files, offsets=()):
+    def __init__(self, anm_files, offsets=None):
+        """Wrapper for scripts and sprites described in “anm_files”.
+
+        The optional “offsets” argument specifies a list of offsets to be added
+        to script and sprite numbers of each file described in “anm_files”.
+
+        That is, if anm_files[0] and anm_files[1] each have only one sprite,
+        numbered 0 in both cases, and offsets=(0, 1), the first file's sprite
+        will be numbered 0 and the second file's will be numbered 1.
+        """
         self.scripts = {}
         self.sprites = {}
 
-        for anm, offset in izip(anm_files, chain(offsets, repeat(0))):
+        if not offsets:
+            offsets = repeat(0) # “offsets” defaults to zeroes
+
+        for anm, offset in zip(anm_files, offsets):
             for script_id, script in anm.scripts.iteritems():
                 self.scripts[script_id + offset] = (anm, script) #TODO: check
             for sprite_id, sprite in anm.sprites.iteritems():
--- a/pytouhou/resource/loader.py
+++ b/pytouhou/resource/loader.py
@@ -1,3 +1,17 @@
+# -*- encoding: utf-8 -*-
+##
+## Copyright (C) 2012 Thibaut Girka <thib@sitedethib.com>
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published
+## by the Free Software Foundation; version 3 only.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+
 import os
 from glob import glob
 from itertools import chain
@@ -163,11 +177,21 @@ class Loader(object):
         return characters
 
 
-    def get_anm_wrapper(self, names, offsets=()):
+    def get_anm_wrapper(self, names, offsets=None):
+        """Create an AnmWrapper for ANM files “names”.
+
+        If one of the files “names” does not exist or is not a valid ANM file,
+        raises an exception.
+        """
         return AnmWrapper((self.get_anm(name) for name in names), offsets)
 
 
-    def get_anm_wrapper2(self, names, offsets=()):
+    def get_anm_wrapper2(self, names, offsets=None):
+        """Create an AnmWrapper for ANM files “names”.
+
+        Stop at the first non-existent or invalid ANM file if there is one,
+        and return an AnmWrapper for all the previous correct files.
+        """
         anms = []
 
         try: