Browse Source

add cache in WeaponImageApplier

Bastien Sevajol 6 years ago
parent
commit
4ac4a6214a
1 changed files with 5 additions and 2 deletions
  1. 5 2
      opencombat/gui/weapon.py

+ 5 - 2
opencombat/gui/weapon.py View File

@@ -72,11 +72,14 @@ class WeaponImageApplier(ImageApplier):
72 72
         animation_position: int,
73 73
     ) -> Image.Image:
74 74
         try:
75
-            # FIXME Cache
76 75
             image_file_path = self.path_manager.path(
77 76
                 self._images_scheme[mode][weapon_type][animation_position],
78 77
             )
79
-            return Image.open(image_file_path)
78
+            try:
79
+                return self._cache[image_file_path]
80
+            except KeyError:
81
+                self._cache[image_file_path] = Image.open(image_file_path)
82
+                return self._cache[image_file_path]
80 83
         except KeyError:
81 84
             raise UnknownWeapon(
82 85
                 'Unknown weapon "{}" for mode "{}"'.format(weapon_type, mode),