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