Selaa lähdekoodia

start and end callbacks

Bastien Sevajol 6 vuotta sitten
vanhempi
commit
79c69bd874
2 muutettua tiedostoa jossa 24 lisäystä ja 2 poistoa
  1. 0 1
      synergine2_cocos2d/actor.py
  2. 24 1
      synergine2_cocos2d/gui.py

+ 0 - 1
synergine2_cocos2d/actor.py Näytä tiedosto

@@ -132,7 +132,6 @@ class Actor(AnimatedInterface, cocos.sprite.Sprite):
132 132
                 final_image_path = self.path_manager.path(animation_image_path)
133 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 135
                 for appliable_image in self.get_animation_appliable_images(
137 136
                     animation_name,
138 137
                     i,

+ 24 - 1
synergine2_cocos2d/gui.py Näytä tiedosto

@@ -126,6 +126,8 @@ class Callback(object):
126 126
         func: typing.Callable[[], None],
127 127
         duration: float,
128 128
         delay: float=None,
129
+        end_callback: typing.Callable[[], None]=None,
130
+        start_callback: typing.Callable[[], None]=None,
129 131
     ) -> None:
130 132
         self.func = func
131 133
         self.duration = duration
@@ -135,8 +137,13 @@ class Callback(object):
135 137
         self.delay = delay
136 138
         if delay is not None:
137 139
             self.require_delay = True
140
+        self.end_callback = end_callback
141
+        self.start_callback = start_callback
138 142
 
139 143
     def execute(self) -> None:
144
+        if self.started is None and self.start_callback:
145
+            self.start_callback()
146
+
140 147
         if self.require_delay and not self.started:
141 148
             self.started = time.time()
142 149
             return
@@ -153,8 +160,15 @@ class Callback(object):
153 160
             self.func()
154 161
         elif not self.duration:
155 162
             self.func()
163
+
164
+            if self.end_callback is not None:
165
+                self.end_callback()
166
+
156 167
             raise FinishedCallback()
157 168
         else:
169
+            if self.end_callback is not None:
170
+                self.end_callback()
171
+
158 172
             raise FinishedCallback()
159 173
 
160 174
 
@@ -249,11 +263,20 @@ class EditLayer(cocos.layer.Layer):
249 263
         self.selectable_actors = []
250 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 274
         self.callbacks.append(Callback(
254 275
             callback,
255 276
             duration,
256 277
             delay=delay,
278
+            start_callback=start_callback,
279
+            end_callback=end_callback,
257 280
         ))
258 281
 
259 282
     def set_selectable(self, actor: Actor) -> None: