Parcourir la source

Add image cache manager

Bastien Sevajol il y a 6 ans
Parent
révision
bcf80aabde
2 fichiers modifiés avec 32 ajouts et 0 suppressions
  1. 8 0
      synergine2_cocos2d/actor.py
  2. 24 0
      synergine2_xyz/image.py

+ 8 - 0
synergine2_cocos2d/actor.py Voir le fichier

@@ -14,6 +14,7 @@ from synergine2.config import Config
14 14
 from synergine2.simulation import Subject
15 15
 from synergine2_cocos2d.animation import AnimatedInterface
16 16
 from synergine2_cocos2d.util import PathManager
17
+from synergine2_xyz.image import ImageCacheManager
17 18
 
18 19
 
19 20
 class Actor(AnimatedInterface, cocos.sprite.Sprite):
@@ -62,6 +63,13 @@ class Actor(AnimatedInterface, cocos.sprite.Sprite):
62 63
         self.properties = properties or {}
63 64
         self._freeze = False
64 65
 
66
+        self.default_image_path = image_path
67
+        self.image_cache = self.get_image_cache_manager()
68
+        self.image_cache.build()
69
+
70
+    def get_image_cache_manager(self) -> ImageCacheManager:
71
+        return ImageCacheManager(self, self.config)
72
+
65 73
     def build_default_image(self, subject_id: int, base_image_path: str) -> str:
66 74
         cache_dir = self.config.resolve('global.cache_dir_path')
67 75
         with open(base_image_path, 'rb') as base_image_file:

+ 24 - 0
synergine2_xyz/image.py Voir le fichier

@@ -0,0 +1,24 @@
1
+# coding: utf-8
2
+import typing
3
+
4
+from synergine2.config import Config
5
+
6
+if typing.TYPE_CHECKING:
7
+    from synergine2_cocos2d.actor import Actor
8
+
9
+class ImageCache(object):
10
+    def __init__(self) -> None:
11
+        self.cache = {}
12
+
13
+
14
+class ImageCacheManager(object):
15
+    def __init__(
16
+        self,
17
+        actor: 'Actor',
18
+        config: Config,
19
+    ) -> None:
20
+        self.config = config
21
+        self.actor = actor
22
+
23
+    def build(self) -> None:
24
+        pass