batframework 1.0.0__py3-none-any.whl → 1.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- batFramework/__init__.py +1 -1
- batFramework/easing.py +5 -5
- batFramework/entity.py +1 -33
- batFramework/gui/button.py +63 -10
- batFramework/gui/constraints.py +18 -2
- batFramework/gui/container.py +3 -0
- batFramework/gui/debugger.py +1 -1
- batFramework/gui/frame.py +9 -12
- batFramework/gui/label.py +0 -2
- batFramework/gui/layout.py +10 -16
- batFramework/gui/widget.py +2 -3
- batFramework/manager.py +11 -7
- batFramework/scene.py +0 -10
- batFramework/sceneManager.py +3 -4
- batFramework/time.py +60 -65
- {batframework-1.0.0.dist-info → batframework-1.0.1.dist-info}/METADATA +2 -2
- {batframework-1.0.0.dist-info → batframework-1.0.1.dist-info}/RECORD +20 -20
- {batframework-1.0.0.dist-info → batframework-1.0.1.dist-info}/LICENCE +0 -0
- {batframework-1.0.0.dist-info → batframework-1.0.1.dist-info}/WHEEL +0 -0
- {batframework-1.0.0.dist-info → batframework-1.0.1.dist-info}/top_level.txt +0 -0
batFramework/__init__.py
CHANGED
@@ -39,7 +39,7 @@ def init_screen(resolution: tuple[int, int], flags: int = 0, vsync: int = 0):
|
|
39
39
|
const.RESOLUTION,const.FLAGS, vsync=const.VSYNC
|
40
40
|
)
|
41
41
|
print(
|
42
|
-
f"Window : {resolution[0]}x{resolution[1]}
|
42
|
+
f"Window : {resolution[0]}x{resolution[1]} [vsync:{pygame.display.is_vsync()}]"
|
43
43
|
)
|
44
44
|
|
45
45
|
def init(
|
batFramework/easing.py
CHANGED
@@ -20,14 +20,14 @@ class EasingAnimation(bf.Timer):
|
|
20
20
|
|
21
21
|
def __init__(
|
22
22
|
self,
|
23
|
-
name: str =
|
23
|
+
name: str = '',
|
24
24
|
easing_function: Easing = Easing.LINEAR,
|
25
25
|
duration: int = 100,
|
26
26
|
update_callback=None,
|
27
27
|
end_callback=None,
|
28
28
|
loop: bool = False,
|
29
29
|
reusable: bool = False,
|
30
|
-
):
|
30
|
+
)->None:
|
31
31
|
self.easing_function = easing_function
|
32
32
|
self.update_callback = update_callback
|
33
33
|
self.value = 0.0
|
@@ -40,8 +40,8 @@ class EasingAnimation(bf.Timer):
|
|
40
40
|
self.value = 0
|
41
41
|
super().start() # self.elapsed_progress set to 0 here
|
42
42
|
|
43
|
-
def update(self) -> bool:
|
44
|
-
if super().update():
|
43
|
+
def update(self,dt) -> bool:
|
44
|
+
if super().update(dt):
|
45
45
|
return True # If timer ended now, end() is called. So don't process value.
|
46
46
|
self._process_value()
|
47
47
|
# if self.name == 0: print("UPDATING (callback) in easing")
|
@@ -61,7 +61,7 @@ class EasingAnimation(bf.Timer):
|
|
61
61
|
|
62
62
|
def _process_value(self):
|
63
63
|
p0, p1, p2, p3 = self.easing_function.control_points
|
64
|
-
cache_key = (self.elapsed_progress, p0, p1, p2, p3)
|
64
|
+
cache_key = (self.easing_function,self.elapsed_progress, p0, p1, p2, p3)
|
65
65
|
if cache_key in EasingAnimation._cache:
|
66
66
|
y = EasingAnimation._cache[cache_key]
|
67
67
|
else:
|
batFramework/entity.py
CHANGED
@@ -33,29 +33,9 @@ class Entity:
|
|
33
33
|
self.visible: bool = True
|
34
34
|
self.debug_color: tuple = bf.color.DARK_RED
|
35
35
|
self.render_order: int = 0
|
36
|
-
self.rotation_origin = (0, 0)
|
37
|
-
self.rotation: float = 0
|
38
|
-
self._rotated_cache = (0,self.surface)
|
39
36
|
self.uid: Any = Entity.__instance_count
|
40
37
|
Entity.__instance_count += 1
|
41
38
|
|
42
|
-
def set_rotation_origin(self, point: tuple) -> Self:
|
43
|
-
self.rotation_origin = point
|
44
|
-
return self
|
45
|
-
|
46
|
-
def get_rotation_origin(self) -> tuple:
|
47
|
-
return self.rotation_origin
|
48
|
-
|
49
|
-
def rotate(self, value: float) -> Self:
|
50
|
-
self.rotation = value
|
51
|
-
self._rotated_cache = None
|
52
|
-
return self
|
53
|
-
|
54
|
-
def rotate_by(self, value: float) -> Self:
|
55
|
-
self.rotation += value
|
56
|
-
self._rotated_cache = None
|
57
|
-
return self
|
58
|
-
|
59
39
|
def set_render_order(self, render_order: int) -> Self:
|
60
40
|
self.render_order = render_order
|
61
41
|
return self
|
@@ -175,18 +155,6 @@ class Entity:
|
|
175
155
|
should_not_draw = not self.visible or not self.surface or not camera.intersects(self.rect)
|
176
156
|
if should_not_draw:
|
177
157
|
return 0
|
178
|
-
|
179
|
-
camera.surface.blit(self.surface, camera.transpose(self.rect))
|
180
|
-
return 1
|
181
|
-
if self._rotated_cache is not None:
|
182
|
-
camera.surface.blit(self._rotated_cache[1], camera.transpose(self.rect))
|
183
|
-
return 1
|
184
|
-
|
185
|
-
rotated = pygame.transform.rotate(self.surface,self.rotation)
|
186
|
-
# if self.convert_alpha : rotated.convert_alpha()
|
187
|
-
new_center = self.rect.move(self.rotation_origin[0],self.rotation_origin[1]).center
|
188
|
-
tmp = rotated.get_rect(center = new_center)
|
189
|
-
camera.surface.blit(rotated, camera.transpose(tmp))
|
190
|
-
self._rotated_cache = (self.rotation,rotated)
|
158
|
+
camera.surface.blit(self.surface, camera.transpose(self.rect))
|
191
159
|
|
192
160
|
return 1
|
batFramework/gui/button.py
CHANGED
@@ -8,16 +8,42 @@ import pygame
|
|
8
8
|
class Button(Label, InteractiveWidget):
|
9
9
|
_cache = {}
|
10
10
|
|
11
|
-
def __init__(self, text: str, callback: Callable = None) -> None:
|
11
|
+
def __init__(self, text: str, callback: None| Callable = None) -> None:
|
12
12
|
# Label.__init__(self,text)
|
13
13
|
self.callback = callback
|
14
14
|
self.click_action = bf.Action("click").add_mouse_control(1)
|
15
15
|
self.hover_action = bf.Action("hover").add_mouse_control(pygame.MOUSEMOTION)
|
16
16
|
self.is_hovered: bool = False
|
17
17
|
self.is_clicking: bool = False
|
18
|
+
self.effect_max :float= 20
|
19
|
+
self.effect_speed :float= 1.2
|
20
|
+
self.effect :float = 0
|
21
|
+
self.enabled :bool = True
|
18
22
|
super().__init__(text=text)
|
19
23
|
self.set_debug_color("cyan")
|
20
24
|
|
25
|
+
def get_surface_filter(self)->pygame.Surface|None:
|
26
|
+
if not self.surface : return None
|
27
|
+
size = self.surface.get_size()
|
28
|
+
surface_filter = Button._cache.get(size, None)
|
29
|
+
if surface_filter is None:
|
30
|
+
surface_filter = pygame.Surface(size).convert_alpha()
|
31
|
+
surface_filter.fill((30, 30, 30, 0))
|
32
|
+
Button._cache[size] = surface_filter
|
33
|
+
return surface_filter
|
34
|
+
def enable(self)->Self:
|
35
|
+
self.enabled = True
|
36
|
+
self.build()
|
37
|
+
return self
|
38
|
+
|
39
|
+
def disable(self)->Self:
|
40
|
+
self.enabled = False
|
41
|
+
self.build()
|
42
|
+
return self
|
43
|
+
|
44
|
+
def is_enabled(self)->bool:
|
45
|
+
return self.enabled
|
46
|
+
|
21
47
|
def set_callback(self, callback: Callable) -> Self:
|
22
48
|
self.callback = callback
|
23
49
|
return self
|
@@ -31,7 +57,7 @@ class Button(Label, InteractiveWidget):
|
|
31
57
|
self.build()
|
32
58
|
|
33
59
|
def to_string_id(self) -> str:
|
34
|
-
return f"Button({self._text})"
|
60
|
+
return f"Button({self._text}){'' if self.enabled else '[disabled]'}"
|
35
61
|
|
36
62
|
def click(self) -> None:
|
37
63
|
if self.callback is not None and not self.is_clicking:
|
@@ -39,6 +65,9 @@ class Button(Label, InteractiveWidget):
|
|
39
65
|
self.callback()
|
40
66
|
self.is_clicking = False
|
41
67
|
|
68
|
+
def start_effect(self):
|
69
|
+
if self.effect <= 0 : self.effect = self.effect_max
|
70
|
+
|
42
71
|
def do_process_actions(self, event):
|
43
72
|
self.click_action.process_event(event)
|
44
73
|
self.hover_action.process_event(event)
|
@@ -52,10 +81,11 @@ class Button(Label, InteractiveWidget):
|
|
52
81
|
if self.click_action.is_active():
|
53
82
|
root = self.get_root()
|
54
83
|
if root is None : return res
|
55
|
-
if root.get_hovered() == self:
|
84
|
+
if root.get_hovered() == self and self.enabled:
|
56
85
|
if not self.is_focused:
|
57
86
|
self.get_focus()
|
58
|
-
self.click()
|
87
|
+
# self.click()
|
88
|
+
self.start_effect()
|
59
89
|
res = True
|
60
90
|
elif self.hover_action.is_active():
|
61
91
|
root = self.get_root()
|
@@ -70,15 +100,38 @@ class Button(Label, InteractiveWidget):
|
|
70
100
|
res = True
|
71
101
|
return res
|
72
102
|
|
103
|
+
def update(self,dt):
|
104
|
+
super().update(dt)
|
105
|
+
if self.effect > 0:
|
106
|
+
self.effect -= dt*60*self.effect_speed
|
107
|
+
self.build()
|
108
|
+
if self.effect <= 0:
|
109
|
+
self.is_hovered = False
|
110
|
+
self.effect = 0
|
111
|
+
self.click()
|
112
|
+
self.build()
|
113
|
+
|
114
|
+
def _build_effect(self)->None:
|
115
|
+
pygame.draw.rect(
|
116
|
+
self.surface,
|
117
|
+
bf.color.CLOUD_WHITE,
|
118
|
+
(0,0,*self.surface.get_size()),
|
119
|
+
int(self.effect),
|
120
|
+
*self._border_radius
|
121
|
+
)
|
122
|
+
|
73
123
|
def build(self) -> None:
|
74
124
|
super().build()
|
125
|
+
size = self.surface.get_size()
|
126
|
+
if not self.enabled:
|
127
|
+
self.surface.blit(self.get_surface_filter(), (0, 0), special_flags=pygame.BLEND_SUB)
|
128
|
+
return
|
129
|
+
if self.effect:
|
130
|
+
if self.effect >= 1 :
|
131
|
+
self._build_effect()
|
132
|
+
return
|
75
133
|
if self.is_hovered:
|
76
|
-
|
77
|
-
if hover_surf is None:
|
78
|
-
hover_surf = pygame.Surface(self.surface.get_size()).convert_alpha()
|
79
|
-
hover_surf.fill((30, 30, 30, 0))
|
80
|
-
Button._cache[self.surface.get_size()] = hover_surf
|
81
|
-
self.surface.blit(hover_surf, (0, 0), special_flags=pygame.BLEND_ADD)
|
134
|
+
self.surface.blit(self.get_surface_filter(), (0, 0), special_flags=pygame.BLEND_ADD)
|
82
135
|
|
83
136
|
def apply_contraints(self) -> None:
|
84
137
|
super().apply_constraints()
|
batFramework/gui/constraints.py
CHANGED
@@ -137,11 +137,12 @@ class ConstraintPercentageHeight(Constraint):
|
|
137
137
|
|
138
138
|
|
139
139
|
class ConstraintHeight(Constraint):
|
140
|
-
def __init__(self, height: float):
|
140
|
+
def __init__(self, height: float, keep_autoresize: bool = True):
|
141
141
|
if height < 0:
|
142
142
|
raise ValueError("height can't be negative")
|
143
143
|
super().__init__(name="height")
|
144
144
|
self.height = height
|
145
|
+
self.keep_autoresize:bool = keep_autoresize
|
145
146
|
|
146
147
|
def to_string(self) -> str:
|
147
148
|
return f"{super().to_string()}.(height={self.height})"
|
@@ -151,15 +152,23 @@ class ConstraintHeight(Constraint):
|
|
151
152
|
|
152
153
|
def apply_constraint(self, parent_widget, child_widget):
|
153
154
|
if not self.evaluate(parent_widget, child_widget):
|
155
|
+
if child_widget.autoresize:
|
156
|
+
if self.keep_autoresize:
|
157
|
+
print(
|
158
|
+
f"Warning: Constraint on {child_widget.to_string()} can't resize, autoresize set to True"
|
159
|
+
)
|
160
|
+
return
|
161
|
+
child_widget.set_autoresize(False)
|
154
162
|
child_widget.set_size(child_widget.rect.w, self.height)
|
155
163
|
|
156
164
|
|
157
165
|
class ConstraintWidth(Constraint):
|
158
|
-
def __init__(self, width: float):
|
166
|
+
def __init__(self, width: float, keep_autoresize: bool = True):
|
159
167
|
if width < 0:
|
160
168
|
raise ValueError("width can't be negative")
|
161
169
|
super().__init__(name="width")
|
162
170
|
self.width = width
|
171
|
+
self.keep_autoresize : bool = keep_autoresize
|
163
172
|
|
164
173
|
def to_string(self) -> str:
|
165
174
|
return f"{super().to_string()}.(width={self.width})"
|
@@ -169,6 +178,13 @@ class ConstraintWidth(Constraint):
|
|
169
178
|
|
170
179
|
def apply_constraint(self, parent_widget, child_widget):
|
171
180
|
if not self.evaluate(parent_widget, child_widget):
|
181
|
+
if child_widget.autoresize:
|
182
|
+
if self.keep_autoresize:
|
183
|
+
print(
|
184
|
+
f"Warning: Constraint on {child_widget.to_string()} can't resize, autoresize set to True"
|
185
|
+
)
|
186
|
+
return
|
187
|
+
child_widget.set_autoresize(False)
|
172
188
|
child_widget.set_size(self.width, child_widget.rect.h)
|
173
189
|
|
174
190
|
|
batFramework/gui/container.py
CHANGED
batFramework/gui/debugger.py
CHANGED
@@ -55,7 +55,7 @@ class Debugger(Label):
|
|
55
55
|
def update(self, dt: float) -> None:
|
56
56
|
if not self.parent_scene:
|
57
57
|
return
|
58
|
-
if self.parent_scene.get_sharedVar("debugging_mode")
|
58
|
+
if self.parent_scene.get_sharedVar("debugging_mode") != 1:
|
59
59
|
self.set_visible(False)
|
60
60
|
return
|
61
61
|
self.set_visible(True)
|
batFramework/gui/frame.py
CHANGED
@@ -4,25 +4,22 @@ import pygame
|
|
4
4
|
|
5
5
|
|
6
6
|
class Frame(Shape):
|
7
|
-
def __init__(self, width: float, height: float):
|
7
|
+
def __init__(self, width: float, height: float,fit_to_children:bool=True):
|
8
|
+
self.fit_to_children = fit_to_children
|
8
9
|
super().__init__(width, height)
|
9
10
|
self.set_debug_color("magenta")
|
10
|
-
|
11
11
|
def to_string_id(self) -> str:
|
12
12
|
return "Frame"
|
13
13
|
|
14
|
-
def
|
14
|
+
def _fit_to_children(self)->None:
|
15
15
|
# TODO CLEAN THIS UP
|
16
16
|
if not self.children: return
|
17
|
-
|
18
|
-
self.
|
19
|
-
self.
|
20
|
-
self.set_size(*self.inflate_rect_by_padding(target_size).size)
|
21
|
-
# *self.inflate_rect_by_padding(self.rect.unionall(list(c.rect for c in self.children))).size
|
22
|
-
for c in self.children:
|
23
|
-
c.set_position(*c.rect.clamp(self.get_content_rect()).topleft)
|
17
|
+
children_rect = self.children[0].rect.unionall(list(c.rect for c in self.children))
|
18
|
+
self.set_size(*self.inflate_rect_by_padding(children_rect).size)
|
19
|
+
self.rect.center = children_rect.center
|
24
20
|
self.apply_all_constraints()
|
25
|
-
|
21
|
+
|
26
22
|
def children_modified(self) -> None:
|
27
|
-
self.fit_to_children()
|
28
23
|
super().children_modified()
|
24
|
+
if self.fit_to_children:
|
25
|
+
self._fit_to_children()
|
batFramework/gui/label.py
CHANGED
batFramework/gui/layout.py
CHANGED
@@ -12,7 +12,7 @@ class Layout:
|
|
12
12
|
self.children_rect = pygame.FRect(0, 0, 0, 0)
|
13
13
|
|
14
14
|
def set_child_constraints(self, *constraints) -> Self:
|
15
|
-
self.child_constraints = constraints
|
15
|
+
self.child_constraints = list(constraints)
|
16
16
|
self.arrange()
|
17
17
|
return self
|
18
18
|
|
@@ -25,7 +25,7 @@ class Layout:
|
|
25
25
|
|
26
26
|
|
27
27
|
class Column(Layout):
|
28
|
-
def __init__(self, gap: int = 0, fit_children: bool =
|
28
|
+
def __init__(self, gap: int = 0, fit_children: bool = True, center: bool = True):
|
29
29
|
super().__init__()
|
30
30
|
self.gap = gap
|
31
31
|
self.fit_children: bool = fit_children
|
@@ -45,10 +45,10 @@ class Column(Layout):
|
|
45
45
|
parent_width,
|
46
46
|
parent_height,
|
47
47
|
)
|
48
|
-
if self.center:
|
49
|
-
self.children_rect.center = self.parent.rect.center
|
50
48
|
if self.fit_children:
|
51
49
|
self.parent.set_size(parent_width,parent_height)
|
50
|
+
if self.center:
|
51
|
+
self.children_rect.center = self.parent.rect.center
|
52
52
|
|
53
53
|
current_y = self.children_rect.top
|
54
54
|
|
@@ -57,11 +57,10 @@ class Column(Layout):
|
|
57
57
|
current_y += child.rect.h + self.gap
|
58
58
|
for c in self.child_constraints:
|
59
59
|
child.add_constraints(c)
|
60
|
-
# if not child.has_constraint(c.name):
|
61
60
|
|
62
61
|
|
63
62
|
class Row(Layout):
|
64
|
-
def __init__(self, gap: int = 0, fit_children: bool =
|
63
|
+
def __init__(self, gap: int = 0, fit_children: bool = True, center: bool = True):
|
65
64
|
super().__init__()
|
66
65
|
self.gap = gap
|
67
66
|
self.fit_children: bool = fit_children
|
@@ -72,8 +71,9 @@ class Row(Layout):
|
|
72
71
|
return
|
73
72
|
|
74
73
|
len_children = len(self.parent.children)
|
75
|
-
parent_width = sum(c.
|
76
|
-
parent_height = max(c.
|
74
|
+
parent_width = sum(c.get_min_required_size()[0] for c in self.parent.children)
|
75
|
+
parent_height = max(c.get_min_required_size()[1] for c in self.parent.children)
|
76
|
+
|
77
77
|
if self.gap:
|
78
78
|
parent_width += (len_children - 1) * self.gap
|
79
79
|
self.children_rect.update(
|
@@ -85,18 +85,12 @@ class Row(Layout):
|
|
85
85
|
if self.center:
|
86
86
|
self.children_rect.center = self.parent.get_content_center()
|
87
87
|
if self.fit_children:
|
88
|
-
# c = self.parent.get_constraint("width")
|
89
|
-
# if not c or c.width != parent_width:
|
90
|
-
# self.parent.add_constraints(ConstraintWidth(parent_width))
|
91
|
-
# c = self.parent.get_constraint("height")
|
92
|
-
# if not c or c.height != parent_height:
|
93
|
-
# self.parent.add_constraints(ConstraintHeight(parent_height))
|
94
88
|
self.parent.set_size(parent_width,parent_height)
|
89
|
+
|
95
90
|
current_x = self.children_rect.left
|
96
91
|
|
97
92
|
for child in self.parent.children:
|
98
93
|
child.set_position(current_x, self.parent.rect.y)
|
99
94
|
current_x += child.rect.w + self.gap
|
100
95
|
for c in self.child_constraints:
|
101
|
-
|
102
|
-
child.add_constraints(c)
|
96
|
+
child.add_constraints(c)
|
batFramework/gui/widget.py
CHANGED
@@ -48,9 +48,6 @@ class Widget(bf.Entity):
|
|
48
48
|
old_raw_size[0] + self.padding[0] + self.padding[2],
|
49
49
|
old_raw_size[1] + self.padding[1] + self.padding[3],
|
50
50
|
)
|
51
|
-
if self.parent:
|
52
|
-
self.apply_constraints()
|
53
|
-
self.parent.children_modified()
|
54
51
|
return self
|
55
52
|
|
56
53
|
|
@@ -340,3 +337,5 @@ class Widget(bf.Entity):
|
|
340
337
|
def children_modified(self) -> None:
|
341
338
|
if self.parent and not self.is_root:
|
342
339
|
self.parent.children_modified()
|
340
|
+
|
341
|
+
|
batFramework/manager.py
CHANGED
@@ -10,25 +10,28 @@ class Manager(bf.SceneManager):
|
|
10
10
|
self._timeManager = bf.TimeManager()
|
11
11
|
self._cutsceneManager = bf.CutsceneManager(self)
|
12
12
|
self._clock: pygame.Clock = pygame.Clock()
|
13
|
+
self.do_pre_init()
|
13
14
|
super().__init__(*initial_scene_list)
|
14
15
|
self.set_sharedVar("clock", self._clock)
|
15
16
|
self.do_init()
|
16
17
|
|
17
18
|
@staticmethod
|
18
|
-
def set_icon(path: str):
|
19
|
-
surf = pygame.image.load(bf.
|
19
|
+
def set_icon(path: str)->None:
|
20
|
+
surf = pygame.image.load(bf.ResourceManager().get_path(path)).convert_alpha()
|
20
21
|
pygame.display.set_icon(surf)
|
21
22
|
|
22
|
-
def get_fps(self):
|
23
|
+
def get_fps(self)->float:
|
23
24
|
return self._clock.get_fps()
|
24
25
|
|
25
|
-
def do_init(self):
|
26
|
+
def do_init(self)->None:
|
26
27
|
pass
|
27
28
|
|
29
|
+
def do_pre_init(self)->None:
|
30
|
+
pass
|
28
31
|
def stop(self) -> None:
|
29
32
|
self._running = False
|
30
33
|
|
31
|
-
def run(self):
|
34
|
+
def run(self)->None:
|
32
35
|
self._running = True
|
33
36
|
dt: float = 0
|
34
37
|
while self._running:
|
@@ -40,10 +43,11 @@ class Manager(bf.SceneManager):
|
|
40
43
|
bf.const.set_resolution((event.w, event.h))
|
41
44
|
self.process_event(event)
|
42
45
|
# update
|
43
|
-
dt = self._clock.tick(bf.const.FPS if not bf.const.VSYNC else 0) / 1000
|
46
|
+
# dt = self._clock.tick(bf.const.FPS if not bf.const.VSYNC else 0) / 1000
|
47
|
+
dt = self._clock.tick(0 if bf.const.VSYNC else bf.const.FPS) / 1000
|
44
48
|
# dt = min(dt, 0.02) dirty fix for dt being too high when window not focused for a long time
|
45
49
|
self._cutsceneManager.update(dt)
|
46
|
-
self._timeManager.update()
|
50
|
+
self._timeManager.update(dt)
|
47
51
|
self.update(dt)
|
48
52
|
# render
|
49
53
|
self.draw(self._screen)
|
batFramework/scene.py
CHANGED
@@ -7,16 +7,6 @@ if TYPE_CHECKING:
|
|
7
7
|
from .sceneManager import SceneManager
|
8
8
|
import pygame
|
9
9
|
import batFramework as bf
|
10
|
-
import math
|
11
|
-
|
12
|
-
|
13
|
-
def rotate_point(origin, point, angle):
|
14
|
-
ox, oy = origin
|
15
|
-
px, py = point
|
16
|
-
angle_rad = math.radians(angle)
|
17
|
-
qx = ox + math.cos(angle_rad) * (px - ox) - math.sin(angle_rad) * (py - oy)
|
18
|
-
qy = oy + math.sin(angle_rad) * (px - ox) + math.cos(angle_rad) * (py - oy)
|
19
|
-
return int(qx), int(qy)
|
20
10
|
|
21
11
|
|
22
12
|
class Scene:
|
batFramework/sceneManager.py
CHANGED
@@ -73,15 +73,15 @@ class SceneManager:
|
|
73
73
|
self.set_scene(dest_scene_name)
|
74
74
|
|
75
75
|
def set_scene(self, name, index=0):
|
76
|
+
target_scene = self.get_scene(name)
|
76
77
|
if (
|
77
78
|
len(self._scenes) == 0
|
78
|
-
or not
|
79
|
+
or not target_scene
|
79
80
|
or index >= len(self._scenes)
|
81
|
+
or index < 0
|
80
82
|
):
|
81
83
|
return
|
82
84
|
|
83
|
-
target_scene = self.get_scene(name)
|
84
|
-
if not target_scene : return
|
85
85
|
old_scene = self._scenes[index]
|
86
86
|
# switch
|
87
87
|
old_scene.on_exit()
|
@@ -99,7 +99,6 @@ class SceneManager:
|
|
99
99
|
):
|
100
100
|
self._debugging = (self._debugging + 1) % 4
|
101
101
|
self.set_sharedVar("debugging_mode",self._debugging)
|
102
|
-
|
103
102
|
return
|
104
103
|
if (
|
105
104
|
keys[pygame.K_LCTRL]
|
batFramework/time.py
CHANGED
@@ -1,90 +1,85 @@
|
|
1
1
|
import pygame
|
2
2
|
import batFramework as bf
|
3
|
-
|
3
|
+
from typing import Self
|
4
4
|
|
5
5
|
class Timer:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
name=None,
|
11
|
-
duration=1000,
|
12
|
-
loop=False,
|
13
|
-
end_callback=None,
|
14
|
-
reusable: bool = False,
|
15
|
-
):
|
16
|
-
# Initialize timer properties
|
17
|
-
self.start_time = None
|
18
|
-
self.stopped = True
|
19
|
-
self.name = name if name is not None else self._highest_count
|
20
|
-
Timer._highest_count += 1
|
21
|
-
self.duration = duration
|
22
|
-
self.loop = loop
|
23
|
-
self.elapsed_progress = 0.0
|
6
|
+
_count :int = 0
|
7
|
+
def __init__(self,duration:int,end_callback,loop:bool=False)->None:
|
8
|
+
self.name = Timer._count
|
9
|
+
Timer._count+=1
|
24
10
|
self.end_callback = end_callback
|
25
|
-
self.
|
11
|
+
self.duration : int = duration
|
12
|
+
self.paused : bool = False
|
13
|
+
self.elapsed_time : int = -1
|
14
|
+
self.over : bool = False
|
15
|
+
self.do_delete:bool = False
|
16
|
+
self.is_looping :bool = loop
|
26
17
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
self.
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
# Timer has completed
|
45
|
-
self.end()
|
46
|
-
return True
|
47
|
-
elif self.loop:
|
48
|
-
# If looping, restart the timer
|
49
|
-
self.start()
|
50
|
-
return False
|
51
|
-
|
52
|
-
def stop(self):
|
53
|
-
# Stop the timer
|
54
|
-
self.stopped = True
|
18
|
+
def stop(self)->Self:
|
19
|
+
self.elapsed_time =-1
|
20
|
+
self.over = False
|
21
|
+
self.paused = False
|
22
|
+
return self
|
23
|
+
|
24
|
+
def start(self)->Self:
|
25
|
+
if self.elapsed_time >= 0 : return self
|
26
|
+
self.elapsed_time = 0
|
27
|
+
self.paused = False
|
28
|
+
self.over = False
|
29
|
+
bf.TimeManager().add_timer(self)
|
30
|
+
return self
|
31
|
+
|
32
|
+
def pause(self)->Self:
|
33
|
+
self.paused = True
|
34
|
+
return self
|
55
35
|
|
36
|
+
def resume(self)->Self:
|
37
|
+
self.paused = False
|
38
|
+
return self
|
39
|
+
def delete(self)->Self:
|
40
|
+
self.do_delete = True
|
41
|
+
return self
|
42
|
+
def get_progression(self)->float:
|
43
|
+
if self.elapsed_time < 0 : return 0
|
44
|
+
if self.elapsed_time >= self.duration: return 1
|
45
|
+
return self.elapsed_time / self.duration
|
46
|
+
|
47
|
+
def update(self,dt)->None:
|
48
|
+
if self.elapsed_time < 0 or self.paused: return
|
49
|
+
self.elapsed_time += dt
|
50
|
+
# print("update :",self.elapsed_time,self.duration)
|
51
|
+
if self.get_progression() == 1:
|
52
|
+
self.end()
|
53
|
+
|
56
54
|
def end(self):
|
57
|
-
|
58
|
-
self.
|
59
|
-
if self.
|
60
|
-
self.
|
55
|
+
print("END")
|
56
|
+
self.end_callback()
|
57
|
+
if self.is_looping:
|
58
|
+
self.elapsed_time = -1
|
59
|
+
self.start()
|
60
|
+
return
|
61
|
+
|
62
|
+
self.over = True
|
61
63
|
|
62
|
-
def
|
63
|
-
|
64
|
-
return False
|
65
|
-
return (
|
66
|
-
(not self.loop)
|
67
|
-
and (self.elapsed_progress >= 1)
|
68
|
-
and (not self.stopped)
|
69
|
-
and not self.reusable
|
70
|
-
)
|
64
|
+
def has_ended(self)->bool:
|
65
|
+
return self.over or self.do_delete
|
71
66
|
|
72
67
|
|
73
68
|
class TimeManager(metaclass=bf.Singleton):
|
74
69
|
def __init__(self):
|
75
|
-
# Initialize the
|
70
|
+
# Initialize the TimeManager class with a dictionary of timers
|
76
71
|
self.timers = {}
|
77
72
|
|
78
73
|
def add_timer(self, timer):
|
79
74
|
# Add a timer to the dictionary
|
80
75
|
self.timers[timer.name] = timer
|
81
76
|
|
82
|
-
def update(self):
|
77
|
+
def update(self,dt):
|
83
78
|
# Update all timers and remove completed ones
|
84
79
|
for timer in list(self.timers.values()):
|
85
|
-
timer.update()
|
80
|
+
timer.update(dt)
|
86
81
|
|
87
|
-
to_remove = [name for name, timer in self.timers.items() if timer.
|
82
|
+
to_remove = [name for name, timer in self.timers.items() if timer.has_ended()]
|
88
83
|
|
89
84
|
for name in to_remove:
|
90
85
|
# print(self.timers.pop(name).name,"removed !")
|
@@ -1,13 +1,13 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: batframework
|
3
|
-
Version: 1.0.
|
3
|
+
Version: 1.0.1
|
4
4
|
Summary: Pygame framework for making games easier.
|
5
5
|
Author-email: Turan Baturay <baturayturan@gmail.com>
|
6
6
|
Project-URL: Homepage, https://github.com/TuranBaturay/batFramework
|
7
7
|
Classifier: Programming Language :: Python :: 3
|
8
8
|
Classifier: License :: OSI Approved :: MIT License
|
9
9
|
Classifier: Operating System :: OS Independent
|
10
|
-
Requires-Python: >=3.
|
10
|
+
Requires-Python: >=3.11
|
11
11
|
Description-Content-Type: text/markdown
|
12
12
|
License-File: LICENCE
|
13
13
|
Requires-Dist: pygame-ce
|
@@ -1,4 +1,4 @@
|
|
1
|
-
batFramework/__init__.py,sha256=
|
1
|
+
batFramework/__init__.py,sha256=_lW-sW7cIGz_QK96RK8852RCLQZHwgjV2BQwQCHEmwE,2147
|
2
2
|
batFramework/action.py,sha256=6XQ3sBylO00UYrGfh5GKjwP9PqgtixIV0um4uwiFj4w,8364
|
3
3
|
batFramework/actionContainer.py,sha256=DMWDWZ9mff70VErtunX7yOfiqOxBuGNGfO9b1YXW1CI,2498
|
4
4
|
batFramework/animatedSprite.py,sha256=2OrYT4aAyhzWMbQuIej_P74FJ9D7nWSKTkLf6DK3zCs,4184
|
@@ -8,41 +8,41 @@ batFramework/constants.py,sha256=VbUoeyG00Coz5BxiWrTsO6d0G96Y6Q5CU24E3z5wRR0,142
|
|
8
8
|
batFramework/cutscene.py,sha256=MSKDbP41F7bWMzzNe_U3xWQupvhqPhIiEWFjmh-dwsk,3636
|
9
9
|
batFramework/cutsceneBlocks.py,sha256=12i9Ln1y7HK6fv4uBm7ZqjvU76u9E5I-5GCB_mceEO0,5138
|
10
10
|
batFramework/dynamicEntity.py,sha256=3-3l58WPO1y6ifncrqkuHOEvNlUaR3YDTYvjTD_2L1I,675
|
11
|
-
batFramework/easing.py,sha256=
|
12
|
-
batFramework/entity.py,sha256=
|
11
|
+
batFramework/easing.py,sha256=M5YjDot_l6DVdotKAbShIQlfotrs_WLpnLqQgQdAfa8,2269
|
12
|
+
batFramework/entity.py,sha256=iuWIFoWW5fVByGiY7AUQ-qVymxJLldJMXIKeD4CF4_M,4200
|
13
13
|
batFramework/enums.py,sha256=b7d4TuEyG6WGoXn0ABrmc6VsrwKrkJ2bCrMXtz37DB0,226
|
14
14
|
batFramework/fontManager.py,sha256=zqevsjZR37EalyHIiaGvnppQfWdCSEWbKLT4da0gYaQ,2136
|
15
|
-
batFramework/manager.py,sha256=
|
15
|
+
batFramework/manager.py,sha256=vcIpitF4to03NzxXcoWYvWcn5aQG0feC0L0EKamPGfE,1869
|
16
16
|
batFramework/particles.py,sha256=pdH9LFfOyDE59DpwHj6KWOj063NfeolzInq2Rj0fctI,2592
|
17
17
|
batFramework/resourceManager.py,sha256=Du_MQulBhBJEJ2rFE9YarrKgHjV5DTFSAsc7XofC0Lk,1902
|
18
|
-
batFramework/scene.py,sha256=
|
19
|
-
batFramework/sceneManager.py,sha256=
|
18
|
+
batFramework/scene.py,sha256=jl41bMYeJ4MgpsSxJ5B7tDTD81KRiwXSUwvbr2ivwyc,10109
|
19
|
+
batFramework/sceneManager.py,sha256=Nsz_r3TzCR90DNMhDU_LYrzF3_KsZ9TF6QGJiuVP_UI,3830
|
20
20
|
batFramework/sprite.py,sha256=OrWiWN8C7ewQg4Bk5ZN8YR0u-swJXPhlTeQaOgc7eE0,1067
|
21
21
|
batFramework/stateMachine.py,sha256=er7WB7I4V81jgUrd-9ftfyYczKpPsEbgdWRXzYl6e9k,1339
|
22
22
|
batFramework/tileset.py,sha256=SI2feJV4pnk81ENUJqGsVeD7YheD565UeyVcXQhRq6w,2485
|
23
|
-
batFramework/time.py,sha256=
|
23
|
+
batFramework/time.py,sha256=bhDJt44IbiAuZyov3Wnj5RFv2xkVVjTuCuE7LyFKoYk,2472
|
24
24
|
batFramework/transition.py,sha256=X6pzP2UhDyXQvcsccvnYOuErZdo55P5xNyYYuxZLtvo,4970
|
25
25
|
batFramework/transitionManager.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
26
26
|
batFramework/triggerZone.py,sha256=ikOOlJT1KIND0MO2xiilCHuKlb1eQhkCMEhZTi1btsI,586
|
27
27
|
batFramework/utils.py,sha256=EVIl1jMKER9L0nR9Nv9MLxeyREUC-JGf7mvmSqYuwCA,1664
|
28
28
|
batFramework/gui/__init__.py,sha256=RT9S65ZKtVMsaLYyrqhkWrSaKvNS5PkvQERgtZNA3q4,391
|
29
|
-
batFramework/gui/button.py,sha256=
|
30
|
-
batFramework/gui/constraints.py,sha256=
|
31
|
-
batFramework/gui/container.py,sha256=
|
32
|
-
batFramework/gui/debugger.py,sha256=
|
33
|
-
batFramework/gui/frame.py,sha256=
|
29
|
+
batFramework/gui/button.py,sha256=p3sfKaPuhve9MYZq7V5ZXQEwfGEPcA0ymbqWnYvdZdM,4389
|
30
|
+
batFramework/gui/constraints.py,sha256=XtZIMuauyQ-QOjKGa6JaZfM9qushkcYrG4RKJJVLk8Q,9899
|
31
|
+
batFramework/gui/container.py,sha256=qG8Db7H9P4HHRELHtS_bnBTsTh89BWs8PnIqEGBO0D4,1755
|
32
|
+
batFramework/gui/debugger.py,sha256=lSfoc5PoxEtz6yQRiEZ7-Y9nd3QQeOcqDdth10voIRs,3035
|
33
|
+
batFramework/gui/frame.py,sha256=kY2Jmt1YpYTg4Aa28qmLQaI59BQ-_nq0FOB7Lf2e_hM,861
|
34
34
|
batFramework/gui/image.py,sha256=77sISSe6N5bQa3DLLLPfDcz_55xnXsyyTRtqVKIVFnI,1318
|
35
35
|
batFramework/gui/indicator.py,sha256=awVhrY1holODuAnChfU1_m6Lp7aLGspSTFdHUnVZo2I,1128
|
36
36
|
batFramework/gui/interactiveWidget.py,sha256=jZQspLvlySch5rrZcPi4DsDTpFkDU-qnjqDGy2xX68U,640
|
37
|
-
batFramework/gui/label.py,sha256=
|
38
|
-
batFramework/gui/layout.py,sha256=
|
37
|
+
batFramework/gui/label.py,sha256=q7wNgSSQB7qYVqu7fJNs7x0LoAoc3UhMff__WluwEDs,4918
|
38
|
+
batFramework/gui/layout.py,sha256=w1BypRnYzwA4dtcFK4NtUirVnYoBUJsxApliHCXzQmk,3290
|
39
39
|
batFramework/gui/root.py,sha256=-NYt8YppPYc359qXieKuw7PiUziLLQbWQH-Y61wtJew,2239
|
40
40
|
batFramework/gui/shape.py,sha256=sEuaRjpCRQHj_GomqWtXlHQMyCDw3ZuZsJ6-bAkqJPY,2459
|
41
41
|
batFramework/gui/slider.py,sha256=8rLHN-4yxavrOsTQi79SguCAR9Er8qCmkWKjUdMnPYg,62
|
42
42
|
batFramework/gui/toggle.py,sha256=dXTIJ8u46xTcEsKchPgvKL9yY7Yxul6mVn3u5yb4pHU,2112
|
43
|
-
batFramework/gui/widget.py,sha256=
|
44
|
-
batframework-1.0.
|
45
|
-
batframework-1.0.
|
46
|
-
batframework-1.0.
|
47
|
-
batframework-1.0.
|
48
|
-
batframework-1.0.
|
43
|
+
batFramework/gui/widget.py,sha256=ZnLdsaQGEN9yCDNTVvWPHsdjgdh-XxivSSvb_VPRpCI,11618
|
44
|
+
batframework-1.0.1.dist-info/LICENCE,sha256=A65iXbMDbOxQLDNOODJLqA7o5RxszYlEqIgNSzBQRf4,1073
|
45
|
+
batframework-1.0.1.dist-info/METADATA,sha256=BKI9yycx-8xTwNUlx9JBHtbioGJui70x2lCqamiHOKs,2499
|
46
|
+
batframework-1.0.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
47
|
+
batframework-1.0.1.dist-info/top_level.txt,sha256=vxAKBIk1oparFTxeXGBrgfIO7iq_YR5Fv1JvPVAIwmA,13
|
48
|
+
batframework-1.0.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|