|
@@ -8,12 +8,14 @@ from PIL import Image
|
8
|
8
|
from synergine2.config import Config
|
9
|
9
|
from synergine2.simulation import Subject
|
10
|
10
|
from synergine2_cocos2d.actor import Actor
|
|
11
|
+from synergine2_xyz.exception import UnknownAnimationIndex
|
11
|
12
|
|
12
|
|
-from opencombat.exception import UnknownWeapon, UnknownAnimationIndex
|
|
13
|
+from opencombat.exception import UnknownWeapon
|
|
14
|
+from opencombat.exception import UnknownFiringAnimation
|
13
|
15
|
from opencombat.gui.animation import ANIMATION_CRAWL
|
14
|
16
|
from opencombat.gui.animation import ANIMATION_WALK
|
15
|
|
-from opencombat.gui.const import POSITION_MAN_STAND_UP
|
16
|
|
-from opencombat.gui.const import POSITION_MAN_CRAWLING
|
|
17
|
+from opencombat.gui.const import MODE_MAN_STAND_UP
|
|
18
|
+from opencombat.gui.const import MODE_MAN_CRAWLING
|
17
|
19
|
from opencombat.gui.image import TileImageCacheManager
|
18
|
20
|
from opencombat.gui.weapon import RIFFLE
|
19
|
21
|
from opencombat.gui.weapon import WeaponImageApplier
|
|
@@ -22,11 +24,22 @@ if typing.TYPE_CHECKING:
|
22
|
24
|
from opencombat.gui.fire import GuiFiringEvent
|
23
|
25
|
|
24
|
26
|
|
|
27
|
+MODE_DEFAULT = 'MODE_DEFAULT'
|
|
28
|
+
|
|
29
|
+
|
25
|
30
|
class BaseActor(Actor):
|
26
|
31
|
position_matching = {
|
27
|
|
- ANIMATION_WALK: POSITION_MAN_STAND_UP,
|
28
|
|
- ANIMATION_CRAWL: POSITION_MAN_CRAWLING,
|
|
32
|
+ ANIMATION_WALK: MODE_MAN_STAND_UP,
|
|
33
|
+ ANIMATION_CRAWL: MODE_MAN_CRAWLING,
|
29
|
34
|
}
|
|
35
|
+ mode_image_paths = {
|
|
36
|
+ MODE_DEFAULT: 'unknown.png',
|
|
37
|
+ }
|
|
38
|
+ modes = [
|
|
39
|
+ MODE_DEFAULT,
|
|
40
|
+ ]
|
|
41
|
+ weapons_firing_image_scheme = {}
|
|
42
|
+ weapon_image_scheme = {}
|
30
|
43
|
|
31
|
44
|
def __init__(
|
32
|
45
|
self,
|
|
@@ -34,20 +47,30 @@ class BaseActor(Actor):
|
34
|
47
|
config: Config,
|
35
|
48
|
subject: Subject,
|
36
|
49
|
) -> None:
|
37
|
|
- self._mode = POSITION_MAN_STAND_UP
|
|
50
|
+ self._mode = MODE_MAN_STAND_UP
|
38
|
51
|
self.weapon_image_applier = WeaponImageApplier(config, self)
|
39
|
52
|
super().__init__(image_path, subject=subject, config=config)
|
40
|
53
|
|
41
|
54
|
# Firing
|
42
|
55
|
self.last_firing_time = 0
|
43
|
56
|
self.firing_change_image_gap = 0.05 # seconds
|
44
|
|
- self.firing_images_cache = {} # type: TODO
|
45
|
57
|
|
46
|
58
|
def get_image_cache_manager(self) -> TileImageCacheManager:
|
47
|
59
|
return TileImageCacheManager(self, self.config)
|
48
|
60
|
|
|
61
|
+ def get_default_mode(self) -> str:
|
|
62
|
+ return MODE_DEFAULT
|
|
63
|
+
|
|
64
|
+ def get_mode_image_path(self, mode: str) -> str:
|
|
65
|
+ return self.mode_image_paths[mode]
|
|
66
|
+
|
|
67
|
+ def get_modes(self) -> typing.List[str]:
|
|
68
|
+ return self.modes
|
|
69
|
+
|
49
|
70
|
@property
|
50
|
71
|
def mode(self) -> str:
|
|
72
|
+ # FIXME: When man is moving (crawling for example), must change mode
|
|
73
|
+ # and man must stay "crawled"
|
51
|
74
|
return self._mode
|
52
|
75
|
|
53
|
76
|
@property
|
|
@@ -86,53 +109,6 @@ class BaseActor(Actor):
|
86
|
109
|
except UnknownWeapon:
|
87
|
110
|
return []
|
88
|
111
|
|
89
|
|
- def get_modes(self) -> typing.List[str]:
|
90
|
|
- return [POSITION_MAN_STAND_UP]
|
91
|
|
-
|
92
|
|
- # def build_firing_images(self) -> None:
|
93
|
|
- # cache_dir = self.config.resolve('global.cache_dir_path')
|
94
|
|
- # for mode in self.get_modes():
|
95
|
|
- # for weapon in self.weapons:
|
96
|
|
- # images = self.weapon_image_applier.get_firing_image(
|
97
|
|
- # mode=mode,
|
98
|
|
- # weapon_type=weapon,
|
99
|
|
- # )
|
100
|
|
- #
|
101
|
|
- # for position in range(len(images)):
|
102
|
|
- # pass
|
103
|
|
- #
|
104
|
|
- #
|
105
|
|
- # for animation_name, animation_image_paths in self.animation_image_paths.items():
|
106
|
|
- # self.animation_images[animation_name] = []
|
107
|
|
- # for i, animation_image_path in enumerate(animation_image_paths):
|
108
|
|
- # final_image_path = self.path_manager.path(animation_image_path)
|
109
|
|
- # final_image = Image.open(final_image_path)
|
110
|
|
- #
|
111
|
|
- # for appliable_image in self.get_animation_appliable_images(
|
112
|
|
- # animation_name,
|
113
|
|
- # i,
|
114
|
|
- # ):
|
115
|
|
- # final_image.paste(
|
116
|
|
- # appliable_image,
|
117
|
|
- # (0, 0),
|
118
|
|
- # appliable_image,
|
119
|
|
- # )
|
120
|
|
- #
|
121
|
|
- # # FIXME NOW: nom des image utilise au dessus
|
122
|
|
- # final_name = '_'.join([
|
123
|
|
- # str(subject_id),
|
124
|
|
- # ntpath.basename(final_image_path),
|
125
|
|
- # ])
|
126
|
|
- # final_path = os.path.join(cache_dir, final_name)
|
127
|
|
- #
|
128
|
|
- # final_image.save(final_path)
|
129
|
|
- #
|
130
|
|
- # self.animation_images[animation_name].append(
|
131
|
|
- # pyglet.image.load(
|
132
|
|
- # final_path,
|
133
|
|
- # )
|
134
|
|
- # )
|
135
|
|
-
|
136
|
112
|
def firing(self, firing: 'GuiFiringEvent') -> None:
|
137
|
113
|
# FIXME: move some code ?
|
138
|
114
|
now = time.time()
|
|
@@ -141,18 +117,27 @@ class BaseActor(Actor):
|
141
|
117
|
firing.increment_animation_index()
|
142
|
118
|
|
143
|
119
|
try:
|
144
|
|
- image = self.image_cache.firing_cache.get(
|
|
120
|
+ image = self.image_cache_manager.firing_cache.get(
|
145
|
121
|
mode=self.mode,
|
146
|
122
|
weapon=firing.weapon,
|
147
|
123
|
position=firing.animation_index,
|
148
|
124
|
)
|
149
|
125
|
except UnknownAnimationIndex:
|
150
|
|
- image = self.image_cache.firing_cache.get(
|
|
126
|
+ image = self.image_cache_manager.firing_cache.get(
|
151
|
127
|
mode=self.mode,
|
152
|
128
|
weapon=firing.weapon,
|
153
|
129
|
position=0,
|
154
|
130
|
)
|
155
|
131
|
firing.reset_animation_index()
|
|
132
|
+ except UnknownFiringAnimation as exc:
|
|
133
|
+ self.logger.error(
|
|
134
|
+ 'No firing animation for actor {}({}): {}'.format(
|
|
135
|
+ self.__class__.__name__,
|
|
136
|
+ str(self.subject.id),
|
|
137
|
+ str(exc),
|
|
138
|
+ )
|
|
139
|
+ )
|
|
140
|
+ return # There is no firing animation defined
|
156
|
141
|
|
157
|
142
|
# FIXME cache: prepare before firing
|
158
|
143
|
import uuid
|
|
@@ -182,6 +167,39 @@ class Man(BaseActor):
|
182
|
167
|
'actors/man_c4.png',
|
183
|
168
|
]
|
184
|
169
|
}
|
|
170
|
+ modes = [
|
|
171
|
+ MODE_MAN_STAND_UP,
|
|
172
|
+ MODE_MAN_CRAWLING,
|
|
173
|
+ ]
|
|
174
|
+ mode_image_paths = {
|
|
175
|
+ MODE_MAN_STAND_UP: 'actors/man.png',
|
|
176
|
+ MODE_MAN_CRAWLING: 'actors/man_c1.png',
|
|
177
|
+ }
|
|
178
|
+ weapon_image_scheme = {
|
|
179
|
+ MODE_MAN_STAND_UP: {
|
|
180
|
+ RIFFLE: [
|
|
181
|
+ 'actors/man_weap1.png'
|
|
182
|
+ ],
|
|
183
|
+ },
|
|
184
|
+ MODE_MAN_CRAWLING: {
|
|
185
|
+ RIFFLE: [
|
|
186
|
+ 'actors/man_c1_weap1.png',
|
|
187
|
+ 'actors/man_c2_weap1.png',
|
|
188
|
+ 'actors/man_c3_weap1.png',
|
|
189
|
+ 'actors/man_c4_weap1.png',
|
|
190
|
+ ],
|
|
191
|
+
|
|
192
|
+ }
|
|
193
|
+ }
|
|
194
|
+ weapons_firing_image_scheme = {
|
|
195
|
+ MODE_MAN_STAND_UP: {
|
|
196
|
+ RIFFLE: [
|
|
197
|
+ 'actors/man_weap1_firing1.png',
|
|
198
|
+ 'actors/man_weap1_firing2.png',
|
|
199
|
+ 'actors/man_weap1_firing3.png',
|
|
200
|
+ ],
|
|
201
|
+ },
|
|
202
|
+ }
|
185
|
203
|
|
186
|
204
|
def __init__(
|
187
|
205
|
self,
|
|
@@ -195,6 +213,9 @@ class Man(BaseActor):
|
195
|
213
|
# TODO BS 2018-01-26: Will be managed by complex part of code
|
196
|
214
|
return [RIFFLE]
|
197
|
215
|
|
|
216
|
+ def get_default_mode(self) -> str:
|
|
217
|
+ return MODE_MAN_STAND_UP
|
|
218
|
+
|
198
|
219
|
|
199
|
220
|
class HeavyVehicle(BaseActor):
|
200
|
221
|
animation_image_paths = {
|
|
@@ -205,6 +226,9 @@ class HeavyVehicle(BaseActor):
|
205
|
226
|
'actors/tank1.png',
|
206
|
227
|
]
|
207
|
228
|
}
|
|
229
|
+ mode_image_paths = {
|
|
230
|
+ MODE_DEFAULT: 'actors/tank1.png',
|
|
231
|
+ }
|
208
|
232
|
|
209
|
233
|
def __init__(
|
210
|
234
|
self,
|