Browse Source

actor crawling with weapon image

Bastien Sevajol 7 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
 
7
 from synergine2.simulation import Subject
7
 from synergine2.simulation import Subject
8
 from synergine2_cocos2d.actor import Actor
8
 from synergine2_cocos2d.actor import Actor
9
+
10
+from opencombat.exception import UnknownWeapon
9
 from opencombat.gui.animation import ANIMATION_WALK
11
 from opencombat.gui.animation import ANIMATION_WALK
10
 from opencombat.gui.animation import ANIMATION_CRAWL
12
 from opencombat.gui.animation import ANIMATION_CRAWL
11
 from opencombat.gui.weapon import WeaponImageApplier
13
 from opencombat.gui.weapon import WeaponImageApplier
19
 }
21
 }
20
 
22
 
21
 MAN_STAND_UP = 'MAN_STAND_UP'
23
 MAN_STAND_UP = 'MAN_STAND_UP'
24
+MAN_CRAWLING = 'MAN_CRAWLING'
22
 
25
 
23
 
26
 
24
 class BaseActor(Actor):
27
 class BaseActor(Actor):
28
         config: Config,
31
         config: Config,
29
         subject: Subject,
32
         subject: Subject,
30
     ) -> None:
33
     ) -> None:
34
+        self._mode = MAN_STAND_UP
31
         self.weapon_image_applier = WeaponImageApplier(config, self)
35
         self.weapon_image_applier = WeaponImageApplier(config, self)
32
         super().__init__(image_path, subject=subject, config=config)
36
         super().__init__(image_path, subject=subject, config=config)
33
 
37
 
34
     @property
38
     @property
35
     def mode(self) -> str:
39
     def mode(self) -> str:
36
-        return MAN_STAND_UP
40
+        return self._mode
37
 
41
 
38
     @property
42
     @property
39
     def weapons(self) -> typing.List[str]:
43
     def weapons(self) -> typing.List[str]:
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
     def firing(self) -> None:
76
     def firing(self) -> None:
54
         pass
77
         pass
55
 
78
 

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

29
 
29
 
30
     def get_images_scheme(self) -> typing.Dict[str, typing.Dict[str, str]]:
30
     def get_images_scheme(self) -> typing.Dict[str, typing.Dict[str, str]]:
31
         from opencombat.gui.actor import MAN_STAND_UP
31
         from opencombat.gui.actor import MAN_STAND_UP
32
+        from opencombat.gui.actor import MAN_CRAWLING
32
         return {
33
         return {
33
             MAN_STAND_UP: {
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
         try:
53
         try:
40
             # FIXME Cache
54
             # FIXME Cache
41
             image_file_path = self.path_manager.path(
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
             return Image.open(image_file_path)
75
             return Image.open(image_file_path)
45
         except KeyError:
76
         except KeyError: