batframework 1.0.8a13__py3-none-any.whl → 1.0.8a14__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/__init__.py CHANGED
@@ -8,7 +8,7 @@ from .resourceManager import ResourceManager
8
8
  from .fontManager import FontManager
9
9
  from .utils import Utils as utils
10
10
  from .tileset import Tileset
11
- from .time import *
11
+ from .timeManager import TimeManager,Timer,SceneTimer
12
12
  from .easingController import EasingController
13
13
  from .cutscene import Cutscene, CutsceneManager
14
14
  from .cutsceneBlocks import *
@@ -17,8 +17,8 @@ import batFramework.transition as transition
17
17
  from .action import Action
18
18
  from .actionContainer import *
19
19
  from .camera import Camera
20
- from .object import Object
21
20
  from .entity import Entity
21
+ from .drawable import Drawable
22
22
  from .renderGroup import RenderGroup
23
23
  from .dynamicEntity import DynamicEntity
24
24
  from .sprite import Sprite
@@ -3,7 +3,7 @@ import pygame
3
3
  from typing import List, Dict, Tuple, Union, Optional, Self
4
4
  from .animation import Animation
5
5
 
6
- class AnimatedSprite(bf.Entity):
6
+ class AnimatedSprite(bf.Drawable):
7
7
  def __init__(self, size: Optional[Tuple[int, int]] = None,*args,**kwargs) -> None:
8
8
  super().__init__(size, no_surface=True,*args,**kwargs)
9
9
  self.float_counter: float = 0
batFramework/character.py CHANGED
@@ -3,7 +3,7 @@ from .stateMachine import State
3
3
  from .animatedSprite import AnimatedSprite
4
4
  from .dynamicEntity import DynamicEntity
5
5
 
6
- class Character(AnimatedSprite,DynamicEntity):
6
+ class Character(DynamicEntity,AnimatedSprite):
7
7
  def __init__(self,*args,**kwargs) -> None:
8
8
  super().__init__(*args,**kwargs)
9
9
  self.state_machine = bf.StateMachine(self)
batFramework/constants.py CHANGED
@@ -4,6 +4,8 @@ import pygame
4
4
  class Constants:
5
5
  SCREEN: pygame.Surface = None
6
6
  RESOLUTION: tuple[int, int] = (1280, 720)
7
+ WIDTH = 1280
8
+ HEIGHT = 720
7
9
  VSYNC = 0
8
10
  FLAGS: int = pygame.SCALED | pygame.RESIZABLE
9
11
  FPS: int = 60
@@ -18,6 +20,8 @@ class Constants:
18
20
  @staticmethod
19
21
  def set_resolution(resolution: tuple[int, int]):
20
22
  Constants.RESOLUTION = resolution
23
+ Constants.WIDTH = resolution[0]
24
+ Constants.HEIGHT = resolution[1]
21
25
 
22
26
  @staticmethod
23
27
  def set_default_cursor(cursor: pygame.Cursor):
batFramework/cutscene.py CHANGED
@@ -1,5 +1,5 @@
1
1
  import batFramework as bf
2
- from typing import TYPE_CHECKING
2
+ from typing import TYPE_CHECKING,Self
3
3
 
4
4
  class CutsceneBlock: ...
5
5
 
@@ -75,13 +75,15 @@ class Cutscene:
75
75
  def init_blocks(self):
76
76
  pass
77
77
 
78
- def add_blocks(self, *blocks: CutsceneBlock):
78
+ def add_blocks(self, *blocks: CutsceneBlock)->Self:
79
79
  self.cutscene_blocks.extend(blocks)
80
-
81
- def add_end_blocks(self, *blocks: CutsceneBlock):
80
+ return self
81
+
82
+ def add_end_blocks(self, *blocks: CutsceneBlock)->Self:
82
83
  _ = [block.set_parent_cutscene(self) for block in blocks]
83
84
  self.end_blocks.extend(blocks)
84
-
85
+ return self
86
+
85
87
  def get_scene_at(self, index):
86
88
  return bf.CutsceneManager().manager.scenes[index]
87
89
 
@@ -0,0 +1,75 @@
1
+ from typing import Any, Self
2
+ import pygame
3
+ import batFramework as bf
4
+ from .entity import Entity
5
+
6
+
7
+ class Drawable(Entity):
8
+ """
9
+ Basic entity class
10
+ """
11
+
12
+ def __init__(
13
+ self,
14
+ size: None | tuple[int, int] = None,
15
+ surface_flags: int = 0,
16
+ convert_alpha: bool = False,
17
+ *args,
18
+ **kwargs,
19
+ ) -> None:
20
+ super().__init__()
21
+ self.visible: bool = True
22
+ self.render_order: int = 0
23
+ self.rect.size = (10, 10) if size is None else size
24
+ self.convert_alpha: bool = convert_alpha
25
+ self.surface_flags: int = surface_flags
26
+ self.blit_flags: int = 0
27
+ self.surface: pygame.Surface = pygame.Surface(self.rect.size, surface_flags)
28
+ if convert_alpha:
29
+ self.surface = self.surface.convert_alpha()
30
+ self.surface.fill((0, 0, 0, 0))
31
+
32
+ def set_alpha(self, alpha: int) -> Self:
33
+ self.surface.set_alpha(min(max(0, alpha), 255))
34
+ return self
35
+
36
+ def get_alpha(self) -> int:
37
+ return self.surface.get_alpha()
38
+
39
+ def set_surface_flags(self, surface_flags: int) -> Self:
40
+ self.surface_flags = surface_flags
41
+ return self
42
+
43
+ def set_convert_alpha(self, value: bool) -> Self:
44
+ self.convert_alpha = value
45
+ return self
46
+
47
+ def set_blit_flags(self, blit_flags: int) -> Self:
48
+ self.blit_flags = blit_flags
49
+ return self
50
+
51
+ def get_debug_outlines(self):
52
+ if self.visible:
53
+ yield (self.rect, self.debug_color)
54
+
55
+ def set_render_order(self, render_order: int) -> Self:
56
+ self.render_order = render_order
57
+ if self.parent_scene:
58
+ self.parent_scene.sort_entities()
59
+ return self
60
+
61
+ def set_visible(self, value: bool) -> Self:
62
+ self.visible = value
63
+ return self
64
+
65
+ def draw(self, camera: bf.Camera) -> None:
66
+ """
67
+ Draw the entity onto the camera surface
68
+ """
69
+ if not self.visible or not camera.rect.colliderect(self.rect):
70
+ return
71
+ camera.surface.blit(
72
+ self.surface,
73
+ camera.world_to_screen(self.rect),
74
+ special_flags=self.blit_flags,
75
+ )
batFramework/entity.py CHANGED
@@ -1,74 +1,124 @@
1
1
  from typing import Any, Self
2
2
  import pygame
3
3
  import batFramework as bf
4
- from .object import Object
5
-
6
-
7
- class Entity(Object):
8
- """
9
- Basic entity class
10
- """
11
-
12
- def __init__(
13
- self,
14
- size: None | tuple[int, int] = None,
15
- surface_flags: int = 0,
16
- convert_alpha: bool = False,
17
- *args,
18
- **kwargs,
19
- ) -> None:
20
- super().__init__()
21
- self.visible: bool = True
22
- self.rect.size = (10, 10) if size is None else size
23
- self.convert_alpha: bool = convert_alpha
24
- self.surface_flags: int = surface_flags
25
- self.blit_flags: int = 0
26
- self.surface: pygame.Surface = pygame.Surface(self.rect.size, surface_flags)
27
- if convert_alpha:
28
- self.surface = self.surface.convert_alpha()
29
- self.surface.fill((0, 0, 0, 0))
30
-
31
- def set_alpha(self, alpha: int) -> Self:
32
- self.surface.set_alpha(min(max(0, alpha), 255))
33
- return self
4
+ from typing import TYPE_CHECKING
34
5
 
35
- def get_alpha(self) -> int:
36
- return self.surface.get_alpha()
6
+ if TYPE_CHECKING:
7
+ from .camera import Camera
37
8
 
38
- def set_surface_flags(self, surface_flags: int) -> Self:
39
- self.surface_flags = surface_flags
40
- return self
41
9
 
42
- def set_convert_alpha(self, value: bool) -> Self:
43
- self.convert_alpha = value
10
+ class Entity:
11
+ __count = 0
12
+ __available_uid = set()
13
+ __used_uid = set()
14
+
15
+ def __init__(self) -> None:
16
+ self.rect = pygame.FRect(0, 0, 0, 0)
17
+ self.tags: list[str] = []
18
+ self.parent_scene: bf.Scene | None = None
19
+ self.debug_color: tuple | str = "red"
20
+ self.uid: int = Entity.__count
21
+ Entity.__used_uid.add(self.uid)
22
+
23
+ if Entity.__available_uid:
24
+ self.name = Entity.__available_uid.pop()
25
+ else:
26
+ self.name = Entity.__count
27
+ Entity.__count += 1
28
+
29
+ def __del__(self):
30
+ Entity.__available_uid.add(self.uid)
31
+
32
+ def set_position(self, x, y) -> Self:
33
+ self.rect.topleft = x, y
44
34
  return self
45
35
 
46
- def set_blit_flags(self, blit_flags: int) -> Self:
47
- self.blit_flags = blit_flags
36
+ def set_center(self, x, y) -> Self:
37
+ self.rect.center = x, y
48
38
  return self
49
39
 
50
40
  def get_debug_outlines(self):
51
- if self.visible:
52
- yield (self.rect, self.debug_color)
41
+ yield (self.rect, self.debug_color)
53
42
 
54
- def set_render_order(self, render_order: int) -> Self:
55
- self.render_order = render_order
56
- if self.parent_scene:
57
- self.parent_scene.sort_entities()
43
+ def set_debug_color(self, color) -> Self:
44
+ self.debug_color = color
58
45
  return self
59
46
 
60
- def set_visible(self, value: bool) -> Self:
61
- self.visible = value
47
+ def set_parent_scene(self, scene) -> Self:
48
+ if scene == self.parent_scene:
49
+ return self
50
+ if self.parent_scene is not None:
51
+ self.do_when_removed()
52
+ self.parent_scene = scene
53
+ if scene is not None:
54
+ self.do_when_added()
62
55
  return self
63
56
 
64
- def draw(self, camera: bf.Camera) -> None:
57
+ def do_when_added(self):
58
+ pass
59
+
60
+ def do_when_removed(self):
61
+ pass
62
+
63
+ def set_uid(self, uid: int) -> Self:
64
+ if uid in Entity.__used_uid:
65
+ print(f"set_uid error : UID '{uid}' is already in use")
66
+ return self
67
+ self.uid = uid
68
+ if uid in Entity.__used_uid:
69
+ Entity.__used_uid.remove(uid)
70
+ Entity.__used_uid.add(uid)
71
+ return self
72
+
73
+ def add_tags(self, *tags) -> Self:
74
+ for tag in tags:
75
+ if tag not in self.tags:
76
+ self.tags.append(tag)
77
+ self.tags.sort()
78
+ return self
79
+
80
+ def remove_tags(self, *tags):
81
+ self.tags = [tag for tag in self.tags if tag not in tags]
82
+
83
+ def has_tags(self, *tags) -> bool:
84
+ return all(tag in self.tags for tag in tags)
85
+
86
+ def get_tags(self) -> list[str]:
87
+ return self.tags
88
+
89
+ def process_event(self, event: pygame.Event) -> bool:
65
90
  """
66
- Draw the entity onto the camera surface
91
+ Returns bool : True if the method is blocking (no propagation to next Entity of the scene)
67
92
  """
68
- if not self.visible or not camera.rect.colliderect(self.rect):
93
+ if event.consumed:
69
94
  return
70
- camera.surface.blit(
71
- self.surface,
72
- camera.world_to_screen(self.rect),
73
- special_flags=self.blit_flags,
74
- )
95
+ self.do_process_actions(event)
96
+ self.do_handle_event(event)
97
+
98
+ def do_process_actions(self, event: pygame.Event) -> None:
99
+ """
100
+ Process entity actions you may have set
101
+ """
102
+
103
+ def do_reset_actions(self) -> None:
104
+ """
105
+ Reset entity actions you may have set
106
+ """
107
+
108
+ def do_handle_event(self, event: pygame.Event):
109
+ """
110
+ Handle specific events with no action support
111
+ """
112
+ return False
113
+
114
+ def update(self, dt: float) -> None:
115
+ """
116
+ Update method to be overriden by subclasses of Entity (must call do_update and do_reset_actions)
117
+ """
118
+ self.do_update(dt)
119
+ self.do_reset_actions()
120
+
121
+ def do_update(self, dt: float) -> None:
122
+ """
123
+ Update method to be overriden for specific behavior by the end user
124
+ """
@@ -174,7 +174,7 @@ class Container(Shape, InteractiveWidget):
174
174
  self.paint()
175
175
  self.dirty_surface = False
176
176
 
177
- bf.Entity.draw(self, camera)
177
+ bf.Drawable.draw(self, camera)
178
178
 
179
179
  if self.clip_children:
180
180
  new_clip = camera.world_to_screen(self.get_padded_rect())
@@ -72,7 +72,7 @@ class Debugger(Label):
72
72
  def update(self, dt: float) -> None:
73
73
  if not self.parent_scene:
74
74
  return
75
- if self.parent_scene.get_sharedVar("debug_mode") != bf.debugMode.DEBUGGER:
75
+ if bf.ResourceManager().get_sharedVar("debug_mode") != bf.debugMode.DEBUGGER:
76
76
  self.set_visible(False)
77
77
  return
78
78
  self.set_visible(True)
batFramework/gui/label.py CHANGED
@@ -37,7 +37,6 @@ class Label(Shape):
37
37
  self.text_rect = pygame.FRect(0, 0, 0, 0)
38
38
  # text surface (result of font.render)
39
39
  self.text_surface: pygame.Surface = pygame.Surface((0, 0))
40
- self.do_caching: bool = False
41
40
 
42
41
  self.show_text_outline: bool = False
43
42
 
@@ -54,21 +53,9 @@ class Label(Shape):
54
53
  self.set_autoresize(True)
55
54
  self.set_font(force=True)
56
55
 
57
- @staticmethod
58
- def clear_cache():
59
- Label._text_cache = {}
60
-
61
56
  def __str__(self) -> str:
62
57
  return f"Label({repr(self.text)})"
63
58
 
64
- def enable_caching(self) -> Self:
65
- self.do_caching = True
66
- return self
67
-
68
- def disable_caching(self) -> Self:
69
- self.do_caching = False
70
- return self
71
-
72
59
  def set_text_color(self, color) -> Self:
73
60
  self.text_color = color
74
61
  self.dirty_surface = True
@@ -205,35 +192,26 @@ class Label(Shape):
205
192
  return self.text
206
193
 
207
194
  def _render_font(self, params: dict) -> pygame.Surface:
208
- key = tuple(params.values())
209
-
210
- cached_value = Label._text_cache.get(key, None)
211
195
 
212
196
  if self.draw_mode == bf.drawMode.SOLID:
213
- if cached_value is None:
214
- params.pop("font_name")
215
-
216
- # save old settings
217
- old_italic = self.font_object.get_italic()
218
- old_bold = self.font_object.get_bold()
219
- old_underline = self.font_object.get_underline()
220
-
221
- # setup font
222
- self.font_object.set_italic(self.is_italic)
223
- self.font_object.set_bold(self.is_bold)
224
- self.font_object.set_underline(self.is_underlined)
225
-
226
- surf = self.font_object.render(**params)
227
-
228
- # reset font
229
- self.font_object.set_italic(old_italic)
230
- self.font_object.set_bold(old_bold)
231
- self.font_object.set_underline(old_underline)
232
-
233
- if self.do_caching:
234
- Label._text_cache[key] = surf
235
- else:
236
- surf = cached_value
197
+ params.pop("font_name")
198
+
199
+ # save old settings
200
+ old_italic = self.font_object.get_italic()
201
+ old_bold = self.font_object.get_bold()
202
+ old_underline = self.font_object.get_underline()
203
+
204
+ # setup font
205
+ self.font_object.set_italic(self.is_italic)
206
+ self.font_object.set_bold(self.is_bold)
207
+ self.font_object.set_underline(self.is_underlined)
208
+
209
+ surf = self.font_object.render(**params)
210
+
211
+ # reset font
212
+ self.font_object.set_italic(old_italic)
213
+ self.font_object.set_bold(old_bold)
214
+ self.font_object.set_underline(old_underline)
237
215
  else:
238
216
  params.pop("font_name")
239
217
  surf = self.font_object.render(**params)
batFramework/gui/root.py CHANGED
@@ -95,8 +95,6 @@ class Root(InteractiveWidget):
95
95
  return self
96
96
 
97
97
  def do_handle_event(self, event):
98
- if not self.parent_scene.get_sharedVar("player_has_control"):
99
- return
100
98
  if self.focused:
101
99
  if event.type == pygame.KEYDOWN:
102
100
  if self.focused.on_key_down(event.key):
@@ -130,8 +128,6 @@ class Root(InteractiveWidget):
130
128
 
131
129
  def update(self, dt: float) -> None:
132
130
  super().update(dt)
133
- if not self.parent_scene.get_sharedVar("player_has_control",True):
134
- return
135
131
  old = self.hovered
136
132
  transposed = self.drawing_camera.screen_to_world(pygame.mouse.get_pos())
137
133
  self.hovered = self.top_at(*transposed) if self.top_at(*transposed) else None
@@ -145,8 +141,6 @@ class Root(InteractiveWidget):
145
141
 
146
142
  def draw(self, camera: bf.Camera) -> None:
147
143
  super().draw(camera)
