batframework 1.0.9a10__py3-none-any.whl → 1.0.10__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 (76) hide show
  1. batFramework/__init__.py +53 -76
  2. batFramework/action.py +99 -126
  3. batFramework/actionContainer.py +9 -53
  4. batFramework/animatedSprite.py +114 -56
  5. batFramework/audioManager.py +36 -82
  6. batFramework/camera.py +69 -263
  7. batFramework/constants.py +53 -29
  8. batFramework/cutscene.py +109 -243
  9. batFramework/cutsceneBlocks.py +176 -0
  10. batFramework/debugger.py +48 -0
  11. batFramework/dynamicEntity.py +9 -16
  12. batFramework/easing.py +71 -0
  13. batFramework/entity.py +85 -92
  14. batFramework/gui/__init__.py +3 -14
  15. batFramework/gui/button.py +78 -12
  16. batFramework/gui/constraints.py +204 -0
  17. batFramework/gui/container.py +31 -183
  18. batFramework/gui/debugger.py +43 -126
  19. batFramework/gui/frame.py +19 -0
  20. batFramework/gui/image.py +20 -55
  21. batFramework/gui/indicator.py +22 -95
  22. batFramework/gui/interactiveWidget.py +12 -229
  23. batFramework/gui/label.py +77 -311
  24. batFramework/gui/layout.py +66 -411
  25. batFramework/gui/root.py +35 -203
  26. batFramework/gui/shape.py +57 -247
  27. batFramework/gui/toggle.py +48 -114
  28. batFramework/gui/widget.py +243 -457
  29. batFramework/manager.py +29 -113
  30. batFramework/particles.py +77 -0
  31. batFramework/scene.py +217 -22
  32. batFramework/sceneManager.py +129 -161
  33. batFramework/stateMachine.py +8 -11
  34. batFramework/time.py +75 -0
  35. batFramework/transition.py +124 -129
  36. batFramework/transitionManager.py +0 -0
  37. batFramework/triggerZone.py +4 -4
  38. batFramework/utils.py +144 -266
  39. {batframework-1.0.9a10.dist-info → batframework-1.0.10.dist-info}/METADATA +24 -17
  40. batframework-1.0.10.dist-info/RECORD +43 -0
  41. batFramework/animation.py +0 -77
  42. batFramework/baseScene.py +0 -240
  43. batFramework/cutsceneManager.py +0 -34
  44. batFramework/drawable.py +0 -77
  45. batFramework/easingController.py +0 -58
  46. batFramework/enums.py +0 -135
  47. batFramework/fontManager.py +0 -65
  48. batFramework/gui/animatedLabel.py +0 -89
  49. batFramework/gui/clickableWidget.py +0 -245
  50. batFramework/gui/constraints/__init__.py +0 -1
  51. batFramework/gui/constraints/constraints.py +0 -980
  52. batFramework/gui/draggableWidget.py +0 -44
  53. batFramework/gui/meter.py +0 -96
  54. batFramework/gui/radioButton.py +0 -35
  55. batFramework/gui/selector.py +0 -250
  56. batFramework/gui/slider.py +0 -397
  57. batFramework/gui/style.py +0 -10
  58. batFramework/gui/styleManager.py +0 -54
  59. batFramework/gui/syncedVar.py +0 -49
  60. batFramework/gui/textInput.py +0 -306
  61. batFramework/gui/tooltip.py +0 -30
  62. batFramework/particle.py +0 -118
  63. batFramework/propertyEaser.py +0 -79
  64. batFramework/renderGroup.py +0 -34
  65. batFramework/resourceManager.py +0 -130
  66. batFramework/sceneLayer.py +0 -138
  67. batFramework/scrollingSprite.py +0 -115
  68. batFramework/sprite.py +0 -51
  69. batFramework/templates/__init__.py +0 -1
  70. batFramework/templates/controller.py +0 -97
  71. batFramework/tileset.py +0 -46
  72. batFramework/timeManager.py +0 -213
  73. batframework-1.0.9a10.dist-info/RECORD +0 -67
  74. {batframework-1.0.9a10.dist-info → batframework-1.0.10.dist-info}/LICENSE +0 -0
  75. {batframework-1.0.9a10.dist-info → batframework-1.0.10.dist-info}/WHEEL +0 -0
  76. {batframework-1.0.9a10.dist-info → batframework-1.0.10.dist-info}/top_level.txt +0 -0
