batframework 1.0.7__py3-none-any.whl → 1.0.8a2__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 +47 -41
- batFramework/action.py +20 -42
- batFramework/actionContainer.py +4 -43
- batFramework/animatedSprite.py +65 -98
- batFramework/audioManager.py +25 -39
- batFramework/camera.py +56 -226
- batFramework/constants.py +48 -32
- batFramework/cutscene.py +24 -32
- batFramework/cutsceneBlocks.py +33 -30
- batFramework/debugger.py +48 -0
- batFramework/dynamicEntity.py +7 -8
- batFramework/easing.py +23 -28
- batFramework/entity.py +52 -89
- batFramework/gui/__init__.py +1 -3
- batFramework/gui/button.py +58 -124
- batFramework/gui/constraints.py +90 -163
- batFramework/gui/container.py +18 -29
- batFramework/gui/debugger.py +42 -106
- batFramework/gui/frame.py +9 -15
- batFramework/gui/image.py +17 -36
- batFramework/gui/indicator.py +14 -20
- batFramework/gui/interactiveWidget.py +12 -63
- batFramework/gui/label.py +50 -113
- batFramework/gui/layout.py +51 -66
- batFramework/gui/root.py +29 -70
- batFramework/gui/shape.py +41 -34
- batFramework/gui/toggle.py +29 -37
- batFramework/gui/widget.py +131 -174
- batFramework/manager.py +14 -21
- batFramework/particles.py +20 -41
- batFramework/scene.py +72 -173
- batFramework/sceneManager.py +80 -40
- batFramework/stateMachine.py +0 -1
- batFramework/time.py +51 -62
- batFramework/transition.py +154 -0
- batFramework/utils.py +150 -3
- batframework-1.0.8a2.dist-info/METADATA +58 -0
- batframework-1.0.8a2.dist-info/RECORD +42 -0
- {batframework-1.0.7.dist-info → batframework-1.0.8a2.dist-info}/WHEEL +1 -1
- batFramework/enums.py +0 -14
- batFramework/fontManager.py +0 -57
- batFramework/gui/dialogueBox.py +0 -70
- batFramework/gui/slider.py +0 -5
- batFramework/gui/textInput.py +0 -88
- batFramework/resourceManager.py +0 -72
- batFramework/sprite.py +0 -33
- batFramework/tileset.py +0 -64
- batframework-1.0.7.dist-info/LICENCE +0 -21
- batframework-1.0.7.dist-info/METADATA +0 -55
- batframework-1.0.7.dist-info/RECORD +0 -50
- {batframework-1.0.7.dist-info → batframework-1.0.8a2.dist-info}/top_level.txt +0 -0
batFramework/gui/constraints.py
CHANGED
@@ -1,30 +1,44 @@
|
|
1
1
|
from .widget import Widget
|
2
2
|
import batFramework as bf
|
3
3
|
|
4
|
+
|
4
5
|
class Constraint:
|
5
|
-
def __init__(self,
|
6
|
+
def __init__(self,name="Constraint", priority=0):
|
6
7
|
self.priority = priority
|
7
8
|
self.name = name
|
8
|
-
|
9
|
-
def set_priority(self, priority) -> "Constraint":
|
9
|
+
def set_priority(self, priority)->"Constraint":
|
10
10
|
self.priority = priority
|
11
11
|
return self
|
12
|
-
|
13
|
-
def to_string(self) -> str:
|
12
|
+
def to_string(self)->str:
|
14
13
|
return f"{self.name.upper()}"
|
15
|
-
|
16
|
-
def evaluate(self, parent_widget:
|
14
|
+
|
15
|
+
def evaluate(self, parent_widget:Widget, child_widget:Widget) -> bool:
|
17
16
|
raise NotImplementedError("Subclasses must implement evaluate method")
|
18
17
|
|
19
|
-
def apply(self, parent_widget:
|
18
|
+
def apply(self, parent_widget:Widget, child_widget:Widget=None) -> bool:
|
20
19
|
if not self.evaluate(parent_widget, child_widget):
|
21
20
|
self.apply_constraint(parent_widget, child_widget)
|
22
21
|
return False
|
23
22
|
return True
|
24
|
-
|
25
|
-
def apply_constraint(self, parent_widget:
|
23
|
+
|
24
|
+
def apply_constraint(self, parent_widget:Widget, child_widget:Widget):
|
26
25
|
raise NotImplementedError("Subclasses must implement apply_constraint method")
|
27
26
|
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
28
42
|
class ConstraintMinWidth(Constraint):
|
29
43
|
def __init__(self, width):
|
30
44
|
super().__init__(name="min_width")
|
@@ -35,9 +49,11 @@ class ConstraintMinWidth(Constraint):
|
|
35
49
|
|
36
50
|
def apply_constraint(self, parent_widget, child_widget):
|
37
51
|
if not self.evaluate(parent_widget, child_widget):
|
38
|
-
child_widget.set_size(self.min_width,
|
52
|
+
child_widget.set_size(self.min_width,child_widget.rect.h)
|
39
53
|
|
40
54
|
|
55
|
+
|
56
|
+
|
41
57
|
class ConstraintCenterX(Constraint):
|
42
58
|
def __init__(self):
|
43
59
|
super().__init__(name="centerx")
|
@@ -45,12 +61,9 @@ class ConstraintCenterX(Constraint):
|
|
45
61
|
def evaluate(self, parent_widget, child_widget):
|
46
62
|
return child_widget.rect.centerx == parent_widget.get_content_center()[0]
|
47
63
|
|
48
|
-
def apply_constraint(self,
|
49
|
-
if not self.evaluate(parent_widget,
|
50
|
-
child_widget.set_center(
|
51
|
-
parent_widget.get_content_center()[0], child_widget.rect.centery
|
52
|
-
)
|
53
|
-
|
64
|
+
def apply_constraint(self,parent_widget,child_widget):
|
65
|
+
if not self.evaluate(parent_widget,child_widget):
|
66
|
+
child_widget.set_center(parent_widget.get_content_center()[0],child_widget.rect.centery)
|
54
67
|
|
55
68
|
class ConstraintCenterY(Constraint):
|
56
69
|
def __init__(self):
|
@@ -59,12 +72,9 @@ class ConstraintCenterY(Constraint):
|
|
59
72
|
def evaluate(self, parent_widget, child_widget):
|
60
73
|
return child_widget.rect.centery == parent_widget.get_content_center()[1]
|
61
74
|
|
62
|
-
def apply_constraint(self,
|
63
|
-
if not self.evaluate(parent_widget,
|
64
|
-
child_widget.set_center(
|
65
|
-
child_widget.rect.centerx, parent_widget.get_content_center()[1]
|
66
|
-
)
|
67
|
-
|
75
|
+
def apply_constraint(self,parent_widget,child_widget):
|
76
|
+
if not self.evaluate(parent_widget,child_widget):
|
77
|
+
child_widget.set_center(child_widget.rect.centerx,parent_widget.get_content_center()[1])
|
68
78
|
|
69
79
|
class ConstraintCenter(Constraint):
|
70
80
|
def __init__(self):
|
@@ -73,205 +83,122 @@ class ConstraintCenter(Constraint):
|
|
73
83
|
def evaluate(self, parent_widget, child_widget):
|
74
84
|
return child_widget.rect.center == parent_widget.get_content_center()
|
75
85
|
|
76
|
-
def apply_constraint(self,
|
77
|
-
if not self.evaluate(parent_widget,
|
86
|
+
def apply_constraint(self,parent_widget,child_widget):
|
87
|
+
if not self.evaluate(parent_widget,child_widget):
|
78
88
|
child_widget.set_center(*parent_widget.get_content_center())
|
79
89
|
|
80
|
-
|
81
90
|
class ConstraintPercentageWidth(Constraint):
|
82
|
-
def __init__(self,
|
91
|
+
def __init__(self,percentage:float,keep_autoresize:bool=True):
|
83
92
|
super().__init__(name="percentage_width")
|
84
|
-
self.percentage:
|
93
|
+
self.percentage:float = percentage
|
85
94
|
self.keep_autoresize: bool = keep_autoresize
|
86
|
-
|
87
|
-
|
88
|
-
return f"{super().to_string()}.[{self.percentage*100}%,keep_autoresize={self.keep_autoresize}]"
|
89
|
-
|
95
|
+
def to_string(self)->str:
|
96
|
+
return f"{super().to_string()}.[{self.percentage},{self.keep_autoresize}]"
|
90
97
|
def evaluate(self, parent_widget, child_widget):
|
91
|
-
return child_widget.rect.width == round(
|
92
|
-
parent_widget.get_content_width() * self.percentage
|
93
|
-
)
|
98
|
+
return child_widget.rect.width == round(parent_widget.get_content_width() * self.percentage)
|
94
99
|
|
95
|
-
def apply_constraint(self,
|
96
|
-
if not self.evaluate(parent_widget,
|
100
|
+
def apply_constraint(self,parent_widget,child_widget):
|
101
|
+
if not self.evaluate(parent_widget,child_widget):
|
97
102
|
if child_widget.autoresize:
|
98
103
|
if self.keep_autoresize:
|
99
|
-
print(
|
100
|
-
|
101
|
-
)
|
102
|
-
return
|
104
|
+
print(f"Warning: Constraint on {child_widget.to_string()} can't resize, autoresize set to True")
|
105
|
+
return
|
103
106
|
child_widget.set_autoresize(False)
|
104
|
-
child_widget.set_size(
|
105
|
-
round(parent_widget.get_content_width() * self.percentage),
|
106
|
-
child_widget.rect.h,
|
107
|
-
)
|
107
|
+
child_widget.set_size(round(parent_widget.get_content_width() * self.percentage) ,child_widget.rect.h)
|
108
108
|
|
109
109
|
|
110
110
|
class ConstraintPercentageHeight(Constraint):
|
111
|
-
def __init__(self,
|
111
|
+
def __init__(self,percentage:float,keep_autoresize:bool=True):
|
112
112
|
super().__init__(name="percentage_height")
|
113
|
-
self.percentage:
|
113
|
+
self.percentage:float = percentage
|
114
114
|
self.keep_autoresize: bool = keep_autoresize
|
115
115
|
|
116
116
|
def evaluate(self, parent_widget, child_widget):
|
117
|
-
return child_widget.rect.height == round(
|
118
|
-
parent_widget.get_content_height() * self.percentage
|
119
|
-
)
|
120
|
-
|
121
|
-
def to_string(self) -> str:
|
122
|
-
return f"{super().to_string()}.[{self.percentage*100}%,keep_autoresize={self.keep_autoresize}]"
|
117
|
+
return child_widget.rect.height == round(parent_widget.get_content_height() * self.percentage)
|
123
118
|
|
124
|
-
def apply_constraint(self,
|
125
|
-
if not self.evaluate(parent_widget,
|
119
|
+
def apply_constraint(self,parent_widget,child_widget):
|
120
|
+
if not self.evaluate(parent_widget,child_widget):
|
126
121
|
if child_widget.autoresize:
|
127
122
|
if self.keep_autoresize:
|
128
|
-
print(
|
129
|
-
|
130
|
-
)
|
131
|
-
return
|
123
|
+
print(f"Warning: Constraint on {child_widget.to_string()} can't resize, autoresize set to True")
|
124
|
+
return
|
132
125
|
child_widget.set_autoresize(False)
|
133
|
-
child_widget.set_size(
|
134
|
-
child_widget.rect.w,
|
135
|
-
round(parent_widget.get_content_height() * self.percentage),
|
136
|
-
)
|
137
|
-
|
126
|
+
child_widget.set_size(child_widget.rect.w,round(parent_widget.get_content_height() * self.percentage))
|
138
127
|
|
139
128
|
class ConstraintHeight(Constraint):
|
140
|
-
def __init__(self,
|
141
|
-
if height < 0:
|
129
|
+
def __init__(self,height:float):
|
130
|
+
if height < 0 :
|
142
131
|
raise ValueError("height can't be negative")
|
143
132
|
super().__init__(name="height")
|
144
133
|
self.height = height
|
145
|
-
self.keep_autoresize:bool = keep_autoresize
|
146
134
|
|
147
|
-
def to_string(self)
|
148
|
-
return f"{super().to_string()}.(
|
135
|
+
def to_string(self)->str:
|
136
|
+
return f"{super().to_string()}.({self.height})"
|
149
137
|
|
150
138
|
def evaluate(self, parent_widget, child_widget):
|
151
139
|
return child_widget.rect.height == self.height
|
152
140
|
|
153
|
-
def apply_constraint(self,
|
154
|
-
if not self.evaluate(parent_widget,
|
155
|
-
|
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)
|
162
|
-
child_widget.set_size(child_widget.rect.w, self.height)
|
163
|
-
|
141
|
+
def apply_constraint(self,parent_widget,child_widget):
|
142
|
+
if not self.evaluate(parent_widget,child_widget):
|
143
|
+
child_widget.set_size(child_widget.rect.w,self.height)
|
164
144
|
|
165
145
|
class ConstraintWidth(Constraint):
|
166
|
-
def __init__(self,
|
167
|
-
if width < 0:
|
146
|
+
def __init__(self,width:float):
|
147
|
+
if width < 0 :
|
168
148
|
raise ValueError("width can't be negative")
|
169
149
|
super().__init__(name="width")
|
170
150
|
self.width = width
|
171
|
-
self.keep_autoresize : bool = keep_autoresize
|
172
151
|
|
173
|
-
def to_string(self)
|
174
|
-
return f"{super().to_string()}.(
|
152
|
+
def to_string(self)->str:
|
153
|
+
return f"{super().to_string()}.({self.width})"
|
175
154
|
|
176
155
|
def evaluate(self, parent_widget, child_widget):
|
177
156
|
return child_widget.rect.width == self.width
|
178
157
|
|
179
|
-
def apply_constraint(self,
|
180
|
-
if not self.evaluate(parent_widget,
|
181
|
-
|
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)
|
188
|
-
child_widget.set_size(self.width, child_widget.rect.h)
|
158
|
+
def apply_constraint(self,parent_widget,child_widget):
|
159
|
+
if not self.evaluate(parent_widget,child_widget):
|
160
|
+
child_widget.set_size(self.width,child_widget.rect.h)
|
189
161
|
|
190
162
|
|
191
163
|
class ConstraintAspectRatio(Constraint):
|
192
|
-
def __init__(self,
|
164
|
+
def __init__(self,ratio:int|float=1):
|
193
165
|
super().__init__(name="aspect_ratio")
|
194
|
-
if isinstance(ratio, float
|
166
|
+
if isinstance(ratio, float|int):
|
195
167
|
self.ratio = ratio
|
196
|
-
elif isinstance(ratio,
|
168
|
+
elif isinstance(ratio,Widget):
|
197
169
|
self.ratio = ratio.rect.w / ratio.rect.h
|
198
170
|
else:
|
199
171
|
raise TypeError(f"Ratio must be float or Widget")
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
172
|
+
def evaluate(self, parent_widget,child_widget):
|
173
|
+
return self.ratio == child_widget.rect.w / child_widget.rect.h
|
174
|
+
|
175
|
+
def apply_constraint(self,parent_widget,child_widget):
|
176
|
+
if not self.evaluate(parent_widget,child_widget):
|
177
|
+
return # TODO
|
178
|
+
|
209
179
|
class ConstraintAnchorBottom(Constraint):
|
210
180
|
def __init__(self):
|
211
181
|
super().__init__(name="anchor_bottom")
|
212
|
-
|
213
|
-
def evaluate(self, parent_widget,
|
214
|
-
return
|
215
|
-
|
216
|
-
def apply_constraint(self,
|
217
|
-
if not self.evaluate(parent_widget,
|
182
|
+
|
183
|
+
def evaluate(self, parent_widget,child_widget):
|
184
|
+
return child_widget.rect.bottom == parent_widget.rect.bottom
|
185
|
+
|
186
|
+
def apply_constraint(self,parent_widget,child_widget):
|
187
|
+
if not self.evaluate(parent_widget,child_widget):
|
218
188
|
child_widget.set_y(parent_widget.get_content_bottom() - child_widget.rect.h)
|
219
189
|
|
220
190
|
|
221
191
|
class ConstraintAnchorTopRight(Constraint):
|
222
192
|
def __init__(self):
|
223
193
|
super().__init__(name="anchor_topright")
|
224
|
-
|
225
|
-
def evaluate(self, parent_widget,
|
226
|
-
return
|
227
|
-
|
228
|
-
def apply_constraint(self,
|
229
|
-
if not self.evaluate(parent_widget,
|
230
|
-
child_widget.set_position(
|
231
|
-
parent_widget.get_content_right() - child_widget.rect.w,
|
232
|
-
parent_widget.get_content_top(),
|
233
|
-
)
|
234
|
-
|
235
|
-
class ConstraintAnchorBottomRight(Constraint):
|
236
|
-
def __init__(self):
|
237
|
-
super().__init__(name="anchor_bottomright")
|
238
|
-
|
239
|
-
def evaluate(self, parent_widget, child_widget):
|
240
|
-
return child_widget.rect.bottomright == parent_widget.get_content_rect().bottomright
|
241
|
-
|
242
|
-
def apply_constraint(self, parent_widget, child_widget):
|
243
|
-
if not self.evaluate(parent_widget, child_widget):
|
244
|
-
child_widget.set_position(
|
245
|
-
parent_widget.get_content_right() - child_widget.rect.w,
|
246
|
-
parent_widget.get_content_bottom() - child_widget.rect.h,
|
247
|
-
)
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
class ConstraintAnchorRight(Constraint):
|
252
|
-
def __init__(self):
|
253
|
-
super().__init__(name="anchor_right")
|
254
|
-
|
255
|
-
def evaluate(self, parent_widget, child_widget):
|
256
|
-
return child_widget.rect.right == parent_widget.get_content_right()
|
257
|
-
|
258
|
-
def apply_constraint(self, parent_widget, child_widget):
|
259
|
-
if not self.evaluate(parent_widget, child_widget):
|
260
|
-
child_widget.set_position(
|
261
|
-
parent_widget.get_content_right() - child_widget.rect.w,
|
262
|
-
child_widget.rect.top,
|
263
|
-
)
|
194
|
+
|
195
|
+
def evaluate(self, parent_widget,child_widget):
|
196
|
+
return child_widget.rect.topright == parent_widget.rect.topright
|
197
|
+
|
198
|
+
def apply_constraint(self,parent_widget,child_widget):
|
199
|
+
if not self.evaluate(parent_widget,child_widget):
|
200
|
+
child_widget.set_position(parent_widget.get_content_right()-child_widget.rect.w, parent_widget.get_content_top())
|
264
201
|
|
265
202
|
|
266
|
-
class ConstraintAnchorLeft(Constraint):
|
267
|
-
def __init__(self):
|
268
|
-
super().__init__(name="anchor_left")
|
269
203
|
|
270
|
-
def evaluate(self, parent_widget, child_widget):
|
271
|
-
return child_widget.rect.left == parent_widget.get_content_left()
|
272
204
|
|
273
|
-
def apply_constraint(self, parent_widget, child_widget):
|
274
|
-
if not self.evaluate(parent_widget, child_widget):
|
275
|
-
child_widget.set_position(
|
276
|
-
parent_widget.get_content_left(), child_widget.rect.top
|
277
|
-
)
|
batFramework/gui/container.py
CHANGED
@@ -1,60 +1,49 @@
|
|
1
1
|
import batFramework as bf
|
2
2
|
from .widget import Widget
|
3
|
-
from .layout import Layout
|
3
|
+
from .layout import Layout
|
4
4
|
from .constraints import Constraint
|
5
5
|
from typing import Self
|
6
6
|
|
7
7
|
class Container(Widget):
|
8
|
-
def __init__(self, layout:
|
8
|
+
def __init__(self, layout:Layout=None, *children:Widget):
|
9
9
|
super().__init__()
|
10
10
|
self.set_debug_color("green")
|
11
11
|
self.surface = None
|
12
|
-
self.layout:
|
13
|
-
if self.layout:
|
14
|
-
self.layout.set_parent(self)
|
12
|
+
self.layout :Layout = layout
|
13
|
+
if self.layout : self.layout.set_parent(self)
|
15
14
|
for child in children:
|
16
15
|
self.add_child(child)
|
17
16
|
|
18
|
-
def
|
19
|
-
return self
|
20
|
-
|
21
|
-
def set_layout(self, layout: Layout) -> Self:
|
17
|
+
def set_layout(self,layout:Layout)->Self:
|
22
18
|
self.layout = layout
|
23
19
|
self.apply_constraints()
|
24
20
|
return self
|
25
21
|
|
26
22
|
def get_bounding_box(self):
|
27
|
-
yield (self.rect,
|
23
|
+
yield (self.rect,self._debug_color)
|
28
24
|
for child in self.children:
|
29
25
|
yield from child.get_bounding_box()
|
30
26
|
|
31
|
-
def clear_children(self)
|
27
|
+
def clear_children(self)->None:
|
32
28
|
self.children.clear()
|
33
29
|
self.apply_constraints()
|
34
30
|
|
35
|
-
def add_child(self
|
31
|
+
def add_child(self,*child:Widget)->None:
|
36
32
|
super().add_child(*child)
|
37
|
-
if self.layout:
|
38
|
-
self.layout.arrange()
|
33
|
+
if self.layout : self.layout.arrange()
|
39
34
|
|
40
|
-
def remove_child(self,
|
35
|
+
def remove_child(self,child:Widget)->None:
|
41
36
|
super().remove_child(child)
|
42
|
-
if self.layout:
|
43
|
-
self.layout.arrange()
|
37
|
+
if self.layout : self.layout.arrange()
|
44
38
|
|
45
|
-
def build(self)
|
39
|
+
def build(self)->None:
|
46
40
|
super().build()
|
47
|
-
if self.layout:
|
48
|
-
self.layout.arrange()
|
41
|
+
if self.layout : self.layout.arrange()
|
49
42
|
|
50
|
-
def apply_constraints(self)
|
43
|
+
def apply_constraints(self)->None:
|
51
44
|
super().apply_constraints()
|
52
|
-
if self.layout:
|
53
|
-
self.layout.arrange()
|
54
|
-
|
55
|
-
def to_string_id(self) -> str:
|
56
|
-
return f"Container({self.uid},{len(self.children)},{[c.to_string() for c in self.constraints]})"
|
45
|
+
if self.layout : self.layout.arrange()
|
57
46
|
|
58
|
-
def
|
59
|
-
self.
|
60
|
-
|
47
|
+
def to_string_id(self)->str:
|
48
|
+
return f"Container({len(self.children)},{[c.to_string() for c in self.constraints]})"
|
49
|
+
|
batFramework/gui/debugger.py
CHANGED
@@ -1,111 +1,47 @@
|
|
1
1
|
from .label import Label
|
2
2
|
from typing import Self
|
3
|
-
import batFramework as bf
|
4
|
-
import pygame
|
5
|
-
|
6
|
-
|
7
|
-
def convert_to_int(*args):
|
8
|
-
return [int(arg) for arg in args]
|
9
3
|
|
10
4
|
class Debugger(Label):
|
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
|
-
def remove_static(self,key)->bool:
|
38
|
-
try:
|
39
|
-
self.static_data.pop(key)
|
40
|
-
return True
|
41
|
-
except KeyError:
|
42
|
-
return False
|
43
|
-
|
44
|
-
def remove_dynamic(self,key)->bool:
|
45
|
-
try:
|
46
|
-
self.dynamic_data.pop(key)
|
47
|
-
return True
|
48
|
-
except KeyError:
|
49
|
-
return False
|
50
|
-
|
51
|
-
def set_parent_scene(self, scene) -> Self:
|
52
|
-
super().set_parent_scene(scene)
|
53
|
-
self.update_text()
|
54
|
-
return self
|
55
|
-
|
56
|
-
def update_text(self) -> None:
|
57
|
-
if not self.parent_scene:
|
58
|
-
return
|
59
|
-
d = "\n".join(
|
60
|
-
key + ":" + data if key != "" else data
|
61
|
-
for key, data in self.static_data.items()
|
62
|
-
)
|
63
|
-
d2 = "\n".join(
|
64
|
-
key + ":" + str(data()) if key != "" else str(data())
|
65
|
-
for key, data in self.dynamic_data.items()
|
66
|
-
)
|
67
|
-
self.set_text("\n".join((d, d2)).strip())
|
68
|
-
|
69
|
-
def update(self, dt: float) -> None:
|
70
|
-
if not self.parent_scene:
|
71
|
-
return
|
72
|
-
if self.parent_scene.get_sharedVar("debugging_mode") != 1:
|
73
|
-
self.set_visible(False)
|
74
|
-
return
|
75
|
-
self.set_visible(True)
|
76
|
-
self.refresh_counter = self.refresh_counter + (dt * 60)
|
77
|
-
if self.refresh_counter > self.refresh_rate:
|
78
|
-
self.refresh_counter = 0
|
79
|
-
self.update_text()
|
80
|
-
|
81
|
-
|
82
|
-
class BasicDebugger(Debugger):
|
83
|
-
def __init__(self):
|
84
|
-
super().__init__()
|
85
|
-
|
86
|
-
def do_when_added(self):
|
87
|
-
if not self.parent_scene or not self.parent_scene.manager:
|
88
|
-
print("Debugger could not link to the manager")
|
89
|
-
return
|
90
|
-
manager_link = self.parent_scene.manager
|
91
|
-
parent_scene = self.parent_scene
|
92
|
-
self.add_static("Resolution", 'x'.join(str(i) for i in bf.const.RESOLUTION))
|
93
|
-
self.add_dynamic(
|
94
|
-
"FPS", lambda: str(round(manager_link.get_fps()))
|
95
|
-
)
|
96
|
-
self.add_dynamic("Mouse", pygame.mouse.get_pos)
|
97
|
-
self.add_dynamic(
|
98
|
-
"World",
|
99
|
-
lambda: convert_to_int(*parent_scene.camera.convert_screen_to_world(
|
100
|
-
*pygame.mouse.get_pos())
|
101
|
-
),
|
102
|
-
)
|
103
|
-
self.add_dynamic(
|
104
|
-
"Hud",
|
105
|
-
lambda: convert_to_int(*parent_scene.hud_camera.convert_screen_to_world(
|
106
|
-
*pygame.mouse.get_pos())
|
107
|
-
),
|
108
|
-
)
|
109
|
-
self.add_dynamic("W. Ent.",lambda : parent_scene.get_world_entity_count())
|
110
|
-
self.add_dynamic("H. Ent.",lambda : parent_scene.get_hud_entity_count())
|
5
|
+
def __init__(self)->None:
|
6
|
+
super().__init__("")
|
7
|
+
self.static_data : dict = {}
|
8
|
+
self.dynamic_data : dict = {}
|
9
|
+
self.refresh_rate = 10
|
10
|
+
self.refresh_counter = 0
|
11
|
+
self.render_order = 99
|
12
|
+
|
13
|
+
def to_string_id(self)->str:
|
14
|
+
return "Debugger"
|
15
|
+
|
16
|
+
def set_refresh_rate(self, value:int)-> Self:
|
17
|
+
self.refresh_rate = value
|
18
|
+
return self
|
19
|
+
|
20
|
+
def add_data(self,key:str,data):
|
21
|
+
self.static_data[key] = str(data)
|
22
|
+
self.update_text()
|
23
|
+
|
24
|
+
def add_dynamic_data(self,key:str,func)->None:
|
25
|
+
self.dynamic_data[key] = func
|
26
|
+
self.update_text()
|
27
|
+
|
28
|
+
def set_parent_scene(self,scene)->None:
|
29
|
+
super().set_parent_scene(scene)
|
30
|
+
self.update_text()
|
111
31
|
|
32
|
+
def update_text(self)->None:
|
33
|
+
if not self.parent_scene:return
|
34
|
+
d = '\n'.join(key+':'+data if key!='' else data for key,data in self.static_data.items())
|
35
|
+
d2 = '\n'.join(key+':'+str(data()) if key!='' else str(data()) for key,data in self.dynamic_data.items())
|
36
|
+
self.set_text('\n'.join((d,d2)).strip())
|
37
|
+
|
38
|
+
def update(self,dt:float)->None:
|
39
|
+
if not self.parent_scene:return
|
40
|
+
if self.parent_scene.get_sharedVar("is_debugging_func")() != 1:
|
41
|
+
self.set_visible(False)
|
42
|
+
return
|
43
|
+
self.set_visible(True)
|
44
|
+
self.refresh_counter = self.refresh_counter + (dt * 60)
|
45
|
+
if self.refresh_counter > self.refresh_rate:
|
46
|
+
self.refresh_counter = 0
|
47
|
+
self.update_text()
|
batFramework/gui/frame.py
CHANGED
@@ -4,22 +4,16 @@ import pygame
|
|
4
4
|
|
5
5
|
|
6
6
|
class Frame(Shape):
|
7
|
-
def __init__(self,
|
8
|
-
|
9
|
-
super().__init__(width, height)
|
7
|
+
def __init__(self,width:float,height:float):
|
8
|
+
super().__init__(width,height)
|
10
9
|
self.set_debug_color("magenta")
|
11
|
-
|
10
|
+
|
11
|
+
def to_string_id(self)->str:
|
12
12
|
return "Frame"
|
13
13
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
self.rect.center = children_rect.center
|
20
|
-
self.apply_all_constraints()
|
21
|
-
|
22
|
-
def children_modified(self) -> None:
|
14
|
+
def children_modified(self)->None:
|
15
|
+
print(self.children)
|
16
|
+
self.set_size(
|
17
|
+
*self.inflate_rect_by_padding(self.rect.unionall(list(c.rect for c in self.children))).size
|
18
|
+
)
|
23
19
|
super().children_modified()
|
24
|
-
if self.fit_to_children:
|
25
|
-
self._fit_to_children()
|