-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
734e333
commit b441fb9
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from __future__ import annotations | ||
from typing import Optional, Union | ||
|
||
from arcade.clock import Clock, GLOBAL_CLOCK | ||
|
||
def boot_strap_clock(clock: Optional[Clock] = None): | ||
""" | ||
Because the sub_clock is not a fully featured part of arcade we have to | ||
manipulate the clocks before the can be used with sub_clocks. | ||
This step will no longer be required when SubClocks become part of the main | ||
library. | ||
calling it will boostrap the global clock. | ||
DO NOT CALL MORE THAN ONCE PER CLOCK. | ||
Args: | ||
clock: a clcok that has yet to be setup. Defaults to arcade.clock.GLOBAL_CLOCK. | ||
""" | ||
clock = clock or GLOBAL_CLOCK | ||
|
||
if hasattr(clock, 'children'): | ||
raise ValueError(f'The clock {clock} has already been bootstrapped.') | ||
|
||
clock.children = [] # type: ignore -- No type check will ever like this, but we do what we must. | ||
|
||
def recursive_tick(delta_time: float) -> None: | ||
clock.tick(delta_time) | ||
for child in clock.children: # type: ignore -- we know the clock will have .children | ||
child.tick(clock._tick_delta_time) | ||
|
||
clock.tick = recursive_tick | ||
|
||
def add_child(child: SubClock): | ||
clock.children.append(child) # type: ignore -- we know the clock will have .children | ||
|
||
clock.add_child = add_child # type: ignore -- we know the clock will have .children | ||
|