batframework 1.0.9a11__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 -188
  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 -414
  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.9a11.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 -244
  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.9a11.dist-info/RECORD +0 -67
  74. {batframework-1.0.9a11.dist-info → batframework-1.0.10.dist-info}/LICENSE +0 -0
  75. {batframework-1.0.9a11.dist-info → batframework-1.0.10.dist-info}/WHEEL +0 -0
  76. {batframework-1.0.9a11.dist-info → batframework-1.0.10.dist-info}/top_level.txt +0 -0
@@ -1,197 +1,165 @@
1
1
  import batFramework as bf
2
2
  import pygame
3
- from typing import Self
4
3
 
5
- def swap(lst, index1, index2):
6
- lst[index1], lst[index2] = lst[index2], lst[index1]
7
4
 
8
5
 
9
6
  class SceneManager:
10
- def __init__(self) -> None:
11
- self.scenes: list[bf.BaseScene] = []
12
- self.shared_events = {pygame.WINDOWRESIZED}
13
- self.current_transition : tuple[str,bf.transition.Transition,int] | None= None
14
-
15
- def init_scenes(self, *initial_scenes:bf.Scene):
16
- for index, s in enumerate(initial_scenes):
7
+ def __init__(self, *initial_scenes: bf.Scene) -> None:
8
+ self._debugging = 0
9
+ self.sharedVarDict = {}
10
+
11
+ self.transitions: list[bf.BaseTransition] = []
12
+ self.set_sharedVar("is_debugging_func", lambda: self._debugging)
13
+ self.set_sharedVar("in_transition", False)
14
+ self.set_sharedVar("in_cutscene", False)
15
+
16
+ self._scenes: list[bf.Scene] = list(initial_scenes)
17
+ for index,s in enumerate(self._scenes):
18
+ s.set_manager(self)
17
19
  s.set_scene_index(index)
18
- for s in reversed(initial_scenes):
19
- self.add_scene(s)
20
- self.set_scene(initial_scenes[0].get_name())
20
+ s.do_when_added()
21
+ self.set_scene(self._scenes[0]._name)
21
22
  self.update_scene_states()
22
23
 
23
- def set_shared_event(self, event: pygame.Event) -> None:
24
- """
25
- Add an event that will be propagated to all active scenes, not just the one on top.
26
- """
27
- self.shared_events.add(event)
28
-
29
24
  def print_status(self):
30
- """
31
- Print detailed information about the current state of the scenes and shared variables.
32
- """
33
-
34
- def format_scene_info(scene:bf.Scene):
35
- status = 'Active' if scene.active else 'Inactive'
36
- visibility = 'Visible' if scene.visible else 'Invisible'
37
- return f"{scene.name:<30} | {status:<8} | {visibility:<10} | Index={scene.scene_index}"
38
-
39
- def format_shared_variable(name, value):
40
- return f"[{name}] = {value}"
41
-
42
- print("\n" + "=" * 50)
43
- print(" SCENE STATUS".center(50))
44
- print("=" * 50)
45
-
46
- # Print scene information
47
- if self.scenes:
48
- header = f"{'Scene Name':<30} | {'Status':<8} | {'Visibility':<10} | {'Index':<7}"
49
- print(header)
50
- print("-" * 50)
51
- print("\n".join(format_scene_info(s) for s in self.scenes))
52
- else:
53
- print("No scenes available.")
54
-
55
- # Print debugging mode status
56
- print("\n" + "=" * 50)
57
- print(" DEBUGGING STATUS".center(50))
58
- print("=" * 50)
59
- print(f"[Debugging Mode] = {bf.ResourceManager().get_sharedVar('debug_mode')}")
60
-
61
- # Print shared variables
62
- print("\n" + "=" * 50)
63
- print(" SHARED VARIABLES".center(50))
64
- print("=" * 50)
65
-
66
- if bf.ResourceManager().shared_variables:
67
- for name, value in bf.ResourceManager().shared_variables.items():
68
- print(format_shared_variable(name, value))
69
- else:
70
- print("No shared variables available.")
71
-
72
- print("=" * 50 + "\n")
73
-
74
- def get_current_scene_name(self) -> str:
75
- """get the name of the current scene"""
76
- return self.scenes[0].get_name()
77
-
78
- def get_current_scene(self) -> bf.Scene:
79
- return self.scenes[0]
25
+ print("-" * 40)
26
+ print([(s._name, s._active, s._visible,s.scene_index) for s in self._scenes])
27
+ print(f"[Debugging] = {self._debugging}")
28
+ print("---SHARED VARIABLES---")
29
+ _ = [
30
+ print(f"[{str(name)} = {str(value)}]")
31
+ for name, value in self.sharedVarDict.items()
32
+ ]
33
+ print("-" * 40)
34
+
35
+ def set_sharedVar(self, name, value) -> bool:
36
+ self.sharedVarDict[name] = value
37
+ return True
38
+
39
+ def get_sharedVar(self, name):
40
+ if name not in self.sharedVarDict:
41
+ return None
42
+ return self.sharedVarDict[name]
43
+
44
+ def get_current_scene_name(self)-> str:
45
+ return self._scenes[0].name
46
+
47
+ def get_current_scene(self)->bf.Scene:
48
+ return self._scenes[0]
80
49
 