batFramework/camera.py CHANGED
@@ -1,317 +1,123 @@
1
+ import batFramework as bf
1
2
  import pygame
2
3
  from pygame.math import Vector2
3
- import batFramework as bf
4
- from typing import Self
5
- import math
6
4
 
7
5
 
8
6
  class Camera:
9
- def __init__(
10
- self, flags=0, size: tuple[int, int] | None = None, convert_alpha: bool = False
11
- ) -> None:
12
- """
13
- Initialize the Camera object.
14
-
15
- Args:
16
- flags (int): Flags for camera initialization.
17
- size (tuple): Optional size for camera (defaults to window size)
18
- convert_alpha (bool): Convert surface to support alpha values
19
- """
20
- self.cached_surfaces: dict[tuple[int, int], pygame.Surface] = {}
21
-
22
- self.target_size = size if size else bf.const.RESOLUTION
23
- self.should_convert_alpha: bool = convert_alpha
24
- self.rect = pygame.FRect(0, 0, *self.target_size)
25
- self.vector_center = Vector2(0, 0)
26
-
27
- self.surface: pygame.Surface = pygame.Surface((0, 0)) # tmp dummy
28
- self.flags: int = flags | (pygame.SRCALPHA if convert_alpha else 0)
7
+ def __init__(self, flags=0) -> None:
8
+ self.rect = pygame.FRect(0, 0, *bf.const.RESOLUTION)
9
+ self.flags: int = flags
10
+ # self.blit_special_flags : int =pygame.BLEND_PREMULTIPLIED if (flags & pygame.SRCALPHA) else 0
29
11
  self.blit_special_flags: int = pygame.BLEND_ALPHA_SDL2
30
-
31
- self._clear_color: pygame.Color = pygame.Color(0, 0, 0, 0)
32
- if not convert_alpha:
33
- self._clear_color = pygame.Color(0, 0, 0)
34
-
35
- self.follow_point_func = None
36
- self.damping = float("inf")
37
- self.dead_zone_radius = 10
38
-
12
+ self._clear_color : pygame.Color = pygame.Color(0, 0, 0, 0)
39
13
  self.zoom_factor = 1
14
+ self.cached_surfaces: dict[float, pygame.Surface] = {}
15
+ self.surface: pygame.Surface = pygame.Surface((0,0))
16
+ self.follow_point_func = None
40
17
  self.max_zoom = 2
41
18
  self.min_zoom = 0.1
42
19
  self.zoom(1)
43
20
 
44
- def get_mouse_pos(self)->tuple[float,float]:
45
- return self.screen_to_world(pygame.mouse.get_pos())
46
-
47
- def set_clear_color(self, color: pygame.Color | tuple | str) -> Self:
48
- """
49
- Set the clear color for the camera surface.
50
-
51
- Args:
52
- color (pygame.Color | tuple): Color to set as the clear color.
53
-
54
- Returns:
55
- Camera: Returns the Camera object.
56
- """
21
+ def set_clear_color(self, color: pygame.Color|tuple):
22
+ if not isinstance(color,pygame.Color):
23
+ color = pygame.Color(color)
57
24
  self._clear_color = color
58
- return self
59
-
60
- def set_max_zoom(self, value: float) -> Self:
61
- """
62
- Set the maximum zoom value for the camera.
63
25
 
64
- Args:
65
- value (float): Maximum zoom value.
66
-
67
- Returns:
68
- Camera: Returns the Camera object.
69
- """
26
+ def set_max_zoom(self,value:float):
70
27
  self.max_zoom = value
71
- return self
72
28
 
73
- def set_min_zoom(self, value: float) -> Self:
74
- """
75
- Set the minimum zoom value for the camera.
76
-
77
- Args:
78
- value (float): Minimum zoom value.
79
-
80
- Returns:
81
- Camera: Returns the Camera object.
82
- """
29
+ def set_min_zoom(self,value:float):
83
30
  self.min_zoom = value
