Pārlūkot izejas kodu

weapon man position matching with gui move type

Bastien Sevajol 6 gadus atpakaļ
vecāks
revīzija
ddb1a41e77
3 mainītis faili ar 22 papildinājumiem un 12 dzēšanām
  1. 11 3
      opencombat/gui/actor.py
  2. 2 2
      opencombat/gui/const.py
  3. 9 7
      opencombat/gui/weapon.py

+ 11 - 3
opencombat/gui/actor.py Parādīt failu

@@ -9,19 +9,25 @@ from synergine2_cocos2d.actor import Actor
9 9
 from opencombat.exception import UnknownWeapon
10 10
 from opencombat.gui.animation import ANIMATION_CRAWL
11 11
 from opencombat.gui.animation import ANIMATION_WALK
12
-from opencombat.gui.const import MAN_STAND_UP
12
+from opencombat.gui.const import POSITION_MAN_STAND_UP
13
+from opencombat.gui.const import POSITION_MAN_CRAWLING
13 14
 from opencombat.gui.weapon import RIFFLE
14 15
 from opencombat.gui.weapon import WeaponImageApplier
15 16
 
16 17
 
17 18
 class BaseActor(Actor):
19
+    position_matching = {
20
+        ANIMATION_WALK: POSITION_MAN_STAND_UP,
21
+        ANIMATION_CRAWL: POSITION_MAN_CRAWLING,
22
+    }
23
+
18 24
     def __init__(
19 25
         self,
20 26
         image_path: str,
21 27
         config: Config,
22 28
         subject: Subject,
23 29
     ) -> None:
24
-        self._mode = MAN_STAND_UP
30
+        self._mode = POSITION_MAN_STAND_UP
25 31
         self.weapon_image_applier = WeaponImageApplier(config, self)
26 32
         super().__init__(image_path, subject=subject, config=config)
27 33
 
@@ -52,10 +58,12 @@ class BaseActor(Actor):
52 58
         if not self.weapons:
53 59
             return []
54 60
 
61
+        position = self.position_matching[animation_name]
62
+
55 63
         try:
56 64
             return [
57 65
                 self.weapon_image_applier.get_animation_image_for_weapon(
58
-                    animation_name,
66
+                    position,
59 67
                     self.weapons[0],
60 68
                     animation_position,
61 69
                 )

+ 2 - 2
opencombat/gui/const.py Parādīt failu

@@ -1,7 +1,7 @@
1 1
 # coding: utf-8
2 2
 
3
-MAN_STAND_UP = 'MAN_STAND_UP'
4
-MAN_CRAWLING = 'MAN_CRAWLING'
3
+POSITION_MAN_STAND_UP = 'POSITION_MAN_STAND_UP'
4
+POSITION_MAN_CRAWLING = 'POSITION_MAN_CRAWLING'
5 5
 FLAG_DE = 'DE'
6 6
 FLAG_COLORS = {
7 7
     FLAG_DE

+ 9 - 7
opencombat/gui/weapon.py Parādīt failu

@@ -6,8 +6,8 @@ from synergine2.config import Config
6 6
 from synergine2_cocos2d.util import PathManager
7 7
 
8 8
 from opencombat.exception import UnknownWeapon
9
-from opencombat.gui.const import MAN_STAND_UP
10
-from opencombat.gui.const import MAN_CRAWLING
9
+from opencombat.gui.const import POSITION_MAN_STAND_UP
10
+from opencombat.gui.const import POSITION_MAN_CRAWLING
11 11
 
12 12
 if typing.TYPE_CHECKING:
13 13
     from opencombat.gui.actor import BaseActor
@@ -30,16 +30,14 @@ class WeaponImageApplier(ImageApplier):
30 30
         self.path_manager = PathManager(config.resolve('global.include_path.graphics'))
31 31
         self._cache = {}  # type: typing.Dict[str, Image.Image]
32 32
 
33
-    def get_images_scheme(self) -> typing.Dict[str, typing.Dict[str, str]]:
33
+    def get_images_scheme(self) -> typing.Dict[str, typing.Dict[str, typing.List[str]]]:
34 34
         return {
35
-            MAN_STAND_UP: {
35
+            POSITION_MAN_STAND_UP: {
36 36
                 RIFFLE: [
37 37
                     'actors/man_weap1.png'
38 38
                 ],
39 39
             },
40
-            # FIXME NOW
41
-            # MAN_CRAWLING: {
42
-            'CRAWL': {
40
+            POSITION_MAN_CRAWLING: {
43 41
                 RIFFLE: [
44 42
                     'actors/man_c1_weap1.png',
45 43
                     'actors/man_c2_weap1.png',
@@ -84,4 +82,8 @@ class WeaponImageApplier(ImageApplier):
84 82
             raise UnknownWeapon(
85 83
                 'Unknown weapon "{}" for mode "{}"'.format(weapon_type, mode),
86 84
             )
85
+        except IndexError:
86
+            raise UnknownWeapon(
87
+                'Unknown weapon "{}" for mode "{}"'.format(weapon_type, mode),
88
+            )
87 89