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