84
- return self
85
31
 
86
- def clear(self) -> None:
32
+ def clear(self):
87
33
  """
88
- Clear the camera surface with the set clear color.
34
+ Clear the camera surface with the set clear color
35
+ (default is tranparent)
89
36
  """
90
- if not self._clear_color: return
91
37
  self.surface.fill(self._clear_color)
92
38
 
93
- def get_center(self) -> tuple[float, float]:
94
- """
95
- Get the center of the camera's view.
96
-
97
- Returns:
98
- tuple[float,float]: Returns the center coordinates.
99
- """
39
+ def get_center(self):
100
40
  return self.rect.center
101
41
 
102
- def get_position(self) -> tuple[float, float]:
103
- """
104
- Get the center of the camera's view.
42
+
105
43
 
106
- Returns:
107
- tuple[float,float]: Returns the center coordinates.
44
+ def move(self, x, y):
108
45
  """
109
- return self.rect.topleft
110
-
111
- def move_by(self, x: float | int, y: float | int) -> Self:
46
+ Moves the camera rect by the given coordinates (+=)
112
47
  """
113
- Moves the camera rect by the given coordinates.
48
+ self.rect.topleft += Vector2(x, y)
114
49
 
115
- Args:
116
- x: X-coordinate to move.
117
- y: Y-coordinate to move.
118
-
119
- Returns:
120
- Camera: Returns the Camera object.
50
+ def set_position(self, x, y):
121
51
  """
122
- self.rect.move_ip(x, y)
123
- return self
124
-
125
- def set_position(self, x, y) -> Self:
126
- """
127
- Set the camera rect top-left position.
128
-
129
- Args:
130
- x: X-coordinate to set.
131
- y: Y-coordinate to set.
132
-
133
- Returns:
134
- Camera: Returns the Camera object.
52
+ Set the camera rect topleft position
135
53
  """
136
54
  self.rect.topleft = (x, y)
137
55
 
138
- return self
139
-
140
- def set_center(self, x, y) -> Self:
56
+ def set_center(self, x, y):
141
57
  """
142
- Set the camera rect center position.
143
-
144
- Args:
145
- x: X-coordinate for the center.
146
- y: Y-coordinate for the center.
147
-
148
- Returns:
149
- Camera: Returns the Camera object.
58
+ Set the camera rect center position
150
59
  """
151
60
  self.rect.center = (x, y)
152
- return self
153
-
154
- def set_follow_point_func(self, func) -> Self:
155
- self.follow_point_func = func
156
- return self
157
-
158
- def set_follow_speed(self, speed: float) -> Self:
159
- self.follow_speed = speed
160
- return self
161
-
162
- def set_follow_damping(self, damping: float) -> Self:
163
- self.damping = damping
164
- return self
165
61
 
166
- def set_dead_zone_radius(self, radius: float) -> Self:
167
- self.dead_zone_radius = radius
168
- return self
169
-
170
- def zoom_by(self, amount: float) -> Self:
171
- """
172
- Zooms the camera by the given amount.
173
-
174
- Args:
175
- amount (float): Amount to zoom.
176
-
177
- Returns:
178
- Camera: Returns the Camera object.
62
+ def set_follow_dynamic_point(self, func):
179
63
  """
180
- self.zoom(max(self.min_zoom, min(self.max_zoom, self.zoom_factor + amount)))
181
- return self
182
-
183
- def zoom(self, factor: float) -> Self:
64
+ Set the following function (returns tuple x y)
65
+ (camera will center its position to the center of the given coordinates)
184
66
  """
185
- Zooms the camera to the given factor.
186
-
187
- Args:
188
- factor: Factor to set for zooming.
67
+ self.follow_point_func = func
189
68
 
190
- Returns:
191
- Camera: Returns the Camera object.
192
- """
193
- if factor < self.min_zoom or factor > self.max_zoom:
194
- print(
195
- f"Zoom value {factor} is outside the zoom range : [{self.min_zoom},{self.max_zoom}]"
196
- )
197
- return self
69
+ def zoom_by(self, amount:float):
70
+ self.zoom(self.zoom_factor + amount)
198
71
 
