batframework 1.0.8a1__py3-none-any.whl → 1.0.8a3__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/action.py +30 -14
- batFramework/actionContainer.py +5 -3
- batFramework/audioManager.py +0 -1
- batFramework/camera.py +29 -24
- batFramework/cutscene.py +2 -4
- batFramework/entity.py +9 -2
- batFramework/enums.py +11 -2
- batFramework/fontManager.py +1 -1
- batFramework/gui/__init__.py +3 -1
- batFramework/gui/button.py +5 -2
- batFramework/gui/clickableWidget.py +42 -29
- batFramework/gui/constraints/constraints.py +269 -57
- batFramework/gui/container.py +39 -21
- batFramework/gui/debugger.py +18 -11
- batFramework/gui/dialogueBox.py +20 -17
- batFramework/gui/draggableWidget.py +7 -5
- batFramework/gui/image.py +27 -15
- batFramework/gui/indicator.py +1 -4
- batFramework/gui/interactiveWidget.py +91 -30
- batFramework/gui/label.py +44 -35
- batFramework/gui/layout.py +115 -43
- batFramework/gui/meter.py +3 -8
- batFramework/gui/radioButton.py +47 -25
- batFramework/gui/root.py +50 -25
- batFramework/gui/shape.py +14 -19
- batFramework/gui/slider.py +70 -44
- batFramework/gui/style.py +10 -0
- batFramework/gui/styleManager.py +48 -0
- batFramework/gui/textInput.py +25 -22
- batFramework/gui/toggle.py +42 -29
- batFramework/gui/widget.py +176 -115
- batFramework/object.py +9 -10
- batFramework/renderGroup.py +7 -2
- batFramework/scene.py +70 -49
- batFramework/sceneManager.py +15 -20
- batFramework/scrollingSprite.py +5 -3
- batFramework/sprite.py +20 -14
- batFramework/stateMachine.py +1 -2
- batFramework/tileset.py +5 -5
- batFramework/utils.py +12 -10
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a3.dist-info}/METADATA +1 -1
- batframework-1.0.8a3.dist-info/RECORD +58 -0
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a3.dist-info}/WHEEL +1 -1
- batframework-1.0.8a1.dist-info/RECORD +0 -56
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a3.dist-info}/LICENCE +0 -0
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a3.dist-info}/top_level.txt +0 -0
batFramework/gui/widget.py
CHANGED
@@ -1,89 +1,129 @@
|
|
1
|
-
from typing import TYPE_CHECKING,Self,Callable
|
1
|
+
from typing import TYPE_CHECKING, Self, Callable
|
2
2
|
from collections.abc import Iterable
|
3
3
|
import batFramework as bf
|
4
4
|
import pygame
|
5
|
-
|
5
|
+
|
6
|
+
if TYPE_CHECKING:
|
6
7
|
from .constraints.constraints import Constraint
|
7
8
|
from .root import Root
|
8
9
|
MAX_CONSTRAINTS = 10
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
|
11
|
+
|
12
|
+
class WidgetMeta(type):
|
13
|
+
def __call__(cls, *args, **kwargs):
|
14
|
+
"""Called when you call MyNewClass()"""
|
15
|
+
obj = type.__call__(cls, *args, **kwargs)
|
16
|
+
# obj.new_init()
|
17
|
+
bf.StyleManager().register_widget(obj)
|
18
|
+
return obj
|
19
|
+
|
20
|
+
|
21
|
+
class Widget(bf.Entity, metaclass=WidgetMeta):
|
22
|
+
def __init__(self, *args, **kwargs) -> None:
|
23
|
+
super().__init__(*args, **kwargs)
|
12
24
|
self.children: list["Widget"] = []
|
13
|
-
self.constraints
|
14
|
-
self.parent
|
15
|
-
self.do_sort_children =False
|
16
|
-
self.clip_children
|
17
|
-
self.padding = (0,
|
18
|
-
self.dirty_surface
|
19
|
-
self.dirty_shape
|
20
|
-
|
21
|
-
|
22
|
-
self.
|
25
|
+
self.constraints: list[Constraint] = []
|
26
|
+
self.parent: "Widget" = None
|
27
|
+
self.do_sort_children = False
|
28
|
+
self.clip_children: bool = True
|
29
|
+
self.padding = (0, 0, 0, 0)
|
30
|
+
self.dirty_surface: bool = True # if true will call paint before drawing
|
31
|
+
self.dirty_shape: bool = (
|
32
|
+
True # if true will call (build+paint) before drawing
|
33
|
+
)
|
34
|
+
self.dirty_constraints: bool = False
|
35
|
+
self.is_root: bool = False
|
36
|
+
self.autoresize_w, self.autoresize_h = True, True
|
23
37
|
self.__constraint_iteration = 0
|
24
38
|
|
25
|
-
def
|
39
|
+
def show(self) -> Self:
|
40
|
+
self.visit(lambda w: w.set_visible(True))
|
41
|
+
return self
|
42
|
+
|
43
|
+
def hide(self) -> Self:
|
44
|
+
self.visit(lambda w: w.set_visible(False))
|
45
|
+
return self
|
46
|
+
|
47
|
+
def set_clip_children(self, value: bool) -> Self:
|
26
48
|
self.clip_children = value
|
27
49
|
self.dirty_surface = True
|
28
50
|
return self
|
29
51
|
|
30
|
-
def __str__(self)->str:
|
52
|
+
def __str__(self) -> str:
|
31
53
|
return "Widget"
|
32
54
|
|
33
|
-
def set_autoresize(self,value:bool)->Self:
|
55
|
+
def set_autoresize(self, value: bool) -> Self:
|
34
56
|
self.autoresize_w = self.autoresize_h = value
|
35
57
|
self.dirty_shape = True
|
36
58
|
return self
|
37
59
|
|
38
|
-
def set_autoresize_w(self,value:bool)->Self:
|
60
|
+
def set_autoresize_w(self, value: bool) -> Self:
|
39
61
|
self.autoresize_w = value
|
40
62
|
self.dirty_shape = True
|
41
63
|
return self
|
42
64
|
|
43
|
-
def set_autoresize_h(self,value:bool)->Self:
|
65
|
+
def set_autoresize_h(self, value: bool) -> Self:
|
44
66
|
self.autoresize_h = value
|
45
67
|
self.dirty_shape = True
|
46
68
|
return self
|
47
69
|
|
48
|
-
def set_render_order(self,render_order:int)->Self:
|
70
|
+
def set_render_order(self, render_order: int) -> Self:
|
49
71
|
super().set_render_order(render_order)
|
50
|
-
if self.parent:
|
72
|
+
if self.parent:
|
73
|
+
self.parent.do_sort_children = True
|
51
74
|
return self
|
52
75
|
|
53
|
-
|
54
|
-
|
76
|
+
def inflate_rect_by_padding(
|
77
|
+
self, rect: pygame.Rect | pygame.FRect
|
78
|
+
) -> pygame.Rect | pygame.FRect:
|
55
79
|
return pygame.FRect(
|
56
80
|
rect[0] - self.padding[0],
|
57
81
|
rect[1] - self.padding[1],
|
58
82
|
rect[2] + self.padding[0] + self.padding[2],
|
59
|
-
rect[3] + self.padding[1] + self.padding[3]
|
83
|
+
rect[3] + self.padding[1] + self.padding[3],
|
60
84
|
)
|
61
|
-
|
85
|
+
|
62
86
|
def set_position(self, x, y) -> Self:
|
63
|
-
if x is None:
|
64
|
-
|
65
|
-
if
|
66
|
-
|
67
|
-
self.rect.topleft
|
68
|
-
|
87
|
+
if x is None:
|
88
|
+
x = self.rect.x
|
89
|
+
if y is None:
|
90
|
+
y = self.rect.y
|
91
|
+
if (x, y) == self.rect.topleft:
|
92
|
+
return self
|
93
|
+
dx, dy = x - self.rect.x, y - self.rect.y
|
94
|
+
self.rect.topleft = x, y
|
95
|
+
_ = [c.set_position(c.rect.x + dx, c.rect.y + dy) for c in self.children]
|
69
96
|
return self
|
70
97
|
|
71
|
-
def set_center(self,x,y)->Self:
|
72
|
-
if x is None
|
73
|
-
|
74
|
-
if
|
75
|
-
|
76
|
-
self.rect.center
|
77
|
-
|
78
|
-
|
98
|
+
def set_center(self, x, y) -> Self:
|
99
|
+
if x is None:
|
100
|
+
x = self.rect.centerx
|
101
|
+
if y is None:
|
102
|
+
y = self.rect.centery
|
103
|
+
if (x, y) == self.rect.center:
|
104
|
+
return self
|
105
|
+
dx, dy = x - self.rect.centerx, y - self.rect.centery
|
106
|
+
self.rect.center = x, y
|
107
|
+
_ = [
|
108
|
+
c.set_center(c.rect.centerx + dx, c.rect.centery + dy)
|
109
|
+
for c in self.children
|
110
|
+
]
|
111
|
+
return self
|
79
112
|
|
80
|
-
def set_parent_scene(self,parent_scene:bf.Scene)->Self:
|
113
|
+
def set_parent_scene(self, parent_scene: bf.Scene) -> Self:
|
81
114
|
super().set_parent_scene(parent_scene)
|
82
|
-
|
83
|
-
|
115
|
+
if parent_scene is None:
|
116
|
+
bf.StyleManager().remove_widget(self)
|
117
|
+
|
118
|
+
for c in self.children:
|
119
|
+
c.set_parent_scene(parent_scene)
|
84
120
|
return self
|
85
|
-
|
86
|
-
def set_parent(self,parent:"Widget")->Self:
|
121
|
+
|
122
|
+
def set_parent(self, parent: "Widget") -> Self:
|
123
|
+
if parent == self.parent:
|
124
|
+
return self
|
125
|
+
if self.parent is not None:
|
126
|
+
self.parent.remove(self)
|
87
127
|
self.parent = parent
|
88
128
|
return self
|
89
129
|
|
@@ -103,42 +143,47 @@ class Widget(bf.Entity):
|
|
103
143
|
self.dirty_shape = True
|
104
144
|
return self
|
105
145
|
|
106
|
-
def get_padded_rect(self)->pygame.FRect:
|
107
|
-
r = self.rect.inflate(
|
146
|
+
def get_padded_rect(self) -> pygame.FRect:
|
147
|
+
r = self.rect.inflate(
|
148
|
+
-self.padding[0] - self.padding[2], -self.padding[1] - self.padding[3]
|
149
|
+
)
|
108
150
|
# r.normalize()
|
109
151
|
return r
|
110
152
|
|
111
|
-
def get_min_required_size(self)->tuple[float,float]:
|
153
|
+
def get_min_required_size(self) -> tuple[float, float]:
|
112
154
|
return self.rect.size
|
113
155
|
|
114
|
-
def get_padded_width(self)->float:
|
156
|
+
def get_padded_width(self) -> float:
|
115
157
|
return self.rect.w - self.padding[0] - self.padding[2]
|
116
|
-
|
117
|
-
def get_padded_height(self)->float:
|
158
|
+
|
159
|
+
def get_padded_height(self) -> float:
|
118
160
|
return self.rect.h - self.padding[1] - self.padding[3]
|
119
|
-
|
120
|
-
def get_padded_left(self)->float:
|
161
|
+
|
162
|
+
def get_padded_left(self) -> float:
|
121
163
|
return self.rect.left + self.padding[0]
|
122
164
|
|
123
|
-
def get_padded_right(self)->float:
|
165
|
+
def get_padded_right(self) -> float:
|
124
166
|
return self.rect.right + self.padding[2]
|
125
167
|
|
126
|
-
def get_padded_center(self)->tuple[float,float]:
|
168
|
+
def get_padded_center(self) -> tuple[float, float]:
|
127
169
|
return self.get_padded_rect().center
|
128
170
|
|
129
|
-
def get_padded_top(self)->float:
|
171
|
+
def get_padded_top(self) -> float:
|
130
172
|
return self.rect.y + self.padding[1]
|
131
173
|
|
132
|
-
def get_padded_bottom(self)->float:
|
133
|
-
return self.rect.bottom - self.padding[3]
|
174
|
+
def get_padded_bottom(self) -> float:
|
175
|
+
return self.rect.bottom - self.padding[3]
|
134
176
|
|
135
177
|
def get_debug_outlines(self):
|
178
|
+
if not self.visible:
|
179
|
+
return
|
136
180
|
yield (self.rect, self.debug_color)
|
137
|
-
if any(self.padding)
|
181
|
+
if any(self.padding):
|
182
|
+
yield (self.get_padded_rect(), self.debug_color)
|
138
183
|
for child in self.children:
|
139
184
|
yield from child.get_debug_outlines()
|
140
185
|
|
141
|
-
def add_constraints(self
|
186
|
+
def add_constraints(self, *constraints: "Constraint") -> Self:
|
142
187
|
self.constraints.extend(constraints)
|
143
188
|
seen = set()
|
144
189
|
result = []
|
@@ -147,11 +192,11 @@ class Widget(bf.Entity):
|
|
147
192
|
result.append(c)
|
148
193
|
seen.add(c.name)
|
149
194
|
self.constraints = result
|
150
|
-
self.constraints.sort(key=lambda c
|
195
|
+
self.constraints.sort(key=lambda c: c.priority)
|
151
196
|
self.dirty_constraints = True
|
152
197
|
return self
|
153
198
|
|
154
|
-
def resolve_constraints(self)->None:
|
199
|
+
def resolve_constraints(self) -> None:
|
155
200
|
if self.parent is None or not self.constraints:
|
156
201
|
self.dirty_constraints = False
|
157
202
|
return
|
@@ -159,34 +204,36 @@ class Widget(bf.Entity):
|
|
159
204
|
constraint_iteration = 0
|
160
205
|
while not all_good:
|
161
206
|
for constraint in self.constraints:
|
162
|
-
if not constraint.evaluate(self.parent,self):
|
163
|
-
constraint.apply(self.parent,self)
|
207
|
+
if not constraint.evaluate(self.parent, self):
|
208
|
+
constraint.apply(self.parent, self)
|
164
209
|
# print(constraint.name,"Applied")
|
165
210
|
constraint_iteration += 1
|
166
|
-
if
|
167
|
-
|
168
|
-
|
211
|
+
if all(c.evaluate(self.parent, self) for c in self.constraints):
|
212
|
+
all_good = True
|
213
|
+
break
|
169
214
|
elif self.__constraint_iteration > MAX_CONSTRAINTS:
|
170
|
-
print(
|
215
|
+
print(
|
216
|
+
self,
|
217
|
+
"CONSTRAINTS ERROR",
|
218
|
+
list(
|
219
|
+
c.name
|
220
|
+
for c in self.constraints
|
221
|
+
if not c.evaluate(self.parent, self)
|
222
|
+
),
|
223
|
+
)
|
171
224
|
self.dirty_constraints = False
|
172
225
|
return
|
173
226
|
# print("DONE")
|
174
227
|
self.dirty_constraints = False
|
175
228
|
|
176
|
-
def remove_constraints(self
|
229
|
+
def remove_constraints(self, *names: str) -> Self:
|
177
230
|
self.constraints = [c for c in self.constraints if c.name not in names]
|
178
231
|
return self
|
179
232
|
|
180
|
-
def has_constraint(self,name:str)->bool:
|
181
|
-
return any(c.name == name for c in self.constraints
|
182
|
-
|
183
|
-
def visit(self,func:Callable,top_down:bool = True)->None:
|
184
|
-
if top_down : func(self)
|
185
|
-
for child in self.children:
|
186
|
-
child.visit(func,top_down)
|
187
|
-
if not top_down: func(self)
|
233
|
+
def has_constraint(self, name: str) -> bool:
|
234
|
+
return any(c.name == name for c in self.constraints)
|
188
235
|
|
189
|
-
def get_root(self)->"Root":
|
236
|
+
def get_root(self) -> "Root":
|
190
237
|
if self.is_root:
|
191
238
|
return self
|
192
239
|
return self.parent.get_root()
|
@@ -194,31 +241,33 @@ class Widget(bf.Entity):
|
|
194
241
|
def top_at(self, x: float | int, y: float | int) -> "None|Widget":
|
195
242
|
if self.children:
|
196
243
|
for child in reversed(self.children):
|
197
|
-
if child.visible:
|
244
|
+
if child.visible:
|
198
245
|
r = child.top_at(x, y)
|
199
246
|
if r is not None:
|
200
247
|
return r
|
201
248
|
return self if self.visible and self.rect.collidepoint(x, y) else None
|
202
249
|
|
203
|
-
def add(self
|
250
|
+
def add(self, *children: "Widget") -> Self:
|
204
251
|
self.children.extend(children)
|
205
252
|
i = len(self.children)
|
206
253
|
for child in children:
|
207
|
-
child.set_render_order(i).set_parent(self).set_parent_scene(
|
254
|
+
child.set_render_order(i).set_parent(self).set_parent_scene(
|
255
|
+
self.parent_scene
|
256
|
+
)
|
208
257
|
i += 1
|
209
258
|
if self.parent:
|
210
259
|
self.parent.do_sort_children = True
|
211
260
|
return self
|
212
261
|
|
213
|
-
def remove(self
|
214
|
-
for child in self.children
|
262
|
+
def remove(self, *children: "Widget") -> Self:
|
263
|
+
for child in self.children:
|
215
264
|
if child in children:
|
216
|
-
child.set_parent(None).set_parent_scene(None)
|
217
265
|
self.children.remove(child)
|
266
|
+
child.set_parent(None).set_parent_scene(None)
|
218
267
|
if self.parent:
|
219
268
|
self.parent.do_sort_children = True
|
220
269
|
|
221
|
-
def set_size_if_autoresize(self,size:tuple[float,float])->Self:
|
270
|
+
def set_size_if_autoresize(self, size: tuple[float, float]) -> Self:
|
222
271
|
size = list(size)
|
223
272
|
size[0] = size[0] if self.autoresize_w else None
|
224
273
|
size[1] = size[1] if self.autoresize_h else None
|
@@ -227,15 +276,17 @@ class Widget(bf.Entity):
|
|
227
276
|
|
228
277
|
return self
|
229
278
|
|
230
|
-
def set_size(self,size:tuple)->Self:
|
279
|
+
def set_size(self, size: tuple) -> Self:
|
231
280
|
size = list(size)
|
232
|
-
if size[0] is None
|
233
|
-
|
234
|
-
if size
|
281
|
+
if size[0] is None:
|
282
|
+
size[0] = self.rect.w
|
283
|
+
if size[1] is None:
|
284
|
+
size[1] = self.rect.h
|
285
|
+
if size == self.rect.size:
|
286
|
+
return self
|
235
287
|
self.rect.size = size
|
236
288
|
self.dirty_shape = True
|
237
289
|
return self
|
238
|
-
|
239
290
|
|
240
291
|
def process_event(self, event: pygame.Event) -> bool:
|
241
292
|
# First propagate to children
|
@@ -244,40 +295,48 @@ class Widget(bf.Entity):
|
|
244
295
|
# return True if the method is blocking (no propagation to next children of the scene)
|
245
296
|
super().process_event(event)
|
246
297
|
|
247
|
-
|
248
|
-
def update(self,dt)->None:
|
298
|
+
def update(self, dt) -> None:
|
249
299
|
if self.do_sort_children:
|
250
|
-
self.children.sort(key
|
300
|
+
self.children.sort(key=lambda c: c.render_order)
|
251
301
|
self.do_sort_children = False
|
252
302
|
_ = [c.update(dt) for c in self.children]
|
253
303
|
super().update(dt)
|
254
304
|
|
255
|
-
|
256
|
-
|
257
|
-
new_size =tuple(map(int,self.rect.size))
|
305
|
+
def build(self) -> None:
|
306
|
+
new_size = tuple(map(int, self.rect.size))
|
258
307
|
if self.surface.get_size() != new_size:
|
259
|
-
new_size = [max(0,i) for i in new_size]
|
260
|
-
self.surface = pygame.Surface(new_size,self.surface_flags)
|
261
|
-
if self.convert_alpha
|
308
|
+
new_size = [max(0, i) for i in new_size]
|
309
|
+
self.surface = pygame.Surface(new_size, self.surface_flags)
|
310
|
+
if self.convert_alpha:
|
311
|
+
self.surface = self.surface.convert_alpha()
|
262
312
|
|
263
|
-
def paint(self)->None:
|
264
|
-
self.surface.fill((0,0,0,0))
|
313
|
+
def paint(self) -> None:
|
314
|
+
self.surface.fill((0, 0, 0, 0))
|
265
315
|
return self
|
266
316
|
|
267
|
-
def
|
268
|
-
if
|
317
|
+
def visit(self, func: Callable, top_down: bool = True, *args, **kwargs) -> None:
|
318
|
+
if top_down:
|
319
|
+
func(self, *args, **kwargs)
|
320
|
+
for child in self.children:
|
321
|
+
child.visit(func, top_down)
|
322
|
+
if not top_down:
|
323
|
+
func(self, *args, **kwargs)
|
324
|
+
|
325
|
+
def visit_up(self, func, *args, **kwargs) -> None:
|
326
|
+
if func(self, *args, **kwargs):
|
327
|
+
return
|
269
328
|
if self.parent:
|
270
|
-
self.parent.visit_up(func)
|
329
|
+
self.parent.visit_up(func, *args, **kwargs)
|
271
330
|
|
272
|
-
def selective_up(self,widget:"Widget"):
|
331
|
+
def selective_up(self, widget: "Widget"):
|
273
332
|
# if returns True then stop climbing widget tree
|
274
333
|
if widget.parent and widget.parent.dirty_constraints:
|
275
334
|
return False
|
276
335
|
widget.visit(self.selective_down)
|
277
336
|
return True
|
278
337
|
|
279
|
-
def selective_down(self,widget: "Widget"):
|
280
|
-
if widget.constraints
|
338
|
+
def selective_down(self, widget: "Widget"):
|
339
|
+
if widget.constraints:
|
281
340
|
widget.resolve_constraints()
|
282
341
|
else:
|
283
342
|
widget.dirty_constraints = False
|
@@ -286,29 +345,27 @@ class Widget(bf.Entity):
|
|
286
345
|
widget.dirty_shape = False
|
287
346
|
self.dirty_surface = True
|
288
347
|
|
289
|
-
|
290
348
|
def draw(self, camera: bf.Camera) -> None:
|
291
349
|
if self.dirty_shape:
|
292
350
|
self.dirty_constraints = True
|
293
351
|
self.dirty_surface = True
|
294
352
|
self.build()
|
295
353
|
self.dirty_shape = False
|
296
|
-
for child in self.children
|
354
|
+
for child in self.children:
|
297
355
|
child.dirty_constraints = True
|
298
356
|
|
299
357
|
if self.dirty_constraints:
|
300
358
|
if self.parent and self.parent.dirty_constraints:
|
301
359
|
self.parent.visit_up(self.selective_up)
|
302
360
|
else:
|
303
|
-
self.visit(lambda c
|
361
|
+
self.visit(lambda c: c.resolve_constraints())
|
304
362
|
|
305
|
-
if self.dirty_surface
|
363
|
+
if self.dirty_surface:
|
306
364
|
self.paint()
|
307
365
|
self.dirty_surface = False
|
308
366
|
|
309
|
-
|
310
|
-
|
311
367
|
super().draw(camera)
|
368
|
+
|
312
369
|
if self.clip_children:
|
313
370
|
|
314
371
|
new_clip = camera.world_to_screen(self.get_padded_rect())
|
@@ -316,6 +373,10 @@ class Widget(bf.Entity):
|
|
316
373
|
new_clip = new_clip.clip(old_clip)
|
317
374
|
camera.surface.set_clip(new_clip)
|
318
375
|
|
319
|
-
_ = [
|
376
|
+
_ = [
|
377
|
+
child.draw(camera)
|
378
|
+
for child in sorted(self.children, key=lambda c: c.render_order)
|
379
|
+
]
|
380
|
+
|
320
381
|
if self.clip_children:
|
321
|
-
camera.surface.set_clip(old_clip)
|
382
|
+
camera.surface.set_clip(old_clip)
|
batFramework/object.py
CHANGED
@@ -25,12 +25,12 @@ class Object:
|
|
25
25
|
Object.__instance_count += 1
|
26
26
|
return i
|
27
27
|
|
28
|
-
def set_position(self,x,y)->Self:
|
29
|
-
self.rect.topleft = x,y
|
28
|
+
def set_position(self, x, y) -> Self:
|
29
|
+
self.rect.topleft = x, y
|
30
30
|
return self
|
31
31
|
|
32
|
-
def set_center(self,x,y)->Self:
|
33
|
-
self.rect.center = x,y
|
32
|
+
def set_center(self, x, y) -> Self:
|
33
|
+
self.rect.center = x, y
|
34
34
|
return self
|
35
35
|
|
36
36
|
def get_debug_outlines(self):
|
@@ -41,8 +41,9 @@ class Object:
|
|
41
41
|
return self
|
42
42
|
|
43
43
|
def set_parent_scene(self, scene) -> Self:
|
44
|
-
if scene == self.parent_scene
|
45
|
-
|
44
|
+
if scene == self.parent_scene:
|
45
|
+
return self
|
46
|
+
if self.parent_scene is not None:
|
46
47
|
self.do_when_removed()
|
47
48
|
self.parent_scene = scene
|
48
49
|
if scene is not None:
|
@@ -59,9 +60,6 @@ class Object:
|
|
59
60
|
self.uid = uid
|
60
61
|
return self
|
61
62
|
|
62
|
-
def get_uid(self) -> int:
|
63
|
-
return self.uid
|
64
|
-
|
65
63
|
def add_tags(self, *tags) -> Self:
|
66
64
|
for tag in tags:
|
67
65
|
if tag not in self.tags:
|
@@ -82,7 +80,8 @@ class Object:
|
|
82
80
|
"""
|
83
81
|
Returns bool : True if the method is blocking (no propagation to next object of the scene)
|
84
82
|
"""
|
85
|
-
if event.consumed
|
83
|
+
if event.consumed:
|
84
|
+
return
|
86
85
|
self.do_process_actions(event)
|
87
86
|
self.do_handle_event(event)
|
88
87
|
|
batFramework/renderGroup.py
CHANGED
@@ -7,8 +7,11 @@ from typing import Self, Iterator, Callable
|
|
7
7
|
+ fblits
|
8
8
|
"""
|
9
9
|
|
10
|
+
|
10
11
|
class RenderGroup(bf.Entity):
|
11
|
-
def __init__(
|
12
|
+
def __init__(
|
13
|
+
self, entity_iterator: Callable[[], Iterator[bf.Entity]], blit_flags: int = 0
|
14
|
+
) -> None:
|
12
15
|
super().__init__()
|
13
16
|
self.entity_iterator = entity_iterator
|
14
17
|
self.set_blit_flags(blit_flags)
|
@@ -57,6 +60,8 @@ class RenderGroup(bf.Entity):
|
|
57
60
|
if not self.visible:
|
58
61
|
return
|
59
62
|
fblits_data = (
|
60
|
-
(e.surface, (e.rect.x - camera.rect.x,e.rect.y - camera.rect.y))
|
63
|
+
(e.surface, (e.rect.x - camera.rect.x, e.rect.y - camera.rect.y))
|
64
|
+
for e in self.entity_iterator()
|
65
|
+
if camera.rect.colliderect(e.rect)
|
61
66
|
)
|
62
67
|
camera.surface.fblits(fblits_data, self.blit_flags)
|