batframework 1.0.8a1__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 (63) hide show
  1. batFramework/__init__.py +50 -53
  2. batFramework/action.py +105 -116
  3. batFramework/actionContainer.py +11 -53
  4. batFramework/animatedSprite.py +65 -115
  5. batFramework/audioManager.py +26 -70
  6. batFramework/camera.py +68 -253
  7. batFramework/constants.py +54 -16
  8. batFramework/cutscene.py +25 -34
  9. batFramework/cutsceneBlocks.py +42 -37
  10. batFramework/debugger.py +48 -0
  11. batFramework/dynamicEntity.py +7 -9
  12. batFramework/easing.py +71 -0
  13. batFramework/entity.py +98 -42
  14. batFramework/gui/__init__.py +2 -8
  15. batFramework/gui/button.py +79 -7
  16. batFramework/gui/constraints.py +204 -0
  17. batFramework/gui/container.py +31 -155
  18. batFramework/gui/debugger.py +43 -124
  19. batFramework/gui/frame.py +19 -0
  20. batFramework/gui/image.py +17 -41
  21. batFramework/gui/indicator.py +21 -41
  22. batFramework/gui/interactiveWidget.py +13 -116
  23. batFramework/gui/label.py +73 -278
  24. batFramework/gui/layout.py +61 -148
  25. batFramework/gui/root.py +37 -102
  26. batFramework/gui/shape.py +57 -258
  27. batFramework/gui/toggle.py +46 -97
  28. batFramework/gui/widget.py +254 -268
  29. batFramework/manager.py +19 -40
  30. batFramework/particles.py +77 -0
  31. batFramework/scene.py +107 -214
  32. batFramework/sceneManager.py +107 -150
  33. batFramework/stateMachine.py +0 -1
  34. batFramework/time.py +57 -117
  35. batFramework/transition.py +126 -184
  36. batFramework/transitionManager.py +0 -0
  37. batFramework/utils.py +161 -34
  38. batframework-1.0.8a2.dist-info/METADATA +58 -0
  39. batframework-1.0.8a2.dist-info/RECORD +42 -0
  40. {batframework-1.0.8a1.dist-info → batframework-1.0.8a2.dist-info}/WHEEL +1 -1
  41. batFramework/easingController.py +0 -58
  42. batFramework/enums.py +0 -104
  43. batFramework/fontManager.py +0 -65
  44. batFramework/gui/clickableWidget.py +0 -206
  45. batFramework/gui/constraints/__init__.py +0 -1
  46. batFramework/gui/constraints/constraints.py +0 -378
  47. batFramework/gui/dialogueBox.py +0 -96
  48. batFramework/gui/draggableWidget.py +0 -38
  49. batFramework/gui/meter.py +0 -76
  50. batFramework/gui/radioButton.py +0 -62
  51. batFramework/gui/slider.py +0 -220
  52. batFramework/gui/textInput.py +0 -134
  53. batFramework/object.py +0 -115
  54. batFramework/particle.py +0 -101
  55. batFramework/renderGroup.py +0 -62
  56. batFramework/resourceManager.py +0 -84
  57. batFramework/scrollingSprite.py +0 -113
  58. batFramework/sprite.py +0 -45
  59. batFramework/tileset.py +0 -46
  60. batframework-1.0.8a1.dist-info/LICENCE +0 -21
  61. batframework-1.0.8a1.dist-info/METADATA +0 -55
  62. batframework-1.0.8a1.dist-info/RECORD +0 -56
  63. {batframework-1.0.8a1.dist-info → batframework-1.0.8a2.dist-info}/top_level.txt +0 -0
batFramework/gui/shape.py CHANGED
@@ -1,287 +1,86 @@
1
1
  import batFramework as bf
2
2
  from .widget import Widget
3
3
  import pygame
4
- from typing import Self,Iterable
5
- from math import ceil
6
4
 
7
5
 
8
6
  class Shape(Widget):
9
- def __init__(self, size: tuple[float, float] = None,*args,**kwargs):
10
- super().__init__(size=size,convert_alpha=True)
11
- self.color = (0, 0, 0, 0)
12
- self.border_radius: list[int] = [0]
13
- self.outline: int = 0
14
- self.outline_color: tuple[int, int, int] | str = (0, 0, 0, 255)
15
- self.texture_surface = None
16
- self.texture_subsize = (0, 0)
17
- self.relief = 0
18
- self.shadow_color: tuple[int, int, int] | str = (0, 0, 0, 255)
19
- self.draw_mode = bf.drawMode.SOLID
7
+ def __init__(self,width:float,height:float):
8
+ self._color = (0,0,0,0)
9
+ self._border_radius:list[int] = [0]
10
+ self._outline : int = 0
11
+ self._outline_color : tuple[int,int,int] | str = (0,0,0,0)
12
+ super().__init__(convert_alpha = True)
13
+ self.set_size(width,height)
20
14
 
21
- def get_padded_bottom(self) -> float:
22
- return self.rect.bottom - self.padding[3] - self.relief
23
15
 
24
- def get_padded_height(self) -> float:
25
- return self.rect.h - self.padding[1] - self.padding[3] - self.relief
26
-
27
- def get_padded_top(self)->float:
28
- return self.rect.y + self.relief
29
-
30
- def get_padded_rect(self)->pygame.FRect:
31
- return pygame.FRect(
32
- self.rect.x + self.padding[0],
33
- self.rect.y + self.padding[1],
34
- self.rect.w - self.padding[2] - self.padding[0],
35
- self.rect.h - self.padding[1] - self.padding[3] - self.relief
36
- )
37
-
38
- def set_shadow_color(self, color: tuple[int, int, int] | str) -> Self:
39
- self.shadow_color = color
40
- self.dirty_surface = True
41
- return self
42
-
43
- def set_relief(self, relief: int) -> Self:
44
- if relief < 0:
45
- return self
46
- if self.relief == relief : return self
47
- self.relief = relief
48
- self.dirty_shape = True
49
- return self
50
-
51
- def get_relief(self) -> int:
52
- return self.relief
53
-
54
- def set_texture(
55
- self, surface: pygame.SurfaceType, subsize: tuple[int, int] | None = None
56
- ) -> Self:
57
- self.texture_surface = surface
58
- if subsize is None:
59
- subsize = (ceil(surface.get_width() / 3), ceil(surface.get_height() / 3))
60
- self.texture_subsize = subsize
61
- self.dirty_surface = True
62
- return self
63
-
64
- def set_draw_mode(self, mode: bf.drawMode) -> Self:
65
- self.draw_mode = mode
66
- self.dirty_surface = True
67
- return self
68
-
69
- def get_draw_mode(self) -> bf.drawMode:
70
- return self.draw_mode
71
-
72
- def has_alpha_color(self) -> bool:
73
- return (pygame.Color(self.color).a != 255) or (
74
- pygame.Color(self.outline_color).a != 255
75
- )
76
-
77
- def __str__(self) -> str:
16
+ def to_string_id(self)->str:
78
17
  return "Shape"
79
18
 
80
- def set_color(self, color: tuple[int, int, int] | str) -> Self:
81
- self.color = color
82
- self.dirty_surface = True
19
+ def set_color(self,color:tuple[int,int,int]|str) -> "Frame":
20
+ self._color = color
21
+ self.build()
83
22
  return self
84
23
 
85
- def set_outline_color(self, color: tuple[int, int, int] | str) -> Self:
86
- self.outline_color = color
87
- self.dirty_surface = True
24
+ def set_outline_color(self,color:tuple[int,int,int]|str) -> "Frame":
25
+ self._outline_color = color
26
+ self.build()
88
27
  return self
89
28
 
90
- def set_border_radius(self, value: int | list[int]) -> Self:
91
- if isinstance(value, int):
92
- self.border_radius = [value]
29
+ def set_border_radius(self,value:int|list[int]) -> "Frame":
30
+ if isinstance(value,int):
31
+ self._border_radius = [value]
93
32
  else:
