1
1
from __future__ import annotations
2
+
2
3
from typing import Optional , Union
3
4
4
- from arcade .clock import Clock , GLOBAL_CLOCK
5
+ from arcade .clock import GLOBAL_CLOCK , Clock
6
+
5
7
6
- def boot_strap_clock (clock : Optional [Clock ] = None ):
8
+ def boot_strap_clock (clock : Optional [Clock ] = None ) -> Clock :
7
9
"""
8
10
Because the sub_clock is not a fully featured part of arcade we have to
9
11
manipulate the clocks before the can be used with sub_clocks.
@@ -19,22 +21,26 @@ def boot_strap_clock(clock: Optional[Clock] = None):
19
21
"""
20
22
clock = clock or GLOBAL_CLOCK
21
23
22
- if hasattr (clock , ' children' ):
23
- raise ValueError (f' The clock { clock } has already been bootstrapped.' )
24
+ if hasattr (clock , " children" ):
25
+ raise ValueError (f" The clock { clock } has already been bootstrapped." )
24
26
25
- clock .children = [] # type: ignore -- No type check will ever like this, but we do what we must.
27
+ # No type check will ever like this, but we do what we must.
28
+ clock .children = [] # type: ignore
26
29
27
30
def recursive_tick (delta_time : float ) -> None :
28
31
clock .tick (delta_time )
29
- for child in clock .children : # type: ignore -- we know the clock will have .children
32
+ for child in clock .children : # type: ignore
30
33
child .tick (clock ._tick_delta_time )
31
34
32
- clock .tick = recursive_tick
35
+ # Hey we did a decorator manually! what a time to be alive.
36
+ clock .tick = recursive_tick # type: ignore
37
+
38
+ def add_child (child : SubClock ) -> None :
39
+ clock .children .append (child ) # type: ignore
33
40
34
- def add_child (child : SubClock ):
35
- clock .children .append (child ) # type: ignore -- we know the clock will have .children
41
+ clock .add_child = add_child # type: ignore
36
42
37
- clock . add_child = add_child # type: ignore -- we know the clock will have .children
43
+ return clock
38
44
39
45
40
46
class SubClock (Clock ):
@@ -49,20 +55,22 @@ class SubClock(Clock):
49
55
i.e. a value of 0.5 means time elapsed half as fast for this clock. Defaults to 1.0.
50
56
"""
51
57
52
- def __init__ (self , parent : Union [Clock , SubClock , None ] = None , tick_speed : float = 1 ):
58
+ def __init__ (self , parent : Union [Clock , SubClock , None ] = None , tick_speed : float = 1 ) -> None :
53
59
parent = parent or GLOBAL_CLOCK
54
60
super ().__init__ (parent ._elapsed_time , parent ._tick , tick_speed )
55
61
self .children : list [SubClock ] = []
56
62
try :
57
- parent .add_child (self ) # type: ignore -- we know the clock will have .children (or if not we want it to yell)
63
+ parent .add_child (self ) # type: ignore
58
64
except AttributeError :
59
- raise AttributeError (f'The clock { parent } has not been bootstrapped properly'
60
- f'call boot_strap_clock({ parent } ) before adding children' )
65
+ raise AttributeError (
66
+ f"The clock { parent } has not been bootstrapped properly"
67
+ f"call boot_strap_clock({ parent } ) before adding children"
68
+ )
61
69
62
- def add_child (self , child : SubClock ):
70
+ def add_child (self , child : SubClock ) -> None :
63
71
self .children .append (child )
64
72
65
- def tick (self , delta_time : float ):
73
+ def tick (self , delta_time : float ) -> None :
66
74
super ().tick (delta_time )
67
75
68
76
for child in self .children :
0 commit comments