Browse Source

image application for actor animations

Bastien Sevajol 6 years ago
parent
commit
b0844a8792
1 changed files with 36 additions and 5 deletions
  1. 36 5
      synergine2_cocos2d/actor.py

+ 36 - 5
synergine2_cocos2d/actor.py View File

56
         self.subject = subject
56
         self.subject = subject
57
         self.cshape = None  # type: collision_model.AARectShape
57
         self.cshape = None  # type: collision_model.AARectShape
58
         self.update_cshape()
58
         self.update_cshape()
59
-        self.build_animation_images()
59
+        self.build_animation_images(subject.id)
60
         self.current_image = image
60
         self.current_image = image
61
         self.need_update_cshape = False
61
         self.need_update_cshape = False
62
         self.properties = properties or {}
62
         self.properties = properties or {}
74
                     default_appliable_image,
74
                     default_appliable_image,
75
                 )
75
                 )
76
 
76
 
77
+            # FIXME NOW: nom des image utilise au dessus
77
             final_name = '_'.join([
78
             final_name = '_'.join([
78
                 str(subject_id),
79
                 str(subject_id),
79
                 ntpath.basename(base_image_path),
80
                 ntpath.basename(base_image_path),
86
     def get_default_appliable_images(self) -> typing.List[Image.Image]:
87
     def get_default_appliable_images(self) -> typing.List[Image.Image]:
87
         return []
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
     def freeze(self) -> None:
97
     def freeze(self) -> None:
90
         """
98
         """
91
         Set object to freeze mode: No visual modification can be done anymore
99
         Set object to freeze mode: No visual modification can be done anymore
112
         self.position = new_position
120
         self.position = new_position
113
         self.cshape.center = new_position  # Note: if remove: strange behaviour: drag change actor position with anomaly
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
         Fill self.animation_images with self.animation_image_paths
125
         Fill self.animation_images with self.animation_image_paths
118
         :return: None
126
         :return: None
119
         """
127
         """
128
+        cache_dir = self.config.resolve('global.cache_dir_path')
120
         for animation_name, animation_image_paths in self.animation_image_paths.items():
129
         for animation_name, animation_image_paths in self.animation_image_paths.items():
121
             self.animation_images[animation_name] = []
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
                 final_image_path = self.path_manager.path(animation_image_path)
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
                 self.animation_images[animation_name].append(
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