|
@@ -6,17 +6,19 @@ import pyglet
|
6
|
6
|
import cocos
|
7
|
7
|
from cocos import collision_model
|
8
|
8
|
from cocos import euclid
|
|
9
|
+
|
|
10
|
+from synergine2.config import Config
|
9
|
11
|
from synergine2.simulation import Subject
|
10
|
12
|
from synergine2_cocos2d.animation import AnimatedInterface
|
|
13
|
+from synergine2_cocos2d.util import PathManager
|
11
|
14
|
|
12
|
15
|
|
13
|
16
|
class Actor(AnimatedInterface, cocos.sprite.Sprite):
|
14
|
17
|
animation_image_paths = {} # type: typing.Dict[str, typing.List[str]]
|
15
|
|
- animation_images = {} # type: typing.Dict[str, typing.List[pyglet.image.TextureRegion]]
|
16
|
18
|
|
17
|
19
|
def __init__(
|
18
|
20
|
self,
|
19
|
|
- image: pyglet.image.TextureRegion,
|
|
21
|
+ image_path: str,
|
20
|
22
|
subject: Subject,
|
21
|
23
|
position=(0, 0),
|
22
|
24
|
rotation=0,
|
|
@@ -25,8 +27,14 @@ class Actor(AnimatedInterface, cocos.sprite.Sprite):
|
25
|
27
|
color=(255, 255, 255),
|
26
|
28
|
anchor=None,
|
27
|
29
|
properties: dict=None,
|
|
30
|
+ config: Config=None,
|
28
|
31
|
**kwargs
|
29
|
32
|
):
|
|
33
|
+ # Note: Parameter required, but we want to modify little as possible parent init
|
|
34
|
+ assert config, "Config is a required parameter"
|
|
35
|
+ self.path_manager = PathManager(config.resolve('global.include_path.graphics'))
|
|
36
|
+ image = pyglet.resource.image(self.path_manager.path(image_path))
|
|
37
|
+ self.animation_images = {} # type: typing.Dict[str, typing.List[pyglet.image.TextureRegion]] # nopep8
|
30
|
38
|
super().__init__(
|
31
|
39
|
image,
|
32
|
40
|
position,
|
|
@@ -80,7 +88,12 @@ class Actor(AnimatedInterface, cocos.sprite.Sprite):
|
80
|
88
|
for animation_name, animation_image_paths in self.animation_image_paths.items():
|
81
|
89
|
self.animation_images[animation_name] = []
|
82
|
90
|
for animation_image_path in animation_image_paths:
|
83
|
|
- self.animation_images[animation_name].append(pyglet.resource.image(animation_image_path))
|
|
91
|
+ final_image_path = self.path_manager.path(animation_image_path)
|
|
92
|
+ self.animation_images[animation_name].append(
|
|
93
|
+ pyglet.resource.image(
|
|
94
|
+ final_image_path,
|
|
95
|
+ )
|
|
96
|
+ )
|
84
|
97
|
|
85
|
98
|
def get_images_for_animation(self, animation_name: str) -> typing.List[pyglet.image.TextureRegion]:
|
86
|
99
|
return self.animation_images.get(animation_name)
|