199
- factor = round(factor, 2)
72
+ def zoom(self, factor):
73
+ if factor <self.min_zoom:
74
+ return
75
+ if factor > self.max_zoom:
76
+ return
77
+ factor = round(factor,2)
200
78
  self.zoom_factor = factor
201
- new_res = tuple(round((i / factor) / 2) * 2 for i in self.target_size)
202
- self.surface = self._get_cached_surface(new_res)
79
+ if factor not in self.cached_surfaces:
80
+ # if factor != 1 : print("creating new surface in cache : ",tuple(i * factor for i in const.RESOLUTION), self.flags)
81
+ self.cached_surfaces[factor] = pygame.Surface(
82
+ tuple(i / factor for i in bf.const.RESOLUTION), flags=self.flags
83
+ ).convert_alpha()
84
+ # c = self.surface.get_colorkey() if self.surface else None
85
+ # if c : self.cached_surfaces[factor].set_colorkey(c)
86
+ self.cached_surfaces[factor].fill((0, 0, 0, 0))
87
+
88
+ self.surface = self.cached_surfaces[self.zoom_factor]
203
89
  self.rect = self.surface.get_frect(center=self.rect.center)
204
- self.clear()
205
- return self
206
-
207
- def _free_cache(self):
208
- self.cached_surfaces = {}
209
-
210
- def _get_cached_surface(self, new_size: tuple[int, int]):
211
- surface = self.cached_surfaces.get(new_size, None)
212
- if surface is None:
213
- surface = pygame.Surface(new_size, flags=self.flags)
214
- if self.flags & pygame.SRCALPHA:
215
- surface = surface.convert_alpha()
216
- self.cached_surfaces[new_size] = surface
217
-
218
- return surface
219
-
220
- def set_size(self, size: tuple[int, int] | None = None) -> Self:
221
- if size is None:
222
- size = bf.const.RESOLUTION
223
- self.target_size = size
224
- self.rect.center = (size[0] / 2, size[1] / 2)
225
- self.zoom(self.zoom_factor)
226
-
227
- return self
90
+ # if factor != 1 : print(self.cached_surfaces)
228
91
 
229
92
  def intersects(self, rect: pygame.Rect | pygame.FRect) -> bool:
230
- """
231
- Check if the camera view intersects with the given rectangle.
232
-
233
- Args:
234
- rect (pygame.Rect | pygame.FRect): Rectangle to check intersection with.
235
-
236
- Returns:
237
- bool: True if intersection occurs, False otherwise.
238
- """
239
- return self.rect.colliderect(rect)
240
-
241
- def world_to_screen(
242
- self, rect: pygame.Rect | pygame.FRect
243
- ) -> pygame.Rect | pygame.FRect:
244
- """
245
- world_to_screen the given rectangle coordinates relative to the camera.
246
-
247
- Args:
248
- rect (pygame.Rect | pygame.FRect): Rectangle to world_to_screen.
249
-
250
- Returns:
251
- pygame.FRect: Transposed rectangle.
252
- """
253
- return pygame.FRect(
254
- rect[0] - self.rect.left, rect[1] - self.rect.top, rect[2], rect[3]
255
- )
256
-
257
- def world_to_screen_point(
258
- self, point: tuple[float, float] | tuple[int, int]
259
- ) -> tuple[float, float]:
260
- """
261
- world_to_screen the given 2D point coordinates relative to the camera.
262
-
263
- Args:
264
- point (tuple[float,float] | tuple[int,int]): Point to world_to_screen.
265
-
266
- Returns:
267
- tuple[float,float] : Transposed point.
268
- """
269
- return point[0] - self.rect.x, point[1] - self.rect.y
270
-
271
- def screen_to_world(
272
- self, point: tuple[float, float] | tuple[int, int]
273
- ) -> tuple[float, float]:
274
- """
275
- Convert screen coordinates to world coordinates based on camera settings.
276
-
277
- Args:
278
- point (tuple[float,float] | tuple[int,int]): Point to screen_to_world.
279
- Returns:
280
- tuple: Converted world coordinates.
281
- """
282
93
  return (
283
- point[0] / self.zoom_factor + self.rect.x,
284
- point[1] / self.zoom_factor + self.rect.y,
94
+ self.rect.x < rect.right
95
+ and self.rect.right > rect.x
96
+ and self.rect.y < rect.bottom
97
+ and self.rect.bottom > rect.y
285
98
  )
286
99
 
287
- def update(self, dt):
288
- if not self.follow_point_func or not (math.isfinite(dt) and dt > 0):
289
- return
290
100
 
291
- target = Vector2(self.follow_point_func())
292
- self.vector_center.update(self.rect.center)
101
+ def transpose(self, rect: pygame.Rect | pygame.FRect) -> pygame.Rect | pygame.FRect:
102
+ x, y = round(rect.x - self.rect.left), round(rect.y - self.rect.top)
103
+ return pygame.Rect(x, y, *rect.size)
293
104
 
294
- if self.damping == float("inf"):
295
- self.vector_center = target
296
- elif math.isfinite(self.damping) and self.damping > 0:
297
- damping_factor = 1 - math.exp(-self.damping * dt)
298
- if not math.isnan(damping_factor):
299
- self.vector_center += (target - self.vector_center) * damping_factor
105
+ def convert_screen_to_world(self, x, y):
106
+ return x / self.zoom_factor + self.rect.x, y / self.zoom_factor + self.rect.y
300
107
 
301
- self.rect.center = self.vector_center
108
+ def update(self, dt):
109
+ if self.follow_point_func:
110
+ target = self.follow_point_func()
111
+ self.rect.center = Vector2(self.rect.center).lerp(target, ((dt * 60) * 0.1))
302
112
 
303
113
  def draw(self, surface: pygame.Surface):
304
- """
305
- Draw the camera view onto the provided surface with proper scaling.
306
-
307
- Args:
308
- surface (pygame.Surface): Surface to draw the camera view onto.
309
- """
114
+ # pygame.draw.circle(surface,bf.color.ORANGE,self.surface.get_rect().center,4)
310
115
  if self.zoom_factor == 1:
311
116
  surface.blit(self.surface, (0, 0), special_flags=self.blit_special_flags)
312
- # surface.blit(self.surface, (0, 0))
313
117
  return
314
-
315
- # Scale the surface to match the resolution
316
- scaled_surface = pygame.transform.scale(self.surface, self.target_size)
317
- surface.blit(scaled_surface, (0, 0), special_flags=self.blit_special_flags)
118
+ # print("From",self.surface,"Target RESOLUTION",const.RESOLUTION,"Destination",surface)
119
+ surface.blit(
120
+ pygame.transform.scale(self.surface, bf.const.RESOLUTION),
121
+ (0, 0),
122
+ special_flags=self.blit_special_flags,
123
+ )
batFramework/constants.py CHANGED
@@ -1,51 +1,75 @@
1
1
  import pygame
2
+ from enum import Enum
2
3
 
3
4
 
4
5
  class Constants:
5
- SCREEN: pygame.Surface = None
6
- RESOLUTION: tuple[int, int] = (1280, 720)
7
- WIDTH = 1280
8
- HEIGHT = 720
6
+ SCREEN = None
7
+ RESOLUTION: tuple[int, int] = (1280,720)
9
8
  VSYNC = 0
10
9
  FLAGS: int = pygame.SCALED | pygame.RESIZABLE
11
10
  FPS: int = 60
11
+ RESOURCE_PATH = "."
12
+
13
+ @staticmethod
14
+ def init_screen(resolution:tuple[int,int],flags:int= 0, vsync:int= 0):
15
+ Constants.RESOLUTION = resolution
16
+ Constants.FLAGS = flags
17
+ Constants.VSYNC = vsync
18
+ Constants.SCREEN = pygame.display.set_mode(Constants.RESOLUTION, Constants.FLAGS,vsync=Constants.VSYNC)
19
+ print(f"Window : {resolution[0]}x{resolution[1]}px | flags:{flags.bit_count()}, vsync:{pygame.display.is_vsync()}")
12
20
  MUSIC_END_EVENT = pygame.event.custom_type()
