Преглед изворни кода

image application for actor animations

Bastien Sevajol пре 6 година
родитељ
комит
b0844a8792
1 измењених фајлова са 36 додато и 5 уклоњено
  1. 36 5
      synergine2_cocos2d/actor.py

+ 36 - 5
synergine2_cocos2d/actor.py Прегледај датотеку

@@ -56,7 +56,7 @@ class Actor(AnimatedInterface, cocos.sprite.Sprite):
56 56
         self.subject = subject
57 57
         self.cshape = None  # type: collision_model.AARectShape
58 58
         self.update_cshape()
59
-        self.build_animation_images()
59
+        self.build_animation_images(subject.id)
60 60
         self.current_image = image
61 61
         self.need_update_cshape = False
62 62
         self.properties = properties or {}
@@ -74,6 +74,7 @@ class Actor(AnimatedInterface, cocos.sprite.Sprite):
74 74
                     default_appliable_image,
75 75
                 )
76 76
 
77
+            # FIXME NOW: nom des image utilise au dessus
77 78
             final_name = '_'.join([
78 79
                 str(subject_id),
79 80
                 ntpath.basename(base_image_path),
@@ -86,6 +87,13 @@ class Actor(AnimatedInterface, cocos.sprite.Sprite):
86 87
     def get_default_appliable_images(self) -> typing.List[Image.Image]:
87 88
         return []
88 89
 
90
+    def get_animation_appliable_images(
91
+        self,
92
+        animation_name: str,
93
+        animation_position: int,
94
+    ) -> typing.List[Image.Image]:
95
+        return []
96
+
89 97
     def freeze(self) -> None:
90 98
         """
91 99
         Set object to freeze mode: No visual modification can be done anymore
@@ -112,18 +120,41 @@ class Actor(AnimatedInterface, cocos.sprite.Sprite):
112 120
         self.position = new_position
113 121
         self.cshape.center = new_position  # Note: if remove: strange behaviour: drag change actor position with anomaly
114 122
 
115
-    def build_animation_images(self) -> None:
123
+    def build_animation_images(self, subject_id: int) -> None:
116 124
         """
117 125
         Fill self.animation_images with self.animation_image_paths
118 126
         :return: None
119 127
         """
128
+        cache_dir = self.config.resolve('global.cache_dir_path')
120 129
         for animation_name, animation_image_paths in self.animation_image_paths.items():
121 130
             self.animation_images[animation_name] = []
122
-            for animation_image_path in animation_image_paths:
131
+            for i, animation_image_path in enumerate(animation_image_paths):
123 132
                 final_image_path = self.path_manager.path(animation_image_path)
133
+                final_image = Image.open(final_image_path)
134
+
135
+                # NOW: recup les image a paste en fonction du mode et de la weapon
136
+                for appliable_image in self.get_animation_appliable_images(
137
+                    animation_name,
138
+                    i,
139
+                ):
140
+                    final_image.paste(
141
+                        appliable_image,
142
+                        (0, 0),
143
+                        appliable_image,
144
+                    )
145
+
146
+                # FIXME NOW: nom des image utilise au dessus
147
+                final_name = '_'.join([
148
+                    str(subject_id),
149
+                    ntpath.basename(final_image_path),
150
+                ])
151
+                final_path = os.path.join(cache_dir, final_name)
152
+
153
+                final_image.save(final_path)
154
+
124 155
                 self.animation_images[animation_name].append(
125
-                    pyglet.resource.image(
126
-                        final_image_path,
156
+                    pyglet.image.load(
157
+                        final_path,
127 158
                     )
128 159
                 )
129 160