Browse Source

start and end callbacks

Bastien Sevajol 6 years ago
parent
commit
79c69bd874
2 changed files with 24 additions and 2 deletions
  1. 0 1
      synergine2_cocos2d/actor.py
  2. 24 1
      synergine2_cocos2d/gui.py

+ 0 - 1
synergine2_cocos2d/actor.py View File

132
                 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)
133
                 final_image = Image.open(final_image_path)
134
 
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(
135
                 for appliable_image in self.get_animation_appliable_images(
137
                     animation_name,
136
                     animation_name,
138
                     i,
137
                     i,

+ 24 - 1
synergine2_cocos2d/gui.py View File

126
         func: typing.Callable[[], None],
126
         func: typing.Callable[[], None],
127
         duration: float,
127
         duration: float,
128
         delay: float=None,
128
         delay: float=None,
129
+        end_callback: typing.Callable[[], None]=None,
130
+        start_callback: typing.Callable[[], None]=None,
129
     ) -> None:
131
     ) -> None:
130
         self.func = func
132
         self.func = func
131
         self.duration = duration
133
         self.duration = duration
135
         self.delay = delay
137
         self.delay = delay
136
         if delay is not None:
138
         if delay is not None:
137
             self.require_delay = True
139
             self.require_delay = True
140
+        self.end_callback = end_callback
141
+        self.start_callback = start_callback
138
 
142
 
139
     def execute(self) -> None:
143
     def execute(self) -> None:
144
+        if self.started is None and self.start_callback:
145
+            self.start_callback()
146
+
140
         if self.require_delay and not self.started:
147
         if self.require_delay and not self.started:
141
             self.started = time.time()
148
             self.started = time.time()
142
             return
149
             return
153
             self.func()
160
             self.func()
154
         elif not self.duration:
161
         elif not self.duration:
155
             self.func()
162
             self.func()
163
+
164
+            if self.end_callback is not None:
165
+                self.end_callback()
166
+
156
             raise FinishedCallback()
167
             raise FinishedCallback()
157
         else:
168
         else:
169
+            if self.end_callback is not None:
170
+                self.end_callback()
171
+
158
             raise FinishedCallback()
172
             raise FinishedCallback()
159
 
173
 
160
 
174
 
249
         self.selectable_actors = []
263
         self.selectable_actors = []
250
         self.callbacks = []  # type: typing.List[Callback]
264
         self.callbacks = []  # type: typing.List[Callback]
251
 
265
 
252
-    def append_callback(self, callback: typing.Callable[[], None], duration: float, delay: float=None) -> None:
266
+    def append_callback(
267
+        self,
268
+        callback: typing.Callable[[], None],
269
+        duration: float,
270
+        delay: float=None,
271
+        start_callback: typing.Callable[[], None]=None,
272
+        end_callback: typing.Callable[[], None]=None,
273
+    ) -> None:
253
         self.callbacks.append(Callback(
274
         self.callbacks.append(Callback(
254
             callback,
275
             callback,
255
             duration,
276
             duration,
256
             delay=delay,
277
             delay=delay,
278
+            start_callback=start_callback,
279
+            end_callback=end_callback,
257
         ))
280
         ))
258
 
281
 
259
     def set_selectable(self, actor: Actor) -> None:
282
     def set_selectable(self, actor: Actor) -> None: