batframework 1.0.8a12__tar.gz → 1.0.8a14__tar.gz

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 (69) hide show
  1. {batframework-1.0.8a12/src/batframework.egg-info → batframework-1.0.8a14}/PKG-INFO +1 -1
  2. {batframework-1.0.8a12 → batframework-1.0.8a14}/pyproject.toml +1 -1
  3. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/__init__.py +4 -3
  4. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/animatedSprite.py +4 -52
  5. batframework-1.0.8a14/src/batFramework/animation.py +52 -0
  6. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/character.py +3 -3
  7. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/constants.py +4 -0
  8. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/cutscene.py +7 -5
  9. batframework-1.0.8a12/src/batFramework/entity.py → batframework-1.0.8a14/src/batFramework/drawable.py +3 -2
  10. batframework-1.0.8a12/src/batFramework/object.py → batframework-1.0.8a14/src/batFramework/entity.py +14 -13
  11. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/container.py +1 -1
  12. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/debugger.py +1 -1
  13. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/label.py +18 -41
  14. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/layout.py +2 -2
  15. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/root.py +0 -6
  16. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/widget.py +1 -1
  17. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/manager.py +35 -34
  18. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/particle.py +1 -1
  19. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/scene.py +1 -34
  20. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/sceneManager.py +5 -23
  21. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/sprite.py +2 -2
  22. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/templates/character.py +5 -6
  23. batframework-1.0.8a12/src/batFramework/time.py → batframework-1.0.8a14/src/batFramework/timeManager.py +0 -2
  24. batframework-1.0.8a14/src/batFramework/utils.py +248 -0
  25. {batframework-1.0.8a12 → batframework-1.0.8a14/src/batframework.egg-info}/PKG-INFO +1 -1
  26. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batframework.egg-info/SOURCES.txt +3 -2
  27. batframework-1.0.8a12/src/batFramework/utils.py +0 -149
  28. {batframework-1.0.8a12 → batframework-1.0.8a14}/LICENCE +0 -0
  29. {batframework-1.0.8a12 → batframework-1.0.8a14}/README.md +0 -0
  30. {batframework-1.0.8a12 → batframework-1.0.8a14}/setup.cfg +0 -0
  31. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/action.py +0 -0
  32. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/actionContainer.py +0 -0
  33. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/audioManager.py +0 -0
  34. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/camera.py +0 -0
  35. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/cutsceneBlocks.py +0 -0
  36. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/dynamicEntity.py +0 -0
  37. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/easingController.py +0 -0
  38. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/enums.py +0 -0
  39. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/fontManager.py +0 -0
  40. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/__init__.py +0 -0
  41. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/button.py +0 -0
  42. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/clickableWidget.py +0 -0
  43. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/constraints/__init__.py +0 -0
  44. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/constraints/constraints.py +0 -0
  45. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/dialogueBox.py +0 -0
  46. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/draggableWidget.py +0 -0
  47. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/image.py +0 -0
  48. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/indicator.py +0 -0
  49. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/interactiveWidget.py +0 -0
  50. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/meter.py +0 -0
  51. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/radioButton.py +0 -0
  52. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/shape.py +0 -0
  53. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/slider.py +0 -0
  54. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/style.py +0 -0
  55. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/styleManager.py +0 -0
  56. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/textInput.py +0 -0
  57. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/gui/toggle.py +0 -0
  58. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/renderGroup.py +0 -0
  59. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/resourceManager.py +0 -0
  60. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/scrollingSprite.py +0 -0
  61. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/stateMachine.py +0 -0
  62. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/templates/__init__.py +0 -0
  63. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/templates/states.py +0 -0
  64. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/tileset.py +0 -0
  65. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/transition.py +0 -0
  66. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batFramework/triggerZone.py +0 -0
  67. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batframework.egg-info/dependency_links.txt +0 -0
  68. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batframework.egg-info/requires.txt +0 -0
  69. {batframework-1.0.8a12 → batframework-1.0.8a14}/src/batframework.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: batframework
3
- Version: 1.0.8a12
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "batframework"
7
- version = "1.0.8a12"
7
+ version = "1.0.8a14"
8
8
  description = "Pygame framework for making games easier."
9
9
  readme = "README.md"
10
10
  classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent",]
@@ -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,14 +17,15 @@ 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
25
25
  from .scrollingSprite import ScrollingSprite