81
50
  def update_scene_states(self):
82
- self.active_scenes = [s for s in reversed(self.scenes) if s.active]
83
- self.visible_scenes = [s for s in reversed(self.scenes) if s.visible]
51
+ self.active_scenes = [s for s in reversed(self._scenes) if s._active]
52
+ self.visible_scenes = [s for s in reversed(self._scenes) if s._visible]
84
53
 
85
54
  def add_scene(self, scene: bf.Scene):
86
- if scene in self.scenes and not self.has_scene(scene.name):
55
+ if scene in self._scenes and not self.has_scene(scene._name):
87
56
  return
88
57
  scene.set_manager(self)
89
- scene.when_added()
90
- self.scenes.insert(0, scene)
58
+ scene.do_when_added()
59
+ self._scenes.insert(0, scene)
91
60
 
92
61
  def remove_scene(self, name: str):
93
- self.scenes = [s for s in self.scenes if s.name != name]
62
+ self._scenes = [s for s in self._scenes if s._name != name]
94
63
 
95
- def has_scene(self, name:str):
96
- return any(name == scene.name for scene in self.scenes)
64
+ def has_scene(self, name):
65
+ return any(name == scene._name for scene in self._scenes)
97
66
 
98
- def get_scene(self, name:str):
67
+ def get_scene(self, name):
99
68
  if not self.has_scene(name):
100
69
  return None
101
- for scene in self.scenes:
102
- if scene.name == name:
70
+ for scene in self._scenes:
71
+ if scene._name == name:
103
72
  return scene
104
73
 
105
- def get_scene_at(self, index: int) -> bf.Scene | None:
106
- if index < 0 or index >= len(self.scenes):
107
- return None
108
- return self.scenes[index]
109
-
110
- def transition_to_scene(
111
- self,
112
- scene_name: str,
113
- transition: bf.transition.Transition = None,
114
- index: int = 0,
115
- ):
116
- if transition is None:
117
- transition = bf.transition.Fade(0.1)
118
- if not (target_scene := self.get_scene(scene_name)):
119
- print(f"Scene '{scene_name}' does not exist")
120
- return
121
- if not (source_scene := self.get_scene_at(index)):
122
- print(f"No scene exists at index {index}.")
123
- return
124
-
125
- source_surface = bf.const.SCREEN.copy()
126
- dest_surface = bf.const.SCREEN.copy()
127
-
128
- target_scene.draw(dest_surface) # draw at least once to ensure smooth transition
129
- target_scene.set_active(True)
130
- target_scene.set_visible(True)
131
-
132
- target_scene.do_on_enter_early()
133
- source_scene.do_on_exit_early()
134
-
135
- self.current_transition :tuple[str,bf.transition.Transition]=(scene_name,transition,index)
136
- transition.set_source(source_surface)
137
- transition.set_dest(dest_surface)
138
- transition.start()
139
-
140
-
141
-
142
- def set_scene(self, scene_name, index=0, ignore_early: bool = False):
143
- target_scene = self.get_scene(scene_name)
144
- if not target_scene:
145
- print(f"'{scene_name}' does not exist")
146
- return
147
- if len(self.scenes) == 0 or index >= len(self.scenes) or index < 0:
148
- return
149
-
150
- # switch
151
- if not ignore_early:
152
- self.scenes[index].do_on_exit_early()
153
- self.scenes[index].on_exit()
154
- # re-insert scene at index 0
155
- self.scenes.remove(target_scene)
156
- self.scenes.insert(index, target_scene)
157
- _ = [s.set_scene_index(i) for i, s in enumerate(self.scenes)]
158
- if not ignore_early:
159
- self.scenes[index].do_on_enter_early()
74
+ def transition_to_scene(self, dest_scene_name, transition, **kwargs):
75
+ if not self.has_scene(dest_scene_name):
76
+ return False
77
+ source_surf = pygame.Surface(bf.const.RESOLUTION,pygame.SRCALPHA).convert_alpha()
78
+ dest_surf = pygame.Surface(bf.const.RESOLUTION,pygame.SRCALPHA).convert_alpha()
79
+
80
+ index = kwargs.pop("index",0)
81
+ #draw the surfaces
82
+ source_scenes = [s for s in self.visible_scenes if s.scene_index >= index and s._visible]
83
+ # source_scenes = self.visible_scenes
84
+ _ = [s.draw(source_surf) for s in source_scenes]
85
+ # self._scenes[index].draw(source_surf)
86
+
87
+ # pygame.image.save_extended:(source_surf,"source_surface.png")
88
+ self.get_scene(dest_scene_name).draw(dest_surf)
89
+ # pygame.image.save_extended(dest_surf,"dest_surface.png")
90
+
91
+ # print(f"start transition from {self._scenes[index]._name} to {dest_scene_name}")
92
+
93
+ instance: bf.BaseTransition = transition(
94
+ source_surf, dest_surf, **kwargs
95
+ )
96
+ instance.set_scene_index(index)
97
+ instance.set_source_name(self._scenes[index]._name)
98
+ instance.set_dest_name(dest_scene_name)
99
+ self.transitions.append(instance)
100
+ self.set_sharedVar("in_transition", True)
101
+
102
+ def set_scene(self, name,index=0):
103
+ if len(self._scenes)==0 or not self.has_scene(name) or index>=len(self._scenes):return
104
+
105
+ target_scene = self.get_scene(name)
106
+ old_scene = self._scenes[index]
107
+
108
+ # print(f"switch from {old_scene._name} to {target_scene._name} in index {index}")
109
+
110
+ #switch
111
+ old_scene.on_exit()
112
+ self.remove_scene(name)
113
+ self._scenes.insert(index,target_scene)
114
+ _ = [s.set_scene_index(i) for i,s in enumerate(self._scenes)]
160
115
  target_scene.on_enter()
