Browse Source

add image cache manager

Bastien Sevajol 7 years ago
parent
commit
a3948a13bb
2 changed files with 11 additions and 30 deletions
  1. 3 6
      opencombat/gui/actor.py
  2. 8 24
      opencombat/gui/image.py

+ 3 - 6
opencombat/gui/actor.py View File

14
 from opencombat.gui.animation import ANIMATION_WALK
14
 from opencombat.gui.animation import ANIMATION_WALK
15
 from opencombat.gui.const import POSITION_MAN_STAND_UP
15
 from opencombat.gui.const import POSITION_MAN_STAND_UP
16
 from opencombat.gui.const import POSITION_MAN_CRAWLING
16
 from opencombat.gui.const import POSITION_MAN_CRAWLING
17
-from opencombat.gui.image import TileImageCache
17
+from opencombat.gui.image import TileImageCacheManager
18
 from opencombat.gui.weapon import RIFFLE
18
 from opencombat.gui.weapon import RIFFLE
19
 from opencombat.gui.weapon import WeaponImageApplier
19
 from opencombat.gui.weapon import WeaponImageApplier
20
 
20
 
43
         self.firing_change_image_gap = 0.05  # seconds
43
         self.firing_change_image_gap = 0.05  # seconds
44
         self.firing_images_cache = {}  # type: TODO
44
         self.firing_images_cache = {}  # type: TODO
45
 
45
 
46
-        self.default_image_path = image_path
47
-
48
-        self.image_cache = TileImageCache(self, self.config)
49
-        self.image_cache.build()
50
-        pass
46
+    def get_image_cache_manager(self) -> TileImageCacheManager:
47
+        return TileImageCacheManager(self, self.config)
51
 
48
 
52
     @property
49
     @property
53
     def mode(self) -> str:
50
     def mode(self) -> str:

+ 8 - 24
opencombat/gui/image.py View File

1
 # coding: utf-8
1
 # coding: utf-8
2
-import io
3
 import typing
2
 import typing
4
 
3
 
5
 from PIL import Image
4
 from PIL import Image
6
 from synergine2.config import Config
5
 from synergine2.config import Config
7
-from synergine2_cocos2d.actor import Actor
8
 from synergine2_cocos2d.util import PathManager
6
 from synergine2_cocos2d.util import PathManager
7
+from synergine2_xyz.image import ImageCache
8
+from synergine2_xyz.image import ImageCacheManager
9
 
9
 
10
 from opencombat.exception import UnknownAnimationIndex
10
 from opencombat.exception import UnknownAnimationIndex
11
 
11
 
12
+if typing.TYPE_CHECKING:
13
+    from opencombat.gui.actor import BaseActor
12
 
14
 
13
-class ImageCache(object):
14
-    def __init__(self) -> None:
15
-        self.cache = {}
16
 
15
 
17
-
18
-class FiringCache(ImageCache):
16
+class FiringImageCache(ImageCache):
19
     def add(
17
     def add(
20
         self,
18
         self,
21
         mode: str,
19
         mode: str,
44
             )
42
             )
45
 
43
 
46
 
44
 
47
-class ImageCache(object):
48
-    # FIXME: Move into synergine
49
-    def __init__(
50
-        self,
51
-        actor: Actor,
52
-        config: Config,
53
-    ) -> None:
54
-        self.config = config
55
-        self.actor = actor
56
-
57
-    def build(self) -> None:
58
-        pass
59
-
60
-
61
-class TileImageCache(ImageCache):
45
+class TileImageCacheManager(ImageCacheManager):
62
     def __init__(
46
     def __init__(
63
         self,
47
         self,
64
-        actor: Actor,
48
+        actor: 'BaseActor',
65
         config: Config,
49
         config: Config,
66
     ) -> None:
50
     ) -> None:
67
         super().__init__(actor, config)
51
         super().__init__(actor, config)
68
-        self.firing_cache = FiringCache()
52
+        self.firing_cache = FiringImageCache()
69
         from opencombat.gui.actor import BaseActor
53
         from opencombat.gui.actor import BaseActor
70
         self.actor = typing.cast(BaseActor, self.actor)
54
         self.actor = typing.cast(BaseActor, self.actor)
71
         self.path_manager = PathManager(
55
         self.path_manager = PathManager(