Browse Source

actor crawling with weapon image

Bastien Sevajol 6 years ago
parent
commit
7caf658ea7
2 changed files with 57 additions and 3 deletions
  1. 24 1
      opencombat/gui/actor.py
  2. 33 2
      opencombat/gui/weapon.py

+ 24 - 1
opencombat/gui/actor.py View File

@@ -6,6 +6,8 @@ from synergine2.config import Config
6 6
 
7 7
 from synergine2.simulation import Subject
8 8
 from synergine2_cocos2d.actor import Actor
9
+
10
+from opencombat.exception import UnknownWeapon
9 11
 from opencombat.gui.animation import ANIMATION_WALK
10 12
 from opencombat.gui.animation import ANIMATION_CRAWL
11 13
 from opencombat.gui.weapon import WeaponImageApplier
@@ -19,6 +21,7 @@ FLAG_COLORS = {
19 21
 }
20 22
 
21 23
 MAN_STAND_UP = 'MAN_STAND_UP'
24
+MAN_CRAWLING = 'MAN_CRAWLING'
22 25
 
23 26
 
24 27
 class BaseActor(Actor):
@@ -28,12 +31,13 @@ class BaseActor(Actor):
28 31
         config: Config,
29 32
         subject: Subject,
30 33
     ) -> None:
34
+        self._mode = MAN_STAND_UP
31 35
         self.weapon_image_applier = WeaponImageApplier(config, self)
32 36
         super().__init__(image_path, subject=subject, config=config)
33 37
 
34 38
     @property
35 39
     def mode(self) -> str:
36
-        return MAN_STAND_UP
40
+        return self._mode
37 41
 
38 42
     @property
39 43
     def weapons(self) -> typing.List[str]:
@@ -50,6 +54,25 @@ class BaseActor(Actor):
50 54
             )
51 55
         ]
52 56
 
57
+    def get_animation_appliable_images(
58
+        self,
59
+        animation_name: str,
60
+        animation_position: int,
61
+    ) -> typing.List[Image.Image]:
62
+        if not self.weapons:
63
+            return []
64
+
65
+        try:
66
+            return [
67
+                self.weapon_image_applier.get_animation_image_for_weapon(
68
+                    animation_name,
69
+                    self.weapons[0],
70
+                    animation_position,
71
+                )
72
+            ]
73
+        except UnknownWeapon:
74
+            return []
75
+
53 76
     def firing(self) -> None:
54 77
         pass
55 78
 

+ 33 - 2
opencombat/gui/weapon.py View File

@@ -29,9 +29,23 @@ class WeaponImageApplier(ImageApplier):
29 29
 
30 30
     def get_images_scheme(self) -> typing.Dict[str, typing.Dict[str, str]]:
31 31
         from opencombat.gui.actor import MAN_STAND_UP
32
+        from opencombat.gui.actor import MAN_CRAWLING
32 33
         return {
33 34
             MAN_STAND_UP: {
34
-                RIFFLE: 'actors/man_weap1.png',
35
+                RIFFLE: [
36
+                    'actors/man_weap1.png'
37
+                ],
38
+            },
39
+            # FIXME NOW
40
+            # MAN_CRAWLING: {
41
+            'CRAWL': {
42
+                RIFFLE: [
43
+                    'actors/man_c1_weap1.png',
44
+                    'actors/man_c2_weap1.png',
45
+                    'actors/man_c3_weap1.png',
46
+                    'actors/man_c4_weap1.png',
47
+                ],
48
+
35 49
             }
36 50
         }
37 51
 
@@ -39,7 +53,24 @@ class WeaponImageApplier(ImageApplier):
39 53
         try:
40 54
             # FIXME Cache
41 55
             image_file_path = self.path_manager.path(
42
-                self._images_scheme[mode][weapon_type],
56
+                self._images_scheme[mode][weapon_type][0],
57
+            )
58
+            return Image.open(image_file_path)
59
+        except KeyError:
60
+            raise UnknownWeapon(
61
+                'Unknown weapon "{}" for mode "{}"'.format(weapon_type, mode),
62
+            )
63
+
64
+    def get_animation_image_for_weapon(
65
+        self,
66
+        mode: str,
67
+        weapon_type: str,
68
+        animation_position: int,
69
+    ) -> Image.Image:
70
+        try:
71
+            # FIXME Cache
72
+            image_file_path = self.path_manager.path(
73
+                self._images_scheme[mode][weapon_type][animation_position],
43 74
             )
44 75
             return Image.open(image_file_path)
45 76
         except KeyError: