1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
from .component import Component, ComponentType
class SpriteSpec:
def __init__(
self,
ms_per_frame: int,
top_x: int,
top_y: int,
end_x: int,
end_y: int,
frames: int,
):
self.ms_per_frame = ms_per_frame
self.frames = frames
self.top_x = top_x
self.top_y = top_y
self.end_x = end_x
self.end_y = end_y
class SpriteSheet(Component):
def __init__(
self,
source: str,
state_to_spritespec: dict[str, SpriteSpec],
initial_state: str,
):
super().__init__(ComponentType.SPRITESHEET)
self.source = source
self.state_to_spritespec = state_to_spritespec
# these are only really used for client initialization
self.initial_state = initial_state
self.current_frame = 0
self.last_update = 0
def __repr__(self) -> str:
return f"SpriteSheet(source={self.source}, state_to_spritespec={self.state_to_spritespec}, initial_state={self.initial_state}, current_frame={self.current_frame}, last_update={self.last_update})"
def to_dict(self) -> dict:
return {
"source": self.source,
"current_frame": self.current_frame,
"last_update": self.last_update,
"current_state": self.initial_state,
"state_to_spritespec": self.state_to_spritespec,
}
|