changeset 575:970cdc219e15 pyntnclick

Add image mutation to resource loader.
author Jeremy Thurgood <firxen@gmail.com>
date Sat, 11 Feb 2012 16:01:33 +0200
parents 4e14721e74a8
children 1b1ab71535bd
files pyntnclick/resources.py
diffstat 1 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pyntnclick/resources.py	Sat Feb 11 15:55:48 2012 +0200
+++ b/pyntnclick/resources.py	Sat Feb 11 16:01:33 2012 +0200
@@ -18,6 +18,7 @@
         self.resource_module = resource_module
         self.language = language
         self._image_cache = {}
+        self._mutated_image_cache = {}
 
     def get_resource_path(self, *resource_path_fragments):
         resource_name = os.path.join(*resource_path_fragments)
@@ -35,11 +36,21 @@
             paths.append(resource_filename(module, resource_path))
         return paths
 
-    def load_image(self, image_name):
+    def load_image(self, image_name, mutators=()):
         image_path = self.get_resource_path('images', image_name)
+
         if image_path not in self._image_cache:
             image = pygame.image.load(image_path)
             if self.CONVERT_ALPHA:
                 image = image.convert_alpha(pygame.display.get_surface())
             self._image_cache[image_path] = image
-        return self._image_cache[image_path]
+
+        image = self._image_cache[image_path]
+        key = (image_path, mutators)
+
+        if key not in self._mutated_image_cache:
+            for mutator in mutators:
+                image = mutator(image)
+            self._mutated_image_cache[key] = image
+
+        return self._mutated_image_cache[key]