batframework 1.0.9a10__py3-none-any.whl → 1.0.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- batFramework/__init__.py +53 -76
- batFramework/action.py +99 -126
- batFramework/actionContainer.py +9 -53
- batFramework/animatedSprite.py +114 -56
- batFramework/audioManager.py +36 -82
- batFramework/camera.py +69 -263
- batFramework/constants.py +53 -29
- batFramework/cutscene.py +109 -243
- batFramework/cutsceneBlocks.py +176 -0
- batFramework/debugger.py +48 -0
- batFramework/dynamicEntity.py +9 -16
- batFramework/easing.py +71 -0
- batFramework/entity.py +85 -92
- batFramework/gui/__init__.py +3 -14
- batFramework/gui/button.py +78 -12
- batFramework/gui/constraints.py +204 -0
- batFramework/gui/container.py +31 -183
- batFramework/gui/debugger.py +43 -126
- batFramework/gui/frame.py +19 -0
- batFramework/gui/image.py +20 -55
- batFramework/gui/indicator.py +22 -95
- batFramework/gui/interactiveWidget.py +12 -229
- batFramework/gui/label.py +77 -311
- batFramework/gui/layout.py +66 -411
- batFramework/gui/root.py +35 -203
- batFramework/gui/shape.py +57 -247
- batFramework/gui/toggle.py +48 -114
- batFramework/gui/widget.py +243 -457
- batFramework/manager.py +29 -113
- batFramework/particles.py +77 -0
- batFramework/scene.py +217 -22
- batFramework/sceneManager.py +129 -161
- batFramework/stateMachine.py +8 -11
- batFramework/time.py +75 -0
- batFramework/transition.py +124 -129
- batFramework/transitionManager.py +0 -0
- batFramework/triggerZone.py +4 -4
- batFramework/utils.py +144 -266
- {batframework-1.0.9a10.dist-info → batframework-1.0.10.dist-info}/METADATA +24 -17
- batframework-1.0.10.dist-info/RECORD +43 -0
- batFramework/animation.py +0 -77
- batFramework/baseScene.py +0 -240
- batFramework/cutsceneManager.py +0 -34
- batFramework/drawable.py +0 -77
- batFramework/easingController.py +0 -58
- batFramework/enums.py +0 -135
- batFramework/fontManager.py +0 -65
- batFramework/gui/animatedLabel.py +0 -89
- batFramework/gui/clickableWidget.py +0 -245
- batFramework/gui/constraints/__init__.py +0 -1
- batFramework/gui/constraints/constraints.py +0 -980
- batFramework/gui/draggableWidget.py +0 -44
- batFramework/gui/meter.py +0 -96
- batFramework/gui/radioButton.py +0 -35
- batFramework/gui/selector.py +0 -250
- batFramework/gui/slider.py +0 -397
- batFramework/gui/style.py +0 -10
- batFramework/gui/styleManager.py +0 -54
- batFramework/gui/syncedVar.py +0 -49
- batFramework/gui/textInput.py +0 -306
- batFramework/gui/tooltip.py +0 -30
- batFramework/particle.py +0 -118
- batFramework/propertyEaser.py +0 -79
- batFramework/renderGroup.py +0 -34
- batFramework/resourceManager.py +0 -130
- batFramework/sceneLayer.py +0 -138
- batFramework/scrollingSprite.py +0 -115
- batFramework/sprite.py +0 -51
- batFramework/templates/__init__.py +0 -1
- batFramework/templates/controller.py +0 -97
- batFramework/tileset.py +0 -46
- batFramework/timeManager.py +0 -213
- batframework-1.0.9a10.dist-info/RECORD +0 -67
- {batframework-1.0.9a10.dist-info → batframework-1.0.10.dist-info}/LICENSE +0 -0
- {batframework-1.0.9a10.dist-info → batframework-1.0.10.dist-info}/WHEEL +0 -0
- {batframework-1.0.9a10.dist-info → batframework-1.0.10.dist-info}/top_level.txt +0 -0
batFramework/sceneManager.py
CHANGED
@@ -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.
|
12
|
-
self.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
19
|
-
|
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
|
-
|
32
|
-
""
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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.
|
83
|
-
self.visible_scenes = [s for s in reversed(self.
|
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.
|
55
|
+
if scene in self._scenes and not self.has_scene(scene._name):
|
87
56
|
return
|
88
57
|
scene.set_manager(self)
|
89
|
-
scene.
|
90
|
-
self.
|
58
|
+
scene.do_when_added()
|
59
|
+
self._scenes.insert(0, scene)
|
91
60
|
|
92
61
|
def remove_scene(self, name: str):
|
93
|
-
self.
|
62
|
+
self._scenes = [s for s in self._scenes if s._name != name]
|
94
63
|
|
95
|
-
def has_scene(self, name
|
96
|
-
return any(name == scene.
|
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
|
67
|
+
def get_scene(self, name):
|
99
68
|
if not self.has_scene(name):
|
100
69
|
return None
|
101
|
-
for scene in self.
|
102
|
-
if scene.
|
70
|
+
for scene in self._scenes:
|
71
|
+
if scene._name == name:
|
103
72
|
return scene
|
104
73
|
|
105
|
-
def
|
106
|
-
if
|
107
|
-
return
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
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
|
-
|
187
|
-
|
188
|
-
def draw(self, surface
|
189
|
-
|
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
|
-
|
batFramework/stateMachine.py
CHANGED
@@ -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.
|
11
|
+
self.parent_entity: bf.Entity | bf.AnimatedSprite = None
|
11
12
|
self.state_machine: StateMachine = None
|
12
13
|
|
13
|
-
def
|
14
|
-
self.
|
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,
|
31
|
+
def __init__(self, parent_entity) -> None:
|
31
32
|
self.states: dict[str, State] = {}
|
32
|
-
self.
|
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.
|
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)
|