148
- if not self.parent_scene.get_sharedVar("player_has_control"):
149
- return
150
144
  if (
151
145
  self.parent_scene
152
146
  and self.parent_scene.active
@@ -18,7 +18,7 @@ class WidgetMeta(type):
18
18
  return obj
19
19
 
20
20
 
21
- class Widget(bf.Entity, metaclass=WidgetMeta):
21
+ class Widget(bf.Drawable, metaclass=WidgetMeta):
22
22
  def __init__(self, *args, **kwargs) -> None:
23
23
  super().__init__(*args, **kwargs)
24
24
  self.children: list["Widget"] = []
batFramework/manager.py CHANGED
@@ -1,23 +1,24 @@
1
1
  import batFramework as bf
2
2
  import pygame
3
3
  import asyncio
4
- import random
5
4
 
6
5
  class Manager(bf.SceneManager):
7
6
  def __init__(self, *initial_scene_list) -> None:
8
- # random.seed("random")
9
7
  super().__init__()
10
- self._screen: pygame.Surface | None = bf.const.SCREEN
11
- self._timeManager = bf.TimeManager()
12
- self._cutsceneManager = bf.CutsceneManager()
13
- self._cutsceneManager.set_manager(self)
14
- self._clock: pygame.Clock = pygame.Clock()
15
- self._is_async_running : bool = False
16
- self._running = False
8
+ self.debug_mode: bf.enums.debugMode = bf.debugMode.HIDDEN
9
+ self.screen: pygame.Surface | None = bf.const.SCREEN
10
+ self.timeManager = bf.TimeManager()
11
+ self.cutsceneManager = bf.CutsceneManager()
12
+ self.cutsceneManager.set_manager(self)
13
+ self.clock: pygame.Clock = pygame.Clock()
14
+ self.is_async_running : bool = False
15
+ self.running = False
17
16
  pygame.mouse.set_cursor(bf.const.DEFAULT_CURSOR)
18
17
  self.do_pre_init()
19
18
  self.init_scenes(*initial_scene_list)
20
- self.set_sharedVar("clock", self._clock)
19
+ bf.ResourceManager().set_sharedVar("clock", self.clock)
20
+ bf.ResourceManager().set_sharedVar("debug_mode", self.debug_mode)
21
+
21
22
  self.do_init()
22
23
 
23
24
  @staticmethod
@@ -39,14 +40,14 @@ class Manager(bf.SceneManager):
39
40
  print("=" * 50)
40
41
 
41
42
  # Print the timers information
42
- print(self._timeManager)
43
+ print(self.timeManager)
43
44
 
44
45
  # End with a visual separator
45
46
  print("=" * 50 + "\n")
46
47
 
47
48
 
48
49
  def get_fps(self) -> float:
49
- return self._clock.get_fps()
50
+ return self.clock.get_fps()
50
51
 
51
52
  def do_init(self) -> None:
52
53
  pass
@@ -55,67 +56,67 @@ class Manager(bf.SceneManager):
55
56
  pass
56
57
 
57
58
  def stop(self) -> None:
58
- self._running = False
59
+ self.running = False
59
60
 
60
61
  async def run_async(self):
61
- if self._running:
62
+ if self.running:
62
63
  print("Error : Already running")
63
64
  return
64
- self._is_async_running = True
65
- self._running = True
65
+ self.is_async_running = True
66
+ self.running = True
66
67
  dt: float = 0
67
- while self._running:
68
+ while self.running:
68
69
  for event in pygame.event.get():
69
70
  event.consumed = False
70
71
  self.process_event(event)
71
72
  if not event.consumed:
72
73
  if event.type == pygame.QUIT:
73
- self._running = False
74
+ self.running = False
74
75
  break
75
76
  if event.type == pygame.VIDEORESIZE and not (
76
77
  bf.const.FLAGS & pygame.SCALED
77
78
  ):
78
79
  bf.const.set_resolution((event.w, event.h))
79
80
  # update
80
- self._timeManager.update(dt)
81
- self._cutsceneManager.update(dt)
81
+ self.timeManager.update(dt)
82
+ self.cutsceneManager.update(dt)
82
83
  self.update(dt)
83
84
  # render
84
- self._screen.fill((0, 0, 0))
85
- self.draw(self._screen)
85
+ self.screen.fill((0, 0, 0))
86
+ self.draw(self.screen)
86
87
  pygame.display.flip()
87
- dt = self._clock.tick(bf.const.FPS) / 1000
88
+ dt = self.clock.tick(bf.const.FPS) / 1000
88
89
  # dt = min(dt, 0.02) dirty fix for dt being too high when window not focused for a long time
89
90
  await asyncio.sleep(0)
90
91
  pygame.quit()
91
92
 
92
93
 
93
94
  def run(self) -> None:
94
- if self._running:
95
+ if self.running:
95
96
  print("Error : Already running")
96
97
  return
97
- self._running = True
98
+ self.running = True
98
99
  dt: float = 0
99
- while self._running:
100
+ while self.running:
100
101
  for event in pygame.event.get():
101
102
  event.consumed = False
102
103
  self.process_event(event)
103
104
  if not event.consumed:
104
105
  if event.type == pygame.QUIT:
105
- self._running = False
106
+ self.running = False
106
107
  break
107
108
  if event.type == pygame.VIDEORESIZE and not (
108
109
  bf.const.FLAGS & pygame.SCALED
109
110
  ):
110
111
  bf.const.set_resolution((event.w, event.h))
111
112
  # update
112
- self._timeManager.update(dt)
113
- self._cutsceneManager.update(dt)
113
+ self.timeManager.update(dt)
114
+ self.cutsceneManager.update(dt)
114
115
  self.update(dt)
115
116
  # render
116
- self._screen.fill((0, 0, 0))
117
- self.draw(self._screen)
117
+ self.screen.fill((0, 0, 0))
118
+ self.draw(self.screen)
118
119
  pygame.display.flip()
119
- dt = self._clock.tick(bf.const.FPS) / 1000
120
+ dt = self.clock.tick(bf.const.FPS) / 1000
120
121
  # dt = min(dt, 0.02) dirty fix for dt being too high when window not focused for a long time
121
122
  pygame.quit()
batFramework/particle.py CHANGED
@@ -78,7 +78,7 @@ class DirectionalParticle(BasicParticle):
78
78
  super().update_surface()
79
79
 
80
80
 
81
- class ParticleGenerator(bf.Entity):
81
+ class ParticleGenerator(bf.Drawable):
82
82
  def __init__(self) -> None:
83
83
  super().__init__((0, 0))
84
84
  self.particles: list[Particle] = []
batFramework/scene.py CHANGED
@@ -70,35 +70,6 @@ class Scene:
70
70
  """Get the scene index."""
71
71
  return self.scene_index
72
72
 
73
- def set_sharedVar(self, name: str, value: Any) -> bool:
74
- """
75
- Set a shared variable in the manager.
76
-
77
- Args:
78
- name: Name of the shared variable.
79
- value: Value to set.
80
-
81
- Returns:
82
- bool: True if setting was successful, False otherwise.
83
- """
84
- if not self.manager:
85
- return False
86
- return self.manager.set_sharedVar(name, value)
87
-
88
- def get_sharedVar(self, name: str, error_value=None) -> Any:
89
- """
90
- Get a shared variable from the manager.
91
-
92
- Args:
93
- name: Name of the shared variable.
94
-
95
- Returns:
96
- Any: Value of the shared variable.
97
- """
98
- if not self.manager:
99
- return error_value
100
- return self.manager.get_sharedVar(name, error_value)
101
-
102
73
  def do_when_added(self):
103
74
  pass
104
75
 
@@ -277,7 +248,6 @@ class Scene:
277
248
  self.actions.reset()
278
249
  self.early_actions.reset()
279
250
 
280
-
281
251
  if self.entities_to_add:
282
252
  for e in self.entities_to_add:
283
253
  self.world_entities[e] = None
@@ -337,7 +307,7 @@ class Scene:
337
307
 
338
308
  def _draw_camera(self, camera: bf.Camera, entity_list):
339
309
  _ = [entity.draw(camera) for entity in entity_list]
340
- debugMode = self.manager.debug_mode
310
+ debugMode = bf.ResourceManager().get_sharedVar("debug_mode")
341
311
  # Draw outlines for world entities if required
342
312
  if debugMode == bf.debugMode.OUTLINES:
343
313
  [self.debug_entity(e, camera) for e in entity_list]
@@ -355,15 +325,12 @@ class Scene:
355
325
  self.set_active(True)
356
326
  self.set_visible(True)
357
327
  self.root.clear_hovered()
358
- # self.root.clear_focused()
359
328
  self.root.build()
360
329
  bf.TimeManager().activate_register(self.name)
361
330
  self.do_on_enter()
362
- # self.root.visit(lambda e : e.resolve_constraints())
363
331
 
364
332
  def on_exit(self):
365
333
  self.root.clear_hovered()
366
- # self.root.clear_focused()
367
334
  self.set_active(False)
368
335
  self.set_visible(False)
369
336
  self.actions.hard_reset()
@@ -2,7 +2,6 @@ import batFramework as bf
2
2
  import pygame
3
3
  from typing import Self
4
4
 
5
-
6
5
  def swap(lst, index1, index2):
7
6
  lst[index1], lst[index2] = lst[index2], lst[index1]
8
7
 
@@ -11,11 +10,6 @@ class SceneManager:
11
10
  def __init__(self) -> None:
12
11
  self.scenes: list[bf.Scene] = []
13
12
  self.shared_events = {pygame.WINDOWRESIZED}
14
-
15
- self.set_sharedVar("in_cutscene", False)
16
- self.set_sharedVar("player_has_control", True)
17
- self.old_player_control = True
18
- self.debug_mode: bf.enums.debugMode = bf.debugMode.HIDDEN
19
13
  self.current_transitions: dict[str, bf.transition.Transition] = {}
20
14
 
21
15
  def init_scenes(self, *initial_scenes:bf.Scene):
@@ -23,7 +17,6 @@ class SceneManager:
23
17
  s.set_scene_index(index)
24
18
  for s in reversed(initial_scenes):
25
19
  self.add_scene(s)
26
- # self.scenes = list(initial_scenes)
27
20
  self.set_scene(initial_scenes[0].get_name())
28
21
  self.update_scene_states()
29
22
 
@@ -38,7 +31,7 @@ class SceneManager:
38
31
  Print detailed information about the current state of the scenes and shared variables.
39
32
  """
40
33
 
41
- def format_scene_info(scene):
34
+ def format_scene_info(scene:bf.Scene):
42
35
  status = 'Active' if scene.active else 'Inactive'
43
36
  visibility = 'Visible' if scene.visible else 'Invisible'
44
37
  return f"{scene.name:<30} | {status:<8} | {visibility:<10} | Index={scene.scene_index}"
@@ -78,13 +71,6 @@ class SceneManager:
78
71
 
79
72
  print("=" * 50 + "\n")
80
73
 
81
-
82
- def set_sharedVar(self, name, value) -> None:
83
- bf.ResourceManager().set_sharedVar(name,value)
84
-
85
- def get_sharedVar(self, name, error_value=None):
86
- return bf.ResourceManager().get_sharedVar(name, error_value)
87
-
88
74
  def get_current_scene_name(self) -> str:
89
75
  """get the name of the current scene"""
90
76
  return self.scenes[0].get_name()
@@ -106,10 +92,10 @@ class SceneManager:
106
92
  def remove_scene(self, name: str):
107
93
  self.scenes = [s for s in self.scenes if s.name != name]
108
94
 
109
- def has_scene(self, name):
95
+ def has_scene(self, name:str):
110
96
  return any(name == scene.name for scene in self.scenes)
111
97
 
112
- def get_scene(self, name):
98
+ def get_scene(self, name:str):
113
99
  if not self.has_scene(name):
114
100
  return None
115
101
  for scene in self.scenes:
@@ -150,8 +136,6 @@ class SceneManager:
150
136
  def _start_transition(self, target_scene: bf.Scene):
151
137
  target_scene.set_active(True)
152
138
  target_scene.set_visible(True)
153
- self.old_player_control = bool(self.get_sharedVar("player_has_control"))
154
- self.set_sharedVar("player_has_control", False)
155
139
 
156
140
  def _end_transition(self, scene_name, index):
157
141
  self.set_scene(scene_name, index, True)
@@ -177,11 +161,10 @@ class SceneManager:
177
161
  self.scenes[index].do_on_enter_early()
178
162
  target_scene.on_enter()
179
163
 
180
- self.set_sharedVar("player_has_control", self.old_player_control)
181
164
 
182
165
 
183
166
  def cycle_debug_mode(self):
184
- current_index = self.debug_mode.value
167
+ current_index = bf.ResourceManager().get_sharedVar("debug_mode").value
185
168
  next_index = (current_index + 1) % len(bf.debugMode)
186
169
  return bf.debugMode(next_index)
187
170
 
@@ -193,8 +176,7 @@ class SceneManager:
193
176
  and event.type == pygame.KEYDOWN
194
177
  ):
195
178
  if event.key == pygame.K_d:
196
- self.debug_mode = self.cycle_debug_mode()
197
- self.set_sharedVar("debug_mode", self.debug_mode)
179
+ bf.ResourceManager().set_sharedVar("debug_mode", self.cycle_debug_mode())
198
180
  return
199
181
  if event.key == pygame.K_p:
200
182
  self.print_status()
batFramework/sprite.py CHANGED
@@ -3,11 +3,11 @@ import pygame
3
3
  from typing import Self
4
4
 
5
5
 
6
- class Sprite(bf.Entity):
6
+ class Sprite(bf.Drawable):
7
7
  def __init__(
8
8
  self,
9
- path=None,
10
9
  size: None | tuple[int, int] = None,
10
+ path=None,
11
11
  convert_alpha: bool = True,
12
12
  ):
13
13
  self.original_surface: pygame.Surface = None
@@ -1,7 +1,5 @@
1
1
  import batFramework as bf
2
2
  from typing import Self
3
-
4
-
5
3
  from typing import Callable, Union, Self
6
4
 
7
5
 
batFramework/utils.py CHANGED
@@ -1,17 +1,16 @@
1
1
  import pygame
2
- from enum import Enum
3
- import os
4
2
  import batFramework as bf
5
- import json
3
+ import random
6
4
  from .enums import *
7
5
  import re
8
- from typing import Callable, TYPE_CHECKING, Any
6
+ from typing import Callable, TYPE_CHECKING
9
7
  from functools import cache
10
8
  if TYPE_CHECKING:
11
- from .object import Object
9
+ from .drawable import Drawable
12
10
  from .entity import Entity
13
11
 
14
12
 
13
+
15
14
  class Singleton(type):
16
15
  _instances = {}
17
16
 
@@ -28,9 +27,15 @@ class Utils:
28
27
  surface: pygame.Surface, split_size: tuple[int, int], func=None
29
28
  ) -> dict[tuple[int, int], pygame.Surface]:
30
29
  """
31
- Splits a surface into subsurfaces and returns a dictionnary of them
32
- with their tuple coordinates as keys.
33
- Exemple : '(0,0) : Surface'
30
+ Splits a surface into subsurfaces based on a given size and returns a dictionary of them with their coordinates as keys.
31
+
32
+ Args:
33
+ surface (pygame.Surface): The surface to be split.
34
+ split_size (tuple[int, int]): The size of each subsurface (width, height).
35
+ func (callable, optional): A function to apply to each subsurface. Defaults to None.
36
+
37
+ Returns:
38
+ dict[tuple[int, int], pygame.Surface]: A dictionary with (x, y) coordinates as keys and the corresponding subsurfaces as values.
34
39
  """
35
40
  width, height = surface.get_size()
36
41
  res = {}
@@ -47,6 +52,19 @@ class Utils:
47
52
 
48
53
  @staticmethod
49
54
  def filter_text(text_mode: textMode):
55
+ """
56
+ Filters a string based on the specified text mode.
57
+
58
+ Args:
59
+ text_mode (textMode): Mode specifying the type of filtering (ALPHABETICAL, NUMERICAL, ALPHANUMERICAL).
60
+
61
+ Returns:
62
+ callable: A function that takes a string and removes all characters not allowed by the text mode.
63
+
64
+ Raises:
65
+ ValueError: If an unsupported text mode is provided.
66
+ """
67
+
50
68
  if text_mode == textMode.ALPHABETICAL:
51
69
  pattern = re.compile(r"[^a-zA-Z]")
52
70
  elif text_mode == textMode.NUMERICAL:
@@ -66,15 +84,20 @@ class Utils:
66
84
  @cache
67
85
  def create_spotlight(inside_color, outside_color, radius, radius_stop=None, dest_surf=None,size=None):
68
86
  """
69
- Draws a circle spotlight centered on a surface
70
- inner color on the center
71
- gradient towards outside color from radius to radius stop
72
- surface background is made transparent
73
- if des_surf is None:
74
- if size is None : size is radius_stop*radius_stop
75
- returns the newly created surface of size 'size' with the spotlight drawn
76
-
87
+ Creates a spotlight effect on a surface with a gradient from inside_color to outside_color.
88
+
89
+ Args:
90
+ inside_color (tuple[int, int, int]): RGB color at the center of the spotlight.
91
+ outside_color (tuple[int, int, int]): RGB color at the outer edge of the spotlight.
92
+ radius (int): Radius of the inner circle.
93
+ radius_stop (int, optional): Radius where the spotlight ends. Defaults to the value of radius.
94
+ dest_surf (pygame.Surface, optional): Surface to draw the spotlight on. Defaults to None.
95
+ size (tuple[int, int], optional): Size of the surface if dest_surf is None. Defaults to a square based on radius_stop.
96
+
97
+ Returns:
98
+ pygame.Surface: The surface with the spotlight effect drawn on it.
77
99
  """
100
+
78
101
  if radius_stop is None:
79
102
  radius_stop = radius
80
103
  diameter = radius_stop * 2
@@ -103,6 +126,18 @@ class Utils:
103
126
 
104
127
  @staticmethod
105
128
  def draw_spotlight(dest_surf:pygame.Surface,inside_color,outside_color,radius,radius_stop=None,center=None):
129
+ """
130
+ Draws a spotlight effect directly onto an existing surface.
131
+
132
+ Args:
133
+ dest_surf (pygame.Surface): The surface to draw the spotlight on.
134
+ inside_color (tuple[int, int, int]): RGB color at the center of the spotlight.
135
+ outside_color (tuple[int, int, int]): RGB color at the outer edge of the spotlight.
136
+ radius (int): Radius of the inner circle.
137
+ radius_stop (int, optional): Radius where the spotlight ends. Defaults to the value of radius.
138
+ center (tuple[int, int], optional): Center point of the spotlight. Defaults to the center of dest_surf.
139
+ """
140
+
106
141
  if radius_stop is None:
107
142
  radius_stop = radius
108
143
  center = dest_surf.get_rect().center if center is None else center
@@ -117,12 +152,34 @@ class Utils:
117
152
  pygame.draw.circle(dest_surf, inside_color, center, radius)
118
153
 
119
154
  @staticmethod
120
- def animate_move(entity:"Object", start_pos : tuple[float,float], end_pos:tuple[float,float])->Callable[[float],None]:
155
+ def animate_move(entity:"Entity", start_pos : tuple[float,float], end_pos:tuple[float,float])->Callable[[float],None]:
156
+ """
157
+ Creates a function to animate the movement of an entity from start_pos to end_pos.
158
+
159
+ Args:
160
+ entity (Entity): The entity to move.
161
+ start_pos (tuple[float, float]): The starting position of the entity.
162
+ end_pos (tuple[float, float]): The ending position of the entity.
163
+
164
+ Returns:
165
+ Callable[[float], None]: A function that updates the entity's position based on a progression value (0 to 1).
166
+ """
121
167
  def func(x):
122
168
  entity.set_center(start_pos[0]+(end_pos[0]-start_pos[0])*x,start_pos[1]+(end_pos[1]-start_pos[1])*x)
123
169
  return func
124
170
 
125
- def animate_move_to(entity: "Object", end_pos: tuple[float, float]) -> Callable[[float], None]:
171
+ def animate_move_to(entity: "Entity", end_pos: tuple[float, float]) -> Callable[[float], None]:
172
+ """
173
+ Creates a function to animate the movement of an entity to a specified end position, capturing the start position at the start of the animation.
174
+
175
+ Args:
176
+ entity (Entity): The entity to move.
177
+ end_pos (tuple[float, float]): The target position of the entity.
178
+
179
+ Returns:
180
+ Callable[[float], None]: A function that updates the entity's position based on a progression value (0 to 1).
181
+ """
182
+
126
183
  # Start position will be captured once when the animation starts
127
184
  start_pos = [None]
128
185
 
@@ -140,10 +197,52 @@ class Utils:
140
197
  return update_position
141
198
 
142
199
  @staticmethod
143
- def animate_alpha(entity:"Entity", start : int, end:int)->Callable[[float],None]:
200
+ def animate_alpha(entity:"Drawable", start : int, end:int)->Callable[[float],None]:
201
+ """
202
+ Creates a function to animate the alpha (transparency) of a drawable entity between a start and end value.
203
+
204
+ Args:
205
+ entity (Drawable): The entity to animate.
206
+ start (int): The starting alpha value (0 to 255).
207
+ end (int): The ending alpha value (0 to 255).
208
+
209
+ Returns:
210
+ Callable[[float], None]: A function that updates the entity's alpha based on a progression value (0 to 1).
211
+ """
144
212
  def func(x):
145
213
  entity.set_alpha(int(pygame.math.clamp(start+(end-start)*x,0,255)))
146
214
  return func
147
215
 
148
216
 
149
217
 
218
+ @staticmethod
219
+ def random_color(min_value: int = 0, max_value: int = 255) -> tuple[int, int, int]:
220
+ """
221
+ Generates a random color as an RGB tuple.
222
+
223
+ Args:
224
+ min_value (int): Minimum value for each RGB component (inclusive). Defaults to 0.
225
+ max_value (int): Maximum value for each RGB component (inclusive). Defaults to 255.
226
+
227
+ Returns:
228
+ tuple[int, int, int]: A tuple representing a random color in RGB format, with each component
229
+ between min_value and max_value.
230
+ """
231
+ return random.randint(min_value, max_value), random.randint(min_value, max_value), random.randint(min_value, max_value)
232
+
233
+ @staticmethod
234
+ def random_point_on_screen(margin: int = 0) -> tuple[int, int]:
235
+ """
236
+ Generates a random point on the screen, considering a margin from the edges.
237
+
238
+ Args:
239
+ margin (int): Margin from the screen edges, where the point won't be generated.
240
+ If margin is less than 0 or greater than the screen resolution, returns (0, 0).
241
+
242
+ Returns:
243
+ tuple[int, int]: A tuple representing a random point (x, y) on the screen within the screen
244
+ resolution minus the margin.
245
+ """
246
+ if margin < 0 or margin > bf.const.RESOLUTION[0] or margin > bf.const.RESOLUTION[1]:
247
+ return 0, 0
248
+ return random.randint(margin, bf.const.RESOLUTION[0] - margin), random.randint(margin, bf.const.RESOLUTION[1] - margin)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: batframework
3
- Version: 1.0.8a13
3
+ Version: 1.0.8a14
4
4
  Summary: Pygame framework for making games easier.
5
5
  Author-email: Turan Baturay <baturayturan@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/TuranBaturay/batFramework
@@ -1,63 +1,63 @@
1
- batFramework/__init__.py,sha256=z-FvSCPuPSJw3y4VnvujiKS9NeqqjD07QmpT_rjwZFI,2542
1
+ batFramework/__init__.py,sha256=DTeryYh2C-cZhmO6GQqfy-Lyjzdpa-KobxvQpIY1meM,2580
2
2
  batFramework/action.py,sha256=919IVYKviLyVYDtQL7oZvlVuE_aodjJCuwz6fGi5sCk,8420
3
3
  batFramework/actionContainer.py,sha256=qy6-YY3iX26KJ8NqFMSYo6JExohD8HFk0sC1qhb7qA8,2602
4
- batFramework/animatedSprite.py,sha256=aHv3a1m6ilhk1fXkWrkDRj9ud1snuR0wt1DUvGstLro,4240
4
+ batFramework/animatedSprite.py,sha256=IWE8zUgpFaqQPUr7iOUo7TJ_E10aUaMNqlIqv8dW87E,4242
5
5
  batFramework/animation.py,sha256=_XcH6r3TVQZUcLbhzUnTNlXrjy-J-nYiRmFpxvTYEoc,1934
6
6
  batFramework/audioManager.py,sha256=8tKSf4huZe5tgH98qHlKoFNjXPGDQNJho6PKfSCe7JA,3869
7
7
  batFramework/camera.py,sha256=u1EPSitZ9mEEa32yQB7K6ywnWgWCSumbhrc4HRjimEY,9406
8
- batFramework/character.py,sha256=uXbhMh8p-O8FXF0-gQW5JFiFiuDlgMZ_icgd5xudjyQ,789
9
- batFramework/constants.py,sha256=5PyZQZ4fCcLA8k_Upby9KGVF-3pnV2ZZ6t26CxiocPM,1102
10
- batFramework/cutscene.py,sha256=Jh2g-zC3zaUSQoO2uVOsirWkuLAUFugu2T8B_ob9IPQ,4007
8
+ batFramework/character.py,sha256=AK5sQLvAOY3X4-7vzeHeIO5WDFsubn_TADLYxmYc0Qo,789
9
+ batFramework/constants.py,sha256=E6Z-q4n_PXGxkP_Lr0l-BmWwDHGcabtlj45yrqifCKg,1217
10
+ batFramework/cutscene.py,sha256=FIry2kyDS1R8gHuEXKnsLz4XT30kf1Te1cjCLEK2Z24,4080
11
11
  batFramework/cutsceneBlocks.py,sha256=3jtmTpV48NKCu-Qgjg7KN5KnwXn0kycIQ7t7G3RH3VE,4862
12
+ batFramework/drawable.py,sha256=oGj3qAh27FsCeQP2lKVBSTZ6NL4OEl3qgy3oapI02-8,2164
12
13
  batFramework/dynamicEntity.py,sha256=6WcI6OveFNmrtOUYzmVMlT35Hz4MXeeRKzd1M3meL1Q,876
13
14
  batFramework/easingController.py,sha256=4N8GIp1fsaWBUlDxXx3SMwOq1Mrhn10MZZIO51_CRnk,1677
14
- batFramework/entity.py,sha256=34gYC6uEMmLkqWtoTG9bgMWRmHRSxhQfxXZKzWS7H2o,2127
15
+ batFramework/entity.py,sha256=vO42Hc2JAKtRAwOwMZNO27AtJR1Y1bJuhWEkr_K6TmY,3373
15
16
  batFramework/enums.py,sha256=re12gHw2g-5qtCNmGOfZbEC5cL5E8-FA79hfKGrI6-I,2078
16
17
  batFramework/fontManager.py,sha256=iCVavr4hpn0T4xsaUAzdNd01j5ebpcj30fvFHzm1g-M,2246
17
- batFramework/manager.py,sha256=PbpwCr9CoRszEepKx2R4jHt1_ZCzZOxMzdnO8H8767g,4162
18
- batFramework/object.py,sha256=_3sfRxrjaiDuVyz5Yk-fYJqYx-Ehq_3-dA4eDTb9kok,3329
19
- batFramework/particle.py,sha256=SD_DRqfhzlEeWlORDVPh1R__2_RplNcBujmqovN9Mww,3079
18
+ batFramework/manager.py,sha256=FXeBe7w98H1YHspTmXjyZe0-_QPXh6ZpBH84eYghDgo,4243
19
+ batFramework/particle.py,sha256=Aps9eJNdFag-TlduMSezKp4ocFQVvI6iZ98chhdhbgE,3081
20
20
  batFramework/renderGroup.py,sha256=_VDvmP4iB-XarFJo_Uh5YKwWq1cazHmOBmTXZkqKk40,2020
21
21
  batFramework/resourceManager.py,sha256=0cOIAFXT7UzzvgHn9QkWcXsTp8H2bIS70NvvgpBL2_4,3554
22
- batFramework/scene.py,sha256=2fXxwle68jzHwR2irKeWJYL95uAVmmU2edexo9p7fu4,12197
23
- batFramework/sceneManager.py,sha256=Jb51KksIDrZrXUafs0bgX73tY-8rglWW89Co48YGdCM,8037
22
+ batFramework/scene.py,sha256=0E7omgNUEl5Uhbx8iO3exyCy4p1MC7bSvqfwncW4KMw,11281
23
+ batFramework/sceneManager.py,sha256=ZH-vQbppwhg63EEdk7ahRpZ-K1TnB7BKVxD7y7IRSjM,7356
24
24
  batFramework/scrollingSprite.py,sha256=PPEieAaFcOLE_Lm7cnm3xc7XyLKopCPcDbXEfyThO48,4133
25
- batFramework/sprite.py,sha256=t_kSyUXGOSXQbSBwrKgBUTp5mITeFQbAKNzugjL5SgY,1625
25
+ batFramework/sprite.py,sha256=Cz8qzl8jR8y33DUSCObJQOk5e8PcZeavtFhBdR2TogU,1627
26
26
  batFramework/stateMachine.py,sha256=wC-5xbKvf-vGm_N16X9KhgMya5915GyVXL79uk5Bapw,1359
27
27
  batFramework/tileset.py,sha256=3AJBWHx90PC43BdLYCBFm811XBrMvWoB-nsUgyo6s-I,1728
28
- batFramework/time.py,sha256=iLDuHPQVNcPrNfqN6UP67d34HuC8Y42s6cdiTE53o7o,4989
28
+ batFramework/timeManager.py,sha256=XcqPs_74pjXafi6oNJe8W85SVfXTfPmOZOQyLOuyt8I,4987
29
29
  batFramework/transition.py,sha256=-1cyk-7Fbm0U2Z4Y2jjpLHwJ2khM1VxIMcfk2bBEo-M,6655
30
30
  batFramework/triggerZone.py,sha256=wIxkvO0cVVupQsJIPOD_-ofqwLnu1TLNK-n6oNXB1E8,579
31
- batFramework/utils.py,sha256=kj0qaOwpwvvPMD1DyOQTZLYeV-1lJ0dobeU2E49Rwg8,5215
31
+ batFramework/utils.py,sha256=G9TBEFW6Okm4H7ohikG1GIf6d1pdql8ZBdhkpK5yyys,9969
32
32
  batFramework/gui/__init__.py,sha256=17ij7mrCBCoehqCq1PV6MSXPOfMoLPmrV_G8d6ax4Tk,687
33
33
  batFramework/gui/button.py,sha256=Ozs6VKHf9FCQXQODDiLQywGN3hwfXtQ6s2I-rzdjnQg,429
34
34
  batFramework/gui/clickableWidget.py,sha256=2vS9GFSI3uufYQbaosXxTMs81vyVfQGz71AeZmf8vcY,7049
35
- batFramework/gui/container.py,sha256=wXjuhwCJc71KKSgY2cYgoRscAKB_hIw5N4njJk3Z9lk,5925
36
- batFramework/gui/debugger.py,sha256=XogxF3J31GO-DZZn6YBrgwpYA5WjadzEfHkQHeMLU7o,3925
35
+ batFramework/gui/container.py,sha256=4FOVYmxpn9HM_-J20YWR7u2sj9kwpJldb4Cfc-2hmi4,5927
36
+ batFramework/gui/debugger.py,sha256=0VTQvhSD5zLjbVhs97ldeBLXqnFLlua-zTCpWB9OBGQ,3928
37
37
  batFramework/gui/dialogueBox.py,sha256=3Z76l9obrpQImI8hjoBS_8G9sY3UILj2d3nJsaxtaI4,3221
38
38
  batFramework/gui/draggableWidget.py,sha256=SKG7oMInZ_GTnrbv2T0aqlppuiuLX1tkVSCQJtRMlk8,1392
39
39
  batFramework/gui/image.py,sha256=7IRvalA6QQz7SYI9h4y4-ryWa9EOxZM3sc10-OZyCPc,1770
40
40
  batFramework/gui/indicator.py,sha256=leCvxsGxt00-oTn0N5MTmLstLH9uLG3RjQ02KlXtZCQ,1549
41
41
  batFramework/gui/interactiveWidget.py,sha256=FAZnSlMIohduZIDTZh5U-_mh1AbgTF4sz-0oig4LWIQ,5760
42
- batFramework/gui/label.py,sha256=FmSY-ABOJKA47AFkbC8z99cOtJ1Ev6X12Ysdlq13iFI,11799
42
+ batFramework/gui/label.py,sha256=WWc_AdxC0ZJzyT478SrUAQUhERsihr2KsTRfVLdPOiQ,11178
43
43
  batFramework/gui/layout.py,sha256=3nprthjCJqUdD1qHN3lReYRb-4L0-t6v51JEO4NRcgo,8563
44
44
  batFramework/gui/meter.py,sha256=RFzAhSzR3O-Pw0wjdfApWGWFQSJoYa4WohkiREDAAJc,2395
45
45
  batFramework/gui/radioButton.py,sha256=rROl9mtUa-m220R5qZ85NBPZS7nPVx-azhqijJ-XhCo,2411
46
- batFramework/gui/root.py,sha256=K75814ct6AF4LF8cyzmtUmnTmSflJRnHVMGbpUXwmkE,5084
46
+ batFramework/gui/root.py,sha256=OsRmbh-UdIDrAqolwa5IV76iSksu_ByVo0WQp0YCSUQ,4812
47
47
  batFramework/gui/shape.py,sha256=Ros_-Mm2Q2CFauZFqFPh1QyyuZnNmg7C2PYbs7Cq41k,9347
48
48
  batFramework/gui/slider.py,sha256=5d3rfTYjDCDiM5prKu6DTemlGgji2FQ_vGuLzxoa5gU,8335
49
49
  batFramework/gui/style.py,sha256=OeLbft0RkIslQ2IcZpBeF6TaQDONIoBcAHj_Bkh9gFw,131
50
50
  batFramework/gui/styleManager.py,sha256=rALKJ-AmRbDAiyu8hVAYRAlkQxw677DiPoNKJZ4xtJ4,1245
51
51
  batFramework/gui/textInput.py,sha256=aTegghN6O3djL0eBEEij9DsEuZ1MyE61P51IzaLUUEg,9324
52
52
  batFramework/gui/toggle.py,sha256=XLFzCRaY7uOkKFVtR3y01wsNjLjZqrS1748IcvBRN2Q,3969
53
- batFramework/gui/widget.py,sha256=HGusTCgh3oAjtvrShzn2YxhFTGgNLsqGGhNilvRx-oo,13883
53
+ batFramework/gui/widget.py,sha256=2tehCiSLum0pwz3KNlrwc5SYvkZ7Hs0FiqtbmXuLoJs,13885
54
54
  batFramework/gui/constraints/__init__.py,sha256=qqXE8nnSrEvCSeHdqY8UYPZLetqdubFPI7IdZuh35QE,26
55
55
  batFramework/gui/constraints/constraints.py,sha256=nyPew0HIJ24rl4JcdBjUYu2aFynTryN9wqv1wKCo4ew,26873
56
56
  batFramework/templates/__init__.py,sha256=8XN-7JwYFKTRx_lnUL_If3spwgn5_2b7bwmrRRBPON0,46
57
57
  batFramework/templates/character.py,sha256=4UEcegUIeIgj48sVgzyRcT6yjpFOZ8Q_gHTtiB5j6kw,1348
58
58
  batFramework/templates/states.py,sha256=WeomVrQ10vHxVCj9Wnk1PcinKyb871uV910mQe287kI,5370
59
- batframework-1.0.8a13.dist-info/LICENCE,sha256=A65iXbMDbOxQLDNOODJLqA7o5RxszYlEqIgNSzBQRf4,1073
60
- batframework-1.0.8a13.dist-info/METADATA,sha256=OzyhEot1q6_IE63BpCHk_FVARFPT-Wq8J4DTNke2DSo,1695
61
- batframework-1.0.8a13.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
62
- batframework-1.0.8a13.dist-info/top_level.txt,sha256=vxAKBIk1oparFTxeXGBrgfIO7iq_YR5Fv1JvPVAIwmA,13
63
- batframework-1.0.8a13.dist-info/RECORD,,
59
+ batframework-1.0.8a14.dist-info/LICENCE,sha256=A65iXbMDbOxQLDNOODJLqA7o5RxszYlEqIgNSzBQRf4,1073
60
+ batframework-1.0.8a14.dist-info/METADATA,sha256=avsotELk-g0Ts9vQWsdLuFQzvXohhiarcDY9UodilRg,1695
61
+ batframework-1.0.8a14.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
62
+ batframework-1.0.8a14.dist-info/top_level.txt,sha256=vxAKBIk1oparFTxeXGBrgfIO7iq_YR5Fv1JvPVAIwmA,13
63
+ batframework-1.0.8a14.dist-info/RECORD,,
batFramework/object.py DELETED
@@ -1,123 +0,0 @@
1
- from typing import Any, Self
2
- import pygame
3
- import batFramework as bf
4
- from typing import TYPE_CHECKING
5
-
6
- if TYPE_CHECKING:
7
- from .camera import Camera
8
-
9
-
10
- class Object:
11
- __count = 0
12
- __available_uid = set()
13
- __used_uid = set()
14
-
15
- def __init__(self) -> None:
16
- self.rect = pygame.FRect(0, 0, 0, 0)
17
- self.tags: list[str] = []
18
- self.parent_scene: bf.Scene | None = None
19
- self.debug_color: tuple | str = "red"
20
- self.render_order: int = 0
21
- self.uid: int = Object.__count
22
- Object.__used_uid.add(self.uid)
23
-
24
- if Object.__available_uid:
25
- self.name = Object.__available_uid.pop()
26
- else:
27
- self.name = Object.__count
28
- Object.__count += 1
29
-
30
- def __del__(self):
31
- Object.__available_uid.add(self.uid)
32
-
33
- def set_position(self, x, y) -> Self:
34
- self.rect.topleft = x, y
35
- return self
36
-
37
- def set_center(self, x, y) -> Self:
38
- self.rect.center = x, y
39
- return self
40
-
41
- def get_debug_outlines(self):
42
- yield (self.rect, self.debug_color)
43
-
44
- def set_debug_color(self, color) -> Self:
45
- self.debug_color = color
46
- return self
47
-
48
- def set_parent_scene(self, scene) -> Self:
49
- if scene == self.parent_scene:
50
- return self
51
- if self.parent_scene is not None:
52
- self.do_when_removed()
53
- self.parent_scene = scene
54
- if scene is not None:
55
- self.do_when_added()
56
- return self
57
-
58
- def do_when_added(self):
59
- pass
60
-
61
- def do_when_removed(self):
62
- pass
63
-
64
- def set_uid(self, uid: int) -> Self:
65
- if uid in Object.__used_uid:
66
- print(f"set_uid error : UID '{uid}' is already in use")
67
- return self
68
- self.uid = uid
69
- Object.__used_uid.add(uid)
70
- return self
71
-
72
- def add_tags(self, *tags) -> Self:
73
- for tag in tags:
74
- if tag not in self.tags:
75
- self.tags.append(tag)
76
- self.tags.sort()
77
- return self
78
-
79
- def remove_tags(self, *tags):
80
- self.tags = [tag for tag in self.tags if tag not in tags]
81
-
82
- def has_tags(self, *tags) -> bool:
83
- return all(tag in self.tags for tag in tags)
84
-
85
- def get_tags(self) -> list[str]:
86
- return self.tags
87
-
88
- def process_event(self, event: pygame.Event) -> bool:
89
- """
90
- Returns bool : True if the method is blocking (no propagation to next object of the scene)
91
- """
92
- if event.consumed:
93
- return
94
- self.do_process_actions(event)
95
- self.do_handle_event(event)
96
-
97
- def do_process_actions(self, event: pygame.Event) -> None:
98
- """
99
- Process entity actions you may have set
100
- """
101
-
102
- def do_reset_actions(self) -> None:
103
- """
104
- Reset entity actions you may have set
105
- """
106
-
107
- def do_handle_event(self, event: pygame.Event):
108
- """
109
- Handle specific events with no action support
110
- """
111
- return False
112
-
113
- def update(self, dt: float) -> None:
114
- """
115
- Update method to be overriden by subclasses of object (must call do_update and do_reset_actions)
116
- """
117
- self.do_update(dt)
118
- self.do_reset_actions()
119
-
120
- def do_update(self, dt: float) -> None:
121
- """
122
- Update method to be overriden for specific behavior by the end user
123
- """