Browse Source

add cache in WeaponImageApplier

Bastien Sevajol 7 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
         animation_position: int,
72
         animation_position: int,
73
     ) -> Image.Image:
73
     ) -> Image.Image:
74
         try:
74
         try:
75
-            # FIXME Cache
76
             image_file_path = self.path_manager.path(
75
             image_file_path = self.path_manager.path(
77
                 self._images_scheme[mode][weapon_type][animation_position],
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
         except KeyError:
83
         except KeyError:
81
             raise UnknownWeapon(
84
             raise UnknownWeapon(
82
                 'Unknown weapon "{}" for mode "{}"'.format(weapon_type, mode),
85
                 'Unknown weapon "{}" for mode "{}"'.format(weapon_type, mode),