|
|
|
|
26
|
self.actor = actor
|
26
|
self.actor = actor
|
27
|
self._images_scheme = self.get_images_scheme()
|
27
|
self._images_scheme = self.get_images_scheme()
|
28
|
self.path_manager = PathManager(config.resolve('global.include_path.graphics'))
|
28
|
self.path_manager = PathManager(config.resolve('global.include_path.graphics'))
|
|
|
29
|
+ self._cache = {} # type: typing.Dict[str, Image.Image]
|
29
|
|
30
|
|
30
|
def get_images_scheme(self) -> typing.Dict[str, typing.Dict[str, str]]:
|
31
|
def get_images_scheme(self) -> typing.Dict[str, typing.Dict[str, str]]:
|
31
|
from opencombat.gui.actor import MAN_STAND_UP
|
32
|
from opencombat.gui.actor import MAN_STAND_UP
|
|
|
|
|
51
|
|
52
|
|
52
|
def get_default_image_for_weapon(self, mode: str, weapon_type: str) -> Image.Image:
|
53
|
def get_default_image_for_weapon(self, mode: str, weapon_type: str) -> Image.Image:
|
53
|
try:
|
54
|
try:
|
54
|
- # FIXME Cache
|
|
|
55
|
image_file_path = self.path_manager.path(
|
55
|
image_file_path = self.path_manager.path(
|
56
|
self._images_scheme[mode][weapon_type][0],
|
56
|
self._images_scheme[mode][weapon_type][0],
|
57
|
)
|
57
|
)
|
58
|
- return Image.open(image_file_path)
|
|
|
|
|
58
|
+ try:
|
|
|
59
|
+ return self._cache[image_file_path]
|
|
|
60
|
+ except KeyError:
|
|
|
61
|
+ self._cache[image_file_path] = Image.open(image_file_path)
|
|
|
62
|
+ return self._cache[image_file_path]
|
59
|
except KeyError:
|
63
|
except KeyError:
|
60
|
raise UnknownWeapon(
|
64
|
raise UnknownWeapon(
|
61
|
'Unknown weapon "{}" for mode "{}"'.format(weapon_type, mode),
|
65
|
'Unknown weapon "{}" for mode "{}"'.format(weapon_type, mode),
|