94
- self.border_radius = value
95
- self.dirty_surface = True
33
+ self._border_radius = value
34
+ self.build()
96
35
  return self
97
-
98
- def set_outline_width(self, value: int) -> Self:
99
- self.outline = value
100
- self.dirty_surface = True
36
+
37
+ def set_outline_width(self,value:int) -> "Frame":
38
+ self._outline = value
39
+ self.build()
101
40
  return self
102
-
103
- def paint(self)->None:
104
- if self.draw_mode == bf.drawMode.TEXTURED:
105
- self._paint_textured()
106
- return
107
- if self.border_radius == [0]:
108
- self._paint_shape()
109
- if self.outline:
110
- self._paint_outline()
41
+
42
+ def build(self)->None:
43
+ if self.surface.get_size() != self.get_size_int():
44
+ self.surface = pygame.Surface(self.get_size_int())
45
+ if self.convert_alpha :
46
+ self.surface = self.surface.convert_alpha()
47
+ self.surface.fill((0,0,0,0))
48
+ if self.parent :
49
+ self.parent.children_modified()
50
+ if self._border_radius == [0]:
51
+ self._build_shape()
52
+ if self._outline : self._build_outline()
111
53
  else:
112
- self._paint_rounded_shape()
113
- if self.outline:
114
- self._paint_rounded_outline()
115
-
116
-
54
+ self._build_rounded_shape()
55
+ if self._outline : self._build_rounded_outline()
117
56
 
118
- def _paint_textured(self) -> None:
119
- self.surface.fill((0, 0, 0, 0))
120
- if self.texture_surface is None:
121
- return
122
- w, h = self.surface.get_size()
123
- sw, sh = self.texture_surface.get_size()
124
- sub = self.texture_subsize
125
57
 
126
- # center
127
- center_surface = self.texture_surface.subsurface((sub[0], sub[1], *sub))
128
- top_surface = self.texture_surface.subsurface((sub[0], 0, *sub))
129
- bottom_surface = self.texture_surface.subsurface((sub[0], sh - sub[1], *sub))
130
- left_surface = self.texture_surface.subsurface((0, sub[1], *sub))
131
- right_surface = self.texture_surface.subsurface((sw - sub[0], sub[1], *sub))
58
+ def _build_shape(self)->None:
59
+ self.surface.fill(self._color)
132
60
 
