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.
Files changed (51) hide show
  1. batFramework/__init__.py +47 -41
  2. batFramework/action.py +20 -42
  3. batFramework/actionContainer.py +4 -43
  4. batFramework/animatedSprite.py +65 -98
  5. batFramework/audioManager.py +25 -39
  6. batFramework/camera.py +56 -226
  7. batFramework/constants.py +48 -32
  8. batFramework/cutscene.py +24 -32
  9. batFramework/cutsceneBlocks.py +33 -30
  10. batFramework/debugger.py +48 -0
  11. batFramework/dynamicEntity.py +7 -8
  12. batFramework/easing.py +23 -28
  13. batFramework/entity.py +52 -89
  14. batFramework/gui/__init__.py +1 -3
  15. batFramework/gui/button.py +58 -124
  16. batFramework/gui/constraints.py +90 -163
  17. batFramework/gui/container.py +18 -29
  18. batFramework/gui/debugger.py +42 -106
  19. batFramework/gui/frame.py +9 -15
  20. batFramework/gui/image.py +17 -36
  21. batFramework/gui/indicator.py +14 -20
  22. batFramework/gui/interactiveWidget.py +12 -63
  23. batFramework/gui/label.py +50 -113
  24. batFramework/gui/layout.py +51 -66
  25. batFramework/gui/root.py +29 -70
  26. batFramework/gui/shape.py +41 -34
  27. batFramework/gui/toggle.py +29 -37
  28. batFramework/gui/widget.py +131 -174
  29. batFramework/manager.py +14 -21
  30. batFramework/particles.py +20 -41
  31. batFramework/scene.py +72 -173
  32. batFramework/sceneManager.py +80 -40
  33. batFramework/stateMachine.py +0 -1
  34. batFramework/time.py +51 -62
  35. batFramework/transition.py +154 -0
  36. batFramework/utils.py +150 -3
  37. batframework-1.0.8a2.dist-info/METADATA +58 -0
  38. batframework-1.0.8a2.dist-info/RECORD +42 -0
  39. {batframework-1.0.7.dist-info → batframework-1.0.8a2.dist-info}/WHEEL +1 -1
  40. batFramework/enums.py +0 -14
  41. batFramework/fontManager.py +0 -57
  42. batFramework/gui/dialogueBox.py +0 -70
  43. batFramework/gui/slider.py +0 -5
  44. batFramework/gui/textInput.py +0 -88
  45. batFramework/resourceManager.py +0 -72
  46. batFramework/sprite.py +0 -33
  47. batFramework/tileset.py +0 -64
  48. batframework-1.0.7.dist-info/LICENCE +0 -21
  49. batframework-1.0.7.dist-info/METADATA +0 -55
  50. batframework-1.0.7.dist-info/RECORD +0 -50
  51. {batframework-1.0.7.dist-info → batframework-1.0.8a2.dist-info}/top_level.txt +0 -0
@@ -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, name="Constraint", priority=0):
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: Widget, child_widget: Widget) -> bool:
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: Widget, child_widget: Widget = None) -> bool:
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: Widget, child_widget: 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, child_widget.rect.h)
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, 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
-
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, 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
-
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, parent_widget, child_widget):
77
- if not self.evaluate(parent_widget, child_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, percentage: float, keep_autoresize: bool = True):
91
+ def __init__(self,percentage:float,keep_autoresize:bool=True):
83
92
  super().__init__(name="percentage_width")
84
- self.percentage: float = percentage
93
+ self.percentage:float = percentage
85
94
  self.keep_autoresize: bool = keep_autoresize
86
-
87
- def to_string(self) -> str:
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, parent_widget, child_widget):
96
- if not self.evaluate(parent_widget, child_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
- f"Warning: Constraint on {child_widget.to_string()} can't resize, autoresize set to True"
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, 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(
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, parent_widget, child_widget):
125
- if not self.evaluate(parent_widget, child_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
- f"Warning: Constraint on {child_widget.to_string()} can't resize, autoresize set to True"
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, height: float, keep_autoresize: bool = True):
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) -> str:
148
- return f"{super().to_string()}.(height={self.height})"
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, 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
-
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, width: float, keep_autoresize: bool = True):
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) -> str:
174
- return f"{super().to_string()}.(width={self.width})"
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, 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)
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, ratio: int | float = 1):
164
+ def __init__(self,ratio:int|float=1):
193
165
  super().__init__(name="aspect_ratio")
194
- if isinstance(ratio, float | int):
166
+ if isinstance(ratio, float|int):
195
167
  self.ratio = ratio
196
- elif isinstance(ratio, Widget):
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
- 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
-
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, 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):
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, 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
- )
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
- )
@@ -1,60 +1,49 @@
1
1
  import batFramework as bf
2
2
  from .widget import Widget
3
- from .layout import Layout,Column
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: Layout = Column(), *children: Widget)->None:
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: Layout = 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 set_padding(self,value)->Self:
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, self.debug_color)
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) -> None:
27
+ def clear_children(self)->None:
32
28
  self.children.clear()
33
29
  self.apply_constraints()
34
30
 
35
- def add_child(self, *child: Widget) -> None:
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, child: Widget) -> None:
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) -> None:
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) -> None:
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 children_modified(self)->None:
59
- self.apply_all_constraints()
60
- super().children_modified()
47
+ def to_string_id(self)->str:
48
+ return f"Container({len(self.children)},{[c.to_string() for c in self.constraints]})"
49
+
@@ -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
- def __init__(self) -> None:
12
- super().__init__("")
13
- self.static_data: dict = {}
14
- self.dynamic_data: dict = {}
15
- self.refresh_rate = 10
16
- self.refresh_counter : float = 0
17
- self.render_order = 99
18
- self.set_uid("debugger")
19
-
20
- def get_bounding_box(self):
21
- yield None
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_static(self, key: str, data):
30
- self.static_data[key] = str(data)
31
- self.update_text()
32
-
33
- def add_dynamic(self, key: str, func) -> None:
34
- self.dynamic_data[key] = func
35
- self.update_text()
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, width: float, height: float,fit_to_children:bool=True):
8
- self.fit_to_children = fit_to_children
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
- def to_string_id(self) -> str:
10
+
11
+ def to_string_id(self)->str:
12
12
  return "Frame"
13
13
 
14
- def _fit_to_children(self)->None:
15
- # TODO CLEAN THIS UP
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:
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()