Replace handle_play_like_call with pre_play and post_play method

This commit is contained in:
Grant Sanderson 2022-12-17 18:59:05 -08:00
parent 24fd6d890e
commit 38db5ca9b9

View file

@ -511,18 +511,15 @@ class Scene(object):
kw["override_skip_animations"] = True kw["override_skip_animations"] = True
return self.get_time_progression(duration, **kw) return self.get_time_progression(duration, **kw)
@staticmethod def pre_play(self):
def handle_play_like_call(func: Callable):
@wraps(func)
def wrapper(self, *args, **kwargs):
if self.inside_embed: if self.inside_embed:
self.save_state() self.save_state()
if self.presenter_mode and self.num_plays == 0: if self.presenter_mode and self.num_plays == 0:
self.hold_loop() self.hold_loop()
self.update_skipping_status() self.update_skipping_status()
should_write = not self.skip_animations
if should_write: if not self.skip_animations:
self.file_writer.begin_animation() self.file_writer.begin_animation()
if self.window: if self.window:
@ -530,9 +527,9 @@ class Scene(object):
self.virtual_animation_start_time = self.time self.virtual_animation_start_time = self.time
self.refresh_static_mobjects() self.refresh_static_mobjects()
func(self, *args, **kwargs)
if should_write: def post_play(self):
if not self.skip_animations:
self.file_writer.end_animation() self.file_writer.end_animation()
if self.inside_embed: if self.inside_embed:
@ -543,7 +540,6 @@ class Scene(object):
self.update_frame(dt=0, ignore_skipping=True) self.update_frame(dt=0, ignore_skipping=True)
self.num_plays += 1 self.num_plays += 1
return wrapper
def refresh_static_mobjects(self) -> None: def refresh_static_mobjects(self) -> None:
self.camera.refresh_static_mobjects() self.camera.refresh_static_mobjects()
@ -580,7 +576,6 @@ class Scene(object):
else: else:
self.update_mobjects(0) self.update_mobjects(0)
@handle_play_like_call
def play( def play(
self, self,
*proto_animations: Animation | _AnimationBuilder, *proto_animations: Animation | _AnimationBuilder,
@ -594,11 +589,12 @@ class Scene(object):
animations = list(map(prepare_animation, proto_animations)) animations = list(map(prepare_animation, proto_animations))
for anim in animations: for anim in animations:
anim.update_rate_info(run_time, rate_func, lag_ratio) anim.update_rate_info(run_time, rate_func, lag_ratio)
self.pre_play()
self.begin_animations(animations) self.begin_animations(animations)
self.progress_through_animations(animations) self.progress_through_animations(animations)
self.finish_animations(animations) self.finish_animations(animations)
self.post_play()
@handle_play_like_call
def wait( def wait(
self, self,
duration: float = DEFAULT_WAIT_TIME, duration: float = DEFAULT_WAIT_TIME,
@ -606,6 +602,7 @@ class Scene(object):
note: str = None, note: str = None,
ignore_presenter_mode: bool = False ignore_presenter_mode: bool = False
): ):
self.pre_play()
self.update_mobjects(dt=0) # Any problems with this? self.update_mobjects(dt=0) # Any problems with this?
if self.presenter_mode and not self.skip_animations and not ignore_presenter_mode: if self.presenter_mode and not self.skip_animations and not ignore_presenter_mode:
if note: if note:
@ -622,6 +619,7 @@ class Scene(object):
if stop_condition is not None and stop_condition(): if stop_condition is not None and stop_condition():
break break
self.refresh_static_mobjects() self.refresh_static_mobjects()
self.post_play()
return self return self
def hold_loop(self): def hold_loop(self):