Browse Source

add image cache manager

Bastien Sevajol 6 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,7 +14,7 @@ from opencombat.gui.animation import ANIMATION_CRAWL
14 14
 from opencombat.gui.animation import ANIMATION_WALK
15 15
 from opencombat.gui.const import POSITION_MAN_STAND_UP
16 16
 from opencombat.gui.const import POSITION_MAN_CRAWLING
17
-from opencombat.gui.image import TileImageCache
17
+from opencombat.gui.image import TileImageCacheManager
18 18
 from opencombat.gui.weapon import RIFFLE
19 19
 from opencombat.gui.weapon import WeaponImageApplier
20 20
 
@@ -43,11 +43,8 @@ class BaseActor(Actor):
43 43
         self.firing_change_image_gap = 0.05  # seconds
44 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 49
     @property
53 50
     def mode(self) -> str:

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

@@ -1,21 +1,19 @@
1 1
 # coding: utf-8
2
-import io
3 2
 import typing
4 3
 
5 4
 from PIL import Image
6 5
 from synergine2.config import Config
7
-from synergine2_cocos2d.actor import Actor
8 6
 from synergine2_cocos2d.util import PathManager
7
+from synergine2_xyz.image import ImageCache
8
+from synergine2_xyz.image import ImageCacheManager
9 9
 
10 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 17
     def add(
20 18
         self,
21 19
         mode: str,
@@ -44,28 +42,14 @@ class FiringCache(ImageCache):
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 46
     def __init__(
63 47
         self,
64
-        actor: Actor,
48
+        actor: 'BaseActor',
65 49
         config: Config,
66 50
     ) -> None:
67 51
         super().__init__(actor, config)
68
-        self.firing_cache = FiringCache()
52
+        self.firing_cache = FiringImageCache()
69 53
         from opencombat.gui.actor import BaseActor
70 54
         self.actor = typing.cast(BaseActor, self.actor)
71 55
         self.path_manager = PathManager(