161
116
 
162
117
 
163
-
164
- def cycle_debug_mode(self):
165
- current_index = bf.ResourceManager().get_sharedVar("debug_mode").value
166
- next_index = (current_index + 1) % len(bf.debugMode)
167
- bf.ResourceManager().set_sharedVar("debug_mode", bf.debugMode(next_index))
168
- return bf.debugMode(next_index)
169
-
170
118
  def process_event(self, event: pygame.Event):
171
-
172
- if event.type in self.shared_events:
173
- [s.process_event(event) for s in self.scenes]
174
- else:
175
- self.scenes[0].process_event(event)
119
+ if self.transitions:
120
+ return
121
+ keys = pygame.key.get_pressed()
122
+ if (
123
+ keys[pygame.K_LCTRL]
124
+ and event.type == pygame.KEYDOWN
125
+ and event.key == pygame.K_d
126
+ ):
127
+ self._debugging = (self._debugging + 1) % 3
128
+ return
129
+ elif (
130
+ keys[pygame.K_LCTRL]
131
+ and event.type == pygame.KEYDOWN
132
+ and event.key == pygame.K_p
133
+ ):
134
+ self.print_status()
135
+ self._scenes[0].process_event(event)
176
136
 
177
137
  def update(self, dt: float) -> None:
138
+ if self.transitions:
139
+ transition = self.transitions[0]
140
+ transition.update(dt)
141
+ if transition.has_ended():
142
+ self.set_sharedVar("in_transition", False)
143
+ self.set_scene(transition.dest_scene_name,transition.index)
144
+
145
+ self.transitions.pop(0)
146
+ return
178
147
  for scene in self.active_scenes:
179
148
  scene.update(dt)
180
- if self.current_transition and self.current_transition[1].is_over:
181
- self.set_scene(self.current_transition[0],self.current_transition[2],True)
182
- self.current_transition = None
183
149
  self.do_update(dt)
184
150
 
185
151
  def do_update(self, dt: float):
186
- pass
187
-
188
- def draw(self, surface:pygame.Surface) -> None:
189
- for scene in self.visible_scenes:
152
+ return
153
+
154
+ def draw(self, surface) -> None:
155
+ transition_scene_index = -1
156
+ visible_scenes = self.visible_scenes.copy()
157
+ if self.transitions:
158
+ transition_scene_index = self.transitions[0].index
159
+
160
+ if transition_scene_index >=0:
161
+ self.transitions[0].draw(surface)
162
+ visible_scenes = [s for s in visible_scenes if s.scene_index < transition_scene_index]
163
+
164
+ for scene in visible_scenes:
190
165
  scene.draw(surface)
191
- if self.current_transition is not None:
192
- self.current_transition[1].set_source(surface)
193
- tmp = surface.copy()
194
- self.get_scene(self.current_transition[0]).draw(tmp)
195
- self.current_transition[1].set_dest(tmp)
196
- self.current_transition[1].draw(surface)
197
-
@@ -1,17 +1,18 @@
1
1
  import batFramework as bf