13
21
 
14
- DEFAULT_CURSOR = pygame.cursors.Cursor(pygame.SYSTEM_CURSOR_ARROW)
15
- DEFAULT_HOVER_CURSOR = pygame.cursors.Cursor(pygame.SYSTEM_CURSOR_ARROW)
16
- DEFAULT_CLICK_CURSOR = pygame.cursors.Cursor(pygame.SYSTEM_CURSOR_ARROW)
17
-
18
- BF_INITIALIZED: bool = False
19
- ALLOW_DEBUG : bool = True
22
+ # ------------GUI SPECIFIC
23
+ DEFAULT_TEXT_SIZE: int = 8
20
24
 
21
- @staticmethod
22
- def set_allow_debug(allow_debug:bool):
23
- Constants.ALLOW_DEBUG = allow_debug
25
+ GUI_SCALE: int = 1
26
+ # ---------------------
24
27
 
25
28
  @staticmethod
26
- def set_resolution(resolution: tuple[int, int]):
29
+ def set_resolution(resolution : tuple[int,int]):
27
30
  Constants.RESOLUTION = resolution
28
- Constants.WIDTH = resolution[0]
29
- Constants.HEIGHT = resolution[1]
30
- Constants.update_screen()
31
31
 
32
32
  @staticmethod
33
- def update_screen():
34
- if Constants.BF_INITIALIZED:
35
- Constants.SCREEN = pygame.display.set_mode(Constants.RESOLUTION,Constants.FLAGS,vsync=Constants.VSYNC)
33
+ def set_resource_path(path: str):
34
+ print("set resource path :", path)
35
+ Constants.RESOURCE_PATH = path
36
36
 
37
37
  @staticmethod
38
- def set_default_cursor(cursor: pygame.Cursor):
39
- Constants.DEFAULT_CURSOR = cursor
38
+ def set_fps_limit(value: int):
39
+ Constants.FPS = value
40
+ print("FPS limit to : ", value)
40
41
 
41
42
  @staticmethod
42
- def set_default_hover_cursor(cursor: pygame.Cursor):
43
- Constants.DEFAULT_HOVER_CURSOR = cursor
43
+ def set_gui_scale(value: int):
44
+ Constants.GUI_SCALE = value
45
+ print("GUI_SCALE to : ", value)
44
46
 
45
47
  @staticmethod
46
- def set_default_click_cursor(cursor: pygame.Cursor):
47
- Constants.DEFAULT_CLICK_CURSOR = cursor
48
+ def set_default_text_size(size:int):
49
+ Constants.DEFAULT_TEXT_SIZE = size
48
50
 
49
- @staticmethod
50
- def set_fps_limit(value: int):
51
- Constants.FPS = value
51
+ class Colors:
52
+ LIGHT_CYAN = (179, 229, 252)
53
+ WASHED_BLUE = (52, 73, 94)
54
+ RIVER_BLUE = (52, 152, 219)
55
+ DARK_INDIGO = (40, 53, 147)
56
+ LIGHT_BLUE = (3, 169, 244)
57
+ DEEP_BLUE = (41, 121, 255)
58
+ DARK_BLUE = (44, 62, 80)
59
+ GREEN = (67, 160, 71)
60
+ DARK_GREEN = (39, 174, 96)
61
+ BROWN = (109, 76, 65)
62
+ DARK_RED = (192, 57, 43)
63
+ ORANGE = (251, 140, 0)
64
+ CLOUD_WHITE = (236, 240, 241)
65
+ SILVER = (189, 195, 199)
66
+ DARK_GRAY = (66, 66, 66)
67
+
68
+ DARK_GB = (27, 42, 9)
69
+ SHADE_GB = (14, 69, 11)
70
+ BASE_GB = (73, 107, 34)
71
+ LIGHT_GB = (154, 158, 63)
72
+
73
+ class Axis(Enum):
74
+ HORIZONTAL = 1
75
+ VERTICAL = 2