26
26
  from .particle import *
27
- from .animatedSprite import AnimatedSprite, Animation
27
+ from .animation import Animation
28
+ from .animatedSprite import AnimatedSprite
28
29
  from .character import Character
29
30
  from .stateMachine import State, StateMachine
30
31
  from .scene import Scene
@@ -1,59 +1,11 @@
1
1
  import batFramework as bf
2
2
  import pygame
3
3
  from typing import List, Dict, Tuple, Union, Optional, Self
4
+ from .animation import Animation
4
5
 
5
-
6
- def search_index(target: int, lst: List[int]) -> int:
7
- cumulative_sum = 0
8
- for index, value in enumerate(lst):
9
- cumulative_sum += value
10
- if cumulative_sum >= target:
11
- return index
12
- return -1
13
-
14
-
15
- class Animation:
16
- def __init__(
17
- self,
18
- name: str
19
- ) -> None:
20
- self.name = name
21
- self.frames: list[pygame.Surface] = []
22
- self.frames_flipX : list[pygame.Surface] = []
23
- self.duration_list = []
24
- self.duration_list_length = 1
25
-
26
- def from_surface(self,surface:pygame.Surface,size : Tuple[int,int])->Self:
27
- self.frames : List[pygame.Surface] = list(bf.utils.split_surface(surface, size).values())
28
- self.frames_flipX : List[pygame.Surface] = list(bf.utils.split_surface(surface, size,func=lambda s : pygame.transform.flip(s,True,False)).values())
29
- return self
30
-
31
- def __repr__(self):
32
- return f"Animation({self.name})"
33
-
34
- def counter_to_frame(self, counter: Union[float, int]) -> int:
35
- if not self.frames :
36
- raise ValueError("Animation has no frames")
37
- return search_index(
38
- int(counter % self.duration_list_length), self.duration_list
39
- )
40
-
41
- def get_frame(self, counter: Union[float, int], flip: bool) -> pygame.Surface:
42
- i = self.counter_to_frame(counter)
43
- return self.frames_flipX[i] if flip else self.frames[i]
44
-
45
- def set_duration_list(self, duration_list: Union[List[int], int]) -> Self:
46
- if isinstance(duration_list, int):
47
- duration_list = [duration_list] * len(self.frames)
48
- if len(duration_list) != len(self.frames):
49
- raise ValueError("duration_list should have values for all frames")
50
- self.duration_list = duration_list
51
- self.duration_list_length = sum(self.duration_list)
52
- return self
53
-
54
- class AnimatedSprite(bf.Entity):
55
- def __init__(self, size: Optional[Tuple[int, int]] = None) -> None:
56
- super().__init__(size, no_surface=True)
6
+ class AnimatedSprite(bf.Drawable):
7
+ def __init__(self, size: Optional[Tuple[int, int]] = None,*args,**kwargs) -> None:
8
+ super().__init__(size, no_surface=True,*args,**kwargs)
57
9
  self.float_counter: float = 0
58
10
  self.animations: Dict[str, Animation] = {}
59
11
  self.current_state: Optional[Animation] = None
@@ -0,0 +1,52 @@
1
+ import pygame
2
+ import batFramework as bf
3
+ from typing import List, Dict, Tuple, Union, Optional, Self
4
+
5
+
6
+ def search_index(target: int, lst: List[int]) -> int:
7
+ cumulative_sum = 0
8
+ for index, value in enumerate(lst):
9
+ cumulative_sum += value
10
+ if cumulative_sum >= target:
11
+ return index
12
+ return -1
13
+
14
+
15
+ class Animation:
16
+ def __init__(
17
+ self,
18
+ name: str
19
+ ) -> None:
20
+ self.name = name
21
+ self.frames: list[pygame.Surface] = []
22
+ self.frames_flipX : list[pygame.Surface] = []
23
+ self.duration_list = []
24
+ self.duration_list_length = 1
25
+
26
+ def from_surface(self,surface:pygame.Surface,size : Tuple[int,int])->Self:
27
+ self.frames : List[pygame.Surface] = list(bf.utils.split_surface(surface, size).values())
28
+ self.frames_flipX : List[pygame.Surface] = list(bf.utils.split_surface(surface, size,func=lambda s : pygame.transform.flip(s,True,False)).values())
29
+ return self
30
+
31
+ def __repr__(self):
32
+ return f"Animation({self.name})"
33
+
34
+ def counter_to_frame(self, counter: Union[float, int]) -> int:
35
+ if not self.frames :
36
+ raise ValueError("Animation has no frames")
37
+ return search_index(
38
+ int(counter % self.duration_list_length), self.duration_list
39
+ )
40
+
41
+ def get_frame(self, counter: Union[float, int], flip: bool) -> pygame.Surface:
42
+ i = self.counter_to_frame(counter)
43
+ return self.frames_flipX[i] if flip else self.frames[i]
44
+
45
+ def set_duration_list(self, duration_list: Union[List[int], int]) -> Self:
46
+ if isinstance(duration_list, int):
47
+ duration_list = [duration_list] * len(self.frames)
48
+ if len(duration_list) != len(self.frames):
49
+ raise ValueError("duration_list should have values for all frames")
50
+ self.duration_list = duration_list
51
+ self.duration_list_length = sum(self.duration_list)
52
+ return self
@@ -3,9 +3,9 @@ from .stateMachine import State
3
3
  from .animatedSprite import AnimatedSprite
4
4
  from .dynamicEntity import DynamicEntity
5
5
 
6
- class Character(AnimatedSprite,DynamicEntity):
7
- def __init__(self) -> None:
8
- super().__init__()
6
+ class Character(DynamicEntity,AnimatedSprite):
7
+ def __init__(self,*args,**kwargs) -> None:
8
+ super().__init__(*args,**kwargs)
9
9
  self.state_machine = bf.StateMachine(self)
10
10
  self.do_setup_animations()
11
11
  self.do_setup_states()
@@ -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):
@@ -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
 
@@ -1,10 +1,10 @@
1
1
  from typing import Any, Self
2
2
  import pygame
3
3
  import batFramework as bf
4
- from .object import Object
4
+ from .entity import Entity
5
5
 
6
6
 
7
- class Entity(Object):
7
+ class Drawable(Entity):
8
8
  """
9
9
  Basic entity class
10
10
  """
@@ -19,6 +19,7 @@ class Entity(Object):
19
19
  ) -> None:
20
20
  super().__init__()
21
21
  self.visible: bool = True
22
+ self.render_order: int = 0
22
23
  self.rect.size = (10, 10) if size is None else size
23
24
  self.convert_alpha: bool = convert_alpha
24
25
  self.surface_flags: int = surface_flags
@@ -7,7 +7,7 @@ if TYPE_CHECKING:
7
7
  from .camera import Camera
8
8
 
9
9
 
10
- class Object:
10
+ class Entity:
11
11
  __count = 0
12
12
  __available_uid = set()
13
13
  __used_uid = set()
@@ -17,18 +17,17 @@ class Object:
17
17
  self.tags: list[str] = []
18
18
  self.parent_scene: bf.Scene | None = None
19
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)
20
+ self.uid: int = Entity.__count
21
+ Entity.__used_uid.add(self.uid)
23
22
 
24
- if Object.__available_uid:
25
- self.name = Object.__available_uid.pop()
23
+ if Entity.__available_uid:
24
+ self.name = Entity.__available_uid.pop()
26
25
  else:
27
- self.name = Object.__count
28
- Object.__count += 1
26
+ self.name = Entity.__count
27
+ Entity.__count += 1
29
28
 
30
29
  def __del__(self):
31
- Object.__available_uid.add(self.uid)
30
+ Entity.__available_uid.add(self.uid)
32
31
 
33
32
  def set_position(self, x, y) -> Self:
34
33
  self.rect.topleft = x, y
@@ -62,11 +61,13 @@ class Object:
62
61
  pass
63
62
 
64
63
  def set_uid(self, uid: int) -> Self:
65
- if uid in Object.__used_uid:
64
+ if uid in Entity.__used_uid:
66
65
  print(f"set_uid error : UID '{uid}' is already in use")
67
66
  return self
68
67
  self.uid = uid
69
- Object.__used_uid.add(uid)
68
+ if uid in Entity.__used_uid:
69
+ Entity.__used_uid.remove(uid)
70
+ Entity.__used_uid.add(uid)
70
71
  return self
71
72
 
72
73
  def add_tags(self, *tags) -> Self:
@@ -87,7 +88,7 @@ class Object:
87
88
 