133
- lst = []
134
- for y in range(sub[1], h + 1 - sub[1] * 2, sub[1]):
135
- for x in range(sub[0], w + 1 - sub[0] * 2, sub[0]):
136
- lst.append((center_surface, (x, y)))
137
-
138
- w_remainder = w % sub[0]
139
- h_remainder = h % sub[1]
140
- fix_x = ((w // sub[0]) - 1) * sub[0]
141
- fix_y = ((h // sub[1]) - 1) * sub[1]
142
-
143
- if (w > sub[0]) and (w_remainder > 0):
144
- # Center : Fix gaps on the x axis
145
- h_portion = center_surface.subsurface(0, 0, w_remainder, sub[1])
146
- for y in range(sub[1], h - sub[1] * 2, sub[1]):
147
- lst.append((h_portion, (fix_x, y)))
148
-
149
- # Fix partial gaps on the top
150
-
151
- t_portion = top_surface.subsurface(0, 0, w_remainder, sub[1])
152
- lst.append((t_portion, (fix_x, 0)))
153
-
154
- # Fix partial gaps on the bottom
155
- b_portion = bottom_surface.subsurface(0, 0, w_remainder, sub[1])
156
- lst.append((b_portion, (fix_x, h - sub[1] - 1)))
157
-
158
- if (h > sub[1]) and (h_remainder > 0):
159
- # Center : Fix gaps on the y axis
160
- v_portion = center_surface.subsurface(0, 0, sub[0], h_remainder)
161
- for x in range(sub[0], w - sub[0] * 2, sub[0]):
162
- lst.append((v_portion, (x, fix_y)))
163
-
164
- # Fix partial gaps on the left
165
- l_portion = left_surface.subsurface(0, 0, sub[0], h_remainder)
166
- lst.append((l_portion, (0, fix_y)))
167
-
168
- # Fix partial gaps on the right
169
- r_portion = right_surface.subsurface(0, 0, sub[0], h_remainder)
170
- lst.append((r_portion, (w - sub[0] - 1, fix_y)))
171
-
172
- # fix corner gap
173
- if h > sub[1] or w > sub[0]:
174
- corner_portion = center_surface.subsurface(
175
- 0,
176
- 0,
177
- w_remainder if w_remainder else sub[0],
178
- h_remainder if h_remainder else sub[1],
179
- )
180
- if w_remainder == 0:
181
- fix_x -= sub[0]
182
- if h_remainder == 0:
183
- fix_y -= sub[1]
184
- lst.append((corner_portion, (fix_x - 1, fix_y - 1)))
185
-
186
- # borders
187
- lst.extend(
188
- [(top_surface, (x, 0)) for x in range(sub[0], w + 1 - sub[0] * 2, sub[0])]
189
- + [
190
- (bottom_surface, (x, h - sub[1] - 1))
191
- for x in range(sub[0], w + 1 - sub[0] * 2, sub[0])
192
- ]
193
- + [
194
- (left_surface, (0, y))
195
- for y in range(sub[1], h + 1 - sub[1] * 2, sub[1])
196
- ]
197
- + [
198
- (right_surface, (w - sub[0] - 1, y))
199
- for y in range(sub[1], h + 1 - sub[1] * 2, sub[1])
200
- ]
201
- + [
202
- (self.texture_surface.subsurface((0, 0, *sub)), (0, 0)),
203
- (
204
- self.texture_surface.subsurface((sw - sub[0], 0, *sub)),
205
- (w - sub[0] - 1, 0),
206
- ),
207
- (
208
- self.texture_surface.subsurface((0, sh - sub[1], *sub)),
209
- (0, h - sub[1] - 1),
210
- ),
211
- (
212
- self.texture_surface.subsurface((sw - sub[0], sh - sub[1], *sub)),
213
- (w - sub[0] - 1, h - sub[1] - 1),
214
- ),
215
- ]
216
- )
217
-
218
- self.surface.fblits(lst)
219
-
220
- def _get_elevated_rect(self) -> pygame.FRect:
221
- return pygame.FRect(
222
- 0,0 , self.rect.w, self.rect.h - self.relief
223
- )
224
-
225
- def _get_base_rect(self) -> pygame.FRect:
226
- return pygame.FRect(
227
- 0, self.rect.h - self.relief , self.rect.w, self.relief
61
+ def _build_rounded_shape(self)->None:
62
+ self.surface.fill((0,0,0,0))
63
+ pygame.draw.rect(
64
+ self.surface,
65
+ self._color,
66
+ (0,0,*self.rect.size),
67
+ 0,
68
+ *self._border_radius
228
69
  )
229
70
 
230
- def _paint_shape(self) -> None:
231
- self.surface.fill((0, 0, 0, 0))
232
- self.surface.fill(self.shadow_color, self._get_base_rect())
233
- self.surface.fill(self.color, self._get_elevated_rect())
234
-
235
- def _paint_rounded_shape(self) -> None:
236
- self.surface.fill((0, 0, 0, 0))
237
- e = self._get_elevated_rect()
238
- b = e.copy()
239
- b.bottom = self.rect.h
240
- pygame.draw.rect(self.surface, self.shadow_color, b, 0, *self.border_radius)
241
- pygame.draw.rect(self.surface, self.color, e, 0, *self.border_radius)
242
-
243
- def _paint_outline(self) -> None:
244
- if self.relief:
245
- pygame.draw.rect(
246
- self.surface,
247
- self.outline_color,
248
- (
249
- 0,
250
- self.relief - self.get_relief(),
251
- self.rect.w,
252
- self.rect.h - self.relief,
253
- ),
254
- self.outline,
255
- )
71
+ def _build_outline(self)->None:
256
72
  pygame.draw.rect(
257
73
  self.surface,
258
- self.outline_color,
259
- (
260
- 0,
261
- self.relief - self.get_relief(),
262
- self.rect.w,
263
- self.rect.h - (self.relief - self.get_relief()),
264
- ),
265
- self.outline,
74
+ self._outline_color,
75
+ (0,0,*self.rect.size),
76
+ self._outline
266
77
  )
267
-
268
- def _paint_rounded_outline(self) -> None:
269
- e = self._get_elevated_rect()
270
- b = e.copy()
271
- b.h += e.bottom - b.bottom
272
-
78
+
79
+ def _build_rounded_outline(self)->None:
273
80
  pygame.draw.rect(
274
81
  self.surface,
275
- self.outline_color,
276
- e,
277
- self.outline,
278
- *self.border_radius,
82
+ self._outline_color,
83
+ (0,0,*self.rect.size),
84
+ self._outline,
85
+ *self._border_radius
279
86
  )
280
- if self.relief:
281
- pygame.draw.rect(
282
- self.surface,
283
- self.outline_color,
284
- b,
285
- self.outline,
286
- *self.border_radius,
287
- )
@@ -1,113 +1,62 @@
1
1
  from .button import Button
2
- from .indicator import Indicator, ToggleIndicator
2
+ from .indicator import Indicator,ToggleIndicator
3
+ import pygame
3
4
  import batFramework as bf
4
5
  from typing import Self
5
- import pygame
6
-
7
6
 
8
7
  class Toggle(Button):
9
- def __init__(self, text: str, callback=None,default_value: bool = False) -> None:
10
- self.value: bool = default_value
11
- self.indicator: ToggleIndicator = ToggleIndicator(default_value)
12
- self.gap: float | int = 0
13
- self.spacing :bf.spacing = bf.spacing.MANUAL
14
- super().__init__(text, callback)
15
- self.add(self.indicator)
16
- # self.set_gap(int(max(4, self.get_padded_width() / 3)))
17
-
18
- def set_value(self, value: bool, do_callback=False) -> Self:
19
- self.value = value
20
- self.indicator.set_value(value)
21
- self.dirty_surface = True
22
- if do_callback and self.callback:
23
- self.callback(self.value)
24
- return self
25
-
26
- def set_spacing(self,spacing:bf.spacing)->Self:
27
- if spacing == self.spacing : return self
28
- self.spacing = spacing
29
- self.dirty_shape = True
30
- return self
31
-
32
- def click(self) -> None:
33
- self.set_value(not self.value, True)
34
-
35
- def set_gap(self, value: int | float) -> Self:
36
- value = max(0, value)
37
- if value == self.gap : return self
8
+ def __init__(self,text:str,default_value : bool = False)->None:
9
+ self.value :bool= default_value
10
+ self.on_toggle = None
11
+ self.indicator : Indicator=ToggleIndicator(default_value)
12
+ self.gap :float|int = 0
13
+ super().__init__(text,self.toggle)
14
+ self.add_child(self.indicator)
15
+ self.set_gap(int(max(4,self.get_content_width()/3)))
16
+ # self.set_gap()
17
+ # self.set_gap(20)
18
+
19
+ def set_gap(self,value:int|float)->Self:
20
+ if value < 0 : return self
38
21
  self.gap = value
39
- self.dirty_shape = True
22
+ self.build()
23
+ if self.parent : self.parent.children_modified()
40
24
  return self
41
-
42
- def __str__(self) -> str:
25
+ def to_string_id(self)->str:
43
26
  return f"Toggle({self.value})"
27
+
28
+ def toggle(self)->None:
29
+ self.value = not self.value
30
+ self.build()
31
+ if self.on_toggle : self.on_toggle(self.value)
44
32
 
45
- def toggle(self) -> None:
46
- self.set_value(not self.value, do_callback=True)
47
-
48
- def get_min_required_size(self) -> tuple[float, float]:
49
- if not self.text_rect:
50
- params = {
51
- "font_name": self.font_object.name,
52
- "text": self.text,
53
- "antialias": False,
54
- "color": "white",
55
- "bgcolor": "black", # if (self.has_alpha_color() or self.draw_mode == bf.drawMode.TEXTURED) else self.color,
56
- "wraplength": int(self.get_padded_width()) if self.auto_wraplength else 0,
57
- }
58
- self.text_rect.size = self._render_font(params).get_size()
59
- w,h = self.text_rect.size
60
- size = max(self.indicator.rect.w,w + self.font_object.point_size + (self.gap if self.text else 0)), max(h,self.font_object.point_size,self.indicator.rect.h)
61
- return self.inflate_rect_by_padding((0,0,*size)).size
33
+ def set_toggle_callback(self,callback)->Self:
34
+ self.on_toggle = callback
35
+ return self
62
36
 
37
+ def _build_layout(self)->None:
38
+ self.indicator.set_value(self.value)
63
39
 
64
- def _build_layout(self) -> None:
65
-
66
- gap = self.gap if self.text else 0
40
+ size = (
41
+ 0,
42
+ 0,
43
+ self._text_rect.w + self.indicator.rect.w + self.gap,
44
+ max(self._text_rect.h, self.indicator.rect.h)
45
+ )
67
46
 
68
- params = {
69
- "font_name": self.font_object.name,
70
- "text": self.text,
71
- "antialias": False,
72
- "color": "white",
73
- "bgcolor": "black", # if (self.has_alpha_color() or self.draw_mode == bf.drawMode.TEXTURED) else self.color,
74
- "wraplength": int(self.get_padded_width()) if self.auto_wraplength else 0,
75
- }
76
- self.text_rect.size = self._render_font(params).get_size()
77
-
78
- indicator_height = self.font_object.point_size
79
-
80
- self.indicator.set_size((indicator_height,indicator_height))
81
-
47
+ required_rect = self.inflate_rect_by_padding(size)
82
48
 
83
- tmp_rect = pygame.FRect(0,0,self.text_rect.w + gap + indicator_height , self.text_rect.h)
49
+ if self.autoresize and (self.rect.size != required_rect.size) :
50
+ self.set_size(*required_rect.size)
51
+ return
84
52
 
53
+ required_rect = self.get_content_rect()
54
+ required_rect_rel = self.get_content_rect_rel()
85
55
 
86
- if self.autoresize_h or self.autoresize_w:
87
- target_rect = self.inflate_rect_by_padding(tmp_rect)
88
- if not self.autoresize_w : target_rect.w = self.rect.w
89
- if not self.autoresize_h : target_rect.h = self.rect.h
90
- if self.rect.size != target_rect.size:
91
- self.set_size(target_rect.size)
92
- self.build()
93
- return
94
-
95
- padded = self.get_padded_rect().move(-self.rect.x,-self.rect.y)
56
+ self._text_rect.midleft = required_rect_rel.midleft
57
+ r = self.indicator.rect.copy()
58
+ r.midleft = required_rect.move(self._text_rect.w+self.gap,0).midleft
59
+ self.indicator.set_position(*r.topleft)
60
+
61
+ self.surface.blit(self._text_surface,self._text_rect)
96
62
 
97
- self.align_text(tmp_rect,padded,self.alignment)
98
- self.text_rect.midleft = tmp_rect.midleft
99
- if self.text :
100
- match self.spacing:
101
- case bf.spacing.MAX:
102
- gap = padded.w - self.text_rect.w - self.indicator.rect.w
103
- case bf.spacing.MIN:
104
- gap = 0
105
- case bf.spacing.HALF:
106
- gap = (padded.w)/2 - self.text_rect.w
107
-
108
- self.indicator.set_position(
109
- *self.text_rect.move(
110
- self.rect.x+gap,
111
- self.rect.y + (self.text_rect.h /2) - self.indicator.rect.h/2
112
- ).topright
113
- )