2
2
 
3
3
 
4
- class StateMachine: ...
4
+ class StateMachine:
5
+ ...
5
6
 
6
7
 
7
8
  class State:
8
9
  def __init__(self, name: str) -> None:
9
10
  self.name = name
10
- self.parent: bf.Entity | bf.AnimatedSprite = None
11
+ self.parent_entity: bf.Entity | bf.AnimatedSprite = None
11
12
  self.state_machine: StateMachine = None
12
13
 
13
- def set_parent(self, parent: bf.Entity | bf.AnimatedSprite):
14
- self.parent = parent
14
+ def set_parent_entity(self, parent_entity: bf.Entity | bf.AnimatedSprite):
15
+ self.parent_entity = parent_entity
15
16
 
16
17
  def set_stateMachine(self, stateMachine):
17
18
  self.state_machine = stateMachine
@@ -27,26 +28,22 @@ class State:
27
28
 
28
29
 
29
30
  class StateMachine:
30
- def __init__(self, parent) -> None:
31
+ def __init__(self, parent_entity) -> None:
31
32
  self.states: dict[str, State] = {}
32
- self.parent = parent
33
+ self.parent_entity = parent_entity
33
34
  self.current_state = None
34
35
 
35
36
  def add_state(self, state: State):
36
37
  self.states[state.name] = state
37
- state.set_parent(self.parent)
38
+ state.set_parent_entity(self.parent_entity)
38
39
  state.set_stateMachine(self)
39
40
 
40
- def remove_state(self,state_name: str):
41
- self.states.pop(state_name,default=None)
42
-
43
41
  def set_state(self, state_name: str):
44
42
  if state_name in self.states:
45
43
  if self.current_state:
46
44
  self.current_state.on_exit()
47
45
  self.current_state = self.states[state_name]
48
46
  self.current_state.on_enter()
49
-
50
47
  def get_current_state(self) -> State:
51
48
  return self.current_state
52
49
 
batFramework/time.py ADDED
@@ -0,0 +1,75 @@
1
+ import pygame
2
+ import batFramework as bf
3
+
4
+ class Timer:
5
+ _highest_count = 0
6
+ def __init__(self, name=None, duration=1000, loop=False, end_callback=None,reusable:bool=False):
7
+ # Initialize timer properties
8
+ self.start_time = None
9
+ self.stopped = True
10
+ self.name = name if name is not None else self._highest_count
11
+ Timer._highest_count += 1
12
+ self.duration = duration
13
+ self.loop = loop
14
+ self.elapsed_progress = 0.0
15
+ self.end_callback = end_callback
16
+ self.reusable:bool = reusable
17
+ def start(self):
18
+ # Start the timer and set the start time
19
+ if self.start_time is None:
20
+ Time().add_timer(self)
21
+
22
+ self.start_time = pygame.time.get_ticks()
23
+ self.stopped = False
24
+ self.elapsed_progress = 0.0
25
+
26
+ def update(self):
27
+ if self.stopped : return False
28
+ current_time = pygame.time.get_ticks()
29
+ if self.elapsed_progress < 1:
30
+ # Calculate elapsed progress
31
+ self.elapsed_progress = (current_time - self.start_time) / self.duration
32
+ if self.elapsed_progress >= 1:
33
+ # Timer has completed
34
+ self.end()
35
+ return True
36
+ elif self.loop:
37
+ # If looping, restart the timer
38
+ self.start()
39
+ return False
40
+
41
+ def stop(self):
42
+ # Stop the timer
43
+ self.stopped = True
44
+
45
+ def end(self):
46
+ self.elapsed_progress = 1
47
+ self.stopped = False
48
+ if self.end_callback:
49
+ self.end_callback()
50
+
51
+ def ended(self):
52
+ if self.start_time is None:
53
+ return False
54
+ return (not self.loop) and (self.elapsed_progress >= 1) and (not self.stopped) and not self.reusable
55
+
56
+
57
+ class Time(metaclass=bf.Singleton):
58
+ def __init__(self):
59
+ # Initialize the Time class with a dictionary of timers
60
+ self.timers = {}
61
+
62
+ def add_timer(self, timer):
63
+ # Add a timer to the dictionary
64
+ self.timers[timer.name] = timer
65
+
66
+ def update(self):
67
+ # Update all timers and remove completed ones
68
+ for timer in list(self.timers.values()):
69
+ timer.update()
70
+
71
+ to_remove = [name for name, timer in self.timers.items() if timer.ended()]
72
+
73
+ for name in to_remove:
74
+ # print(self.timers.pop(name).name,"removed !")
75
+ self.timers.pop(name)