88
89
  def process_event(self, event: pygame.Event) -> bool:
89
90
  """
90
- Returns bool : True if the method is blocking (no propagation to next object of the scene)
91
+ Returns bool : True if the method is blocking (no propagation to next Entity of the scene)
91
92
  """
92
93
  if event.consumed:
93
94
  return
@@ -112,7 +113,7 @@ class Object:
112
113
 
113
114
  def update(self, dt: float) -> None:
114
115
  """
115
- Update method to be overriden by subclasses of object (must call do_update and do_reset_actions)
116
+ Update method to be overriden by subclasses of Entity (must call do_update and do_reset_actions)
116
117
  """
117
118
  self.do_update(dt)
118
119
  self.do_reset_actions()
@@ -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)
@@ -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
@@ -197,7 +184,6 @@ class Label(Shape):
197
184
  self.text_rect.size = self._get_text_rect_required_size()
198
185
  res = self.inflate_rect_by_padding((0, 0, *self.text_rect.size)).size
199
186
 
200
- return res
201
187
  return res[0] if self.autoresize_w else self.rect.w, (
202
188
  res[1] if self.autoresize_h else self.rect.h
203
189
  )
@@ -206,35 +192,26 @@ class Label(Shape):
206
192
  return self.text
207
193
 
208
194
  def _render_font(self, params: dict) -> pygame.Surface:
209
- key = tuple(params.values())
210
-
211
- cached_value = Label._text_cache.get(key, None)
212
195
 
213
196
  if self.draw_mode == bf.drawMode.SOLID:
214
- if cached_value is None:
215
- params.pop("font_name")
216
-
217
- # save old settings
218
- old_italic = self.font_object.get_italic()
219
- old_bold = self.font_object.get_bold()
220
- old_underline = self.font_object.get_underline()
221
-
222
- # setup font
223
- self.font_object.set_italic(self.is_italic)
224
- self.font_object.set_bold(self.is_bold)
225
- self.font_object.set_underline(self.is_underlined)
226
-
227
- surf = self.font_object.render(**params)
228
-
229
- # reset font
230
- self.font_object.set_italic(old_italic)
231
- self.font_object.set_bold(old_bold)
232
- self.font_object.set_underline(old_underline)
233
-
234
- if self.do_caching:
235
- Label._text_cache[key] = surf
236
- else:
237
- 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)
238
215
  else:
239
216
  params.pop("font_name")
240
217
  surf = self.font_object.render(**params)
@@ -1,8 +1,8 @@
1
1
  import batFramework as bf
2
2
  from .widget import Widget
3
3
  from .constraints.constraints import *
4
- from typing import Self, TYPE_CHECKING,override
5
- from abc import ABC,abstractmethod
4
+ from typing import Self, TYPE_CHECKING
5
+ from abc import ABC
6
6
  import pygame
7
7
 
8
8
  if TYPE_CHECKING:
@@ -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"] = []
@@ -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
- dt = self._clock.tick(bf.const.FPS) / 1000
81
- # dt = min(dt, 0.02) dirty fix for dt being too high when window not focused for a long time
82
- self._timeManager.update(dt)
83
- self._cutsceneManager.update(dt)
81
+ self.timeManager.update(dt)
82
+ self.cutsceneManager.update(dt)
84
83
  self.update(dt)
85
84
  # render
86
- self._screen.fill((0, 0, 0))
87
- self.draw(self._screen)
85
+ self.screen.fill((0, 0, 0))
86
+ self.draw(self.screen)
88
87
  pygame.display.flip()
88
+ dt = self.clock.tick(bf.const.FPS) / 1000
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
- dt = self._clock.tick(bf.const.FPS) / 1000
113
- # dt = min(dt, 0.02) dirty fix for dt being too high when window not focused for a long time
114
- self._timeManager.update(dt)
115
- self._cutsceneManager.update(dt)
113
+ self.timeManager.update(dt)
114
+ self.cutsceneManager.update(dt)
116
115
  self.update(dt)
117
116
  # render
118
- self._screen.fill((0, 0, 0))
119
- self.draw(self._screen)
117
+ self.screen.fill((0, 0, 0))
118
+ self.draw(self.screen)
120
119
  pygame.display.flip()
120
+ dt = self.clock.tick(bf.const.FPS) / 1000
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()
@@ -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] = []