batframework 1.0.8a1__py3-none-any.whl → 1.0.8a2__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 +50 -53
- batFramework/action.py +105 -116
- batFramework/actionContainer.py +11 -53
- batFramework/animatedSprite.py +65 -115
- batFramework/audioManager.py +26 -70
- batFramework/camera.py +68 -253
- batFramework/constants.py +54 -16
- batFramework/cutscene.py +25 -34
- batFramework/cutsceneBlocks.py +42 -37
- batFramework/debugger.py +48 -0
- batFramework/dynamicEntity.py +7 -9
- batFramework/easing.py +71 -0
- batFramework/entity.py +98 -42
- batFramework/gui/__init__.py +2 -8
- batFramework/gui/button.py +79 -7
- batFramework/gui/constraints.py +204 -0
- batFramework/gui/container.py +31 -155
- batFramework/gui/debugger.py +43 -124
- batFramework/gui/frame.py +19 -0
- batFramework/gui/image.py +17 -41
- batFramework/gui/indicator.py +21 -41
- batFramework/gui/interactiveWidget.py +13 -116
- batFramework/gui/label.py +73 -278
- batFramework/gui/layout.py +61 -148
- batFramework/gui/root.py +37 -102
- batFramework/gui/shape.py +57 -258
- batFramework/gui/toggle.py +46 -97
- batFramework/gui/widget.py +254 -268
- batFramework/manager.py +19 -40
- batFramework/particles.py +77 -0
- batFramework/scene.py +107 -214
- batFramework/sceneManager.py +107 -150
- batFramework/stateMachine.py +0 -1
- batFramework/time.py +57 -117
- batFramework/transition.py +126 -184
- batFramework/transitionManager.py +0 -0
- batFramework/utils.py +161 -34
- batframework-1.0.8a2.dist-info/METADATA +58 -0
- batframework-1.0.8a2.dist-info/RECORD +42 -0
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a2.dist-info}/WHEEL +1 -1
- batFramework/easingController.py +0 -58
- batFramework/enums.py +0 -104
- batFramework/fontManager.py +0 -65
- batFramework/gui/clickableWidget.py +0 -206
- batFramework/gui/constraints/__init__.py +0 -1
- batFramework/gui/constraints/constraints.py +0 -378
- batFramework/gui/dialogueBox.py +0 -96
- batFramework/gui/draggableWidget.py +0 -38
- batFramework/gui/meter.py +0 -76
- batFramework/gui/radioButton.py +0 -62
- batFramework/gui/slider.py +0 -220
- batFramework/gui/textInput.py +0 -134
- batFramework/object.py +0 -115
- batFramework/particle.py +0 -101
- batFramework/renderGroup.py +0 -62
- batFramework/resourceManager.py +0 -84
- batFramework/scrollingSprite.py +0 -113
- batFramework/sprite.py +0 -45
- batFramework/tileset.py +0 -46
- batframework-1.0.8a1.dist-info/LICENCE +0 -21
- batframework-1.0.8a1.dist-info/METADATA +0 -55
- batframework-1.0.8a1.dist-info/RECORD +0 -56
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a2.dist-info}/top_level.txt +0 -0
batFramework/animatedSprite.py
CHANGED
@@ -2,6 +2,7 @@ import batFramework as bf
|
|
2
2
|
import pygame
|
3
3
|
|
4
4
|
|
5
|
+
|
5
6
|
def search_index(target, lst):
|
6
7
|
cumulative_sum = 0
|
7
8
|
for index, value in enumerate(lst):
|
@@ -12,156 +13,105 @@ def search_index(target, lst):
|
|
12
13
|
|
13
14
|
|
14
15
|
class AnimState:
|
15
|
-
def __init__(
|
16
|
-
self,
|
17
|
-
|
18
|
-
|
19
|
-
width,
|
20
|
-
height,
|
21
|
-
duration_list: list | int,
|
22
|
-
) -> None:
|
23
|
-
self.frames: list[pygame.Surface] = list(
|
24
|
-
bf.utils.split_surface(
|
25
|
-
surface, width, height, False, convert_alpha
|
26
|
-
).values()
|
27
|
-
)
|
28
|
-
self.frames_flipX: list[pygame.Surface] = list(
|
29
|
-
bf.utils.split_surface(surface, width, height, True, convert_alpha).values()
|
16
|
+
def __init__(self, file, width, height, frame_length_list:list|int) -> None:
|
17
|
+
self.frames: list[pygame.Surface] = bf.utils.img_slice(file, width, height)
|
18
|
+
self.frames_flipX: list[pygame.Surface] = bf.utils.img_slice(
|
19
|
+
file, width, height, True
|
30
20
|
)
|
31
21
|
|
32
|
-
self.
|
33
|
-
self.
|
34
|
-
self.
|
35
|
-
self.set_duration_list(duration_list)
|
22
|
+
self.frame_length_list = []
|
23
|
+
self.ffl_length = 0
|
24
|
+
self.set_frame_length_list(frame_length_list)
|
36
25
|
|
37
|
-
def
|
38
|
-
return
|
39
|
-
|
40
|
-
def counter_to_frame(self, counter: float | int) -> int:
|
41
|
-
return search_index(
|
42
|
-
int(counter % self.duration_list_length), self.duration_list
|
43
|
-
)
|
26
|
+
def get_frame_index(self, counter:float|int):
|
27
|
+
return search_index(int(counter % self.ffl_length), self.frame_length_list)
|
44
28
|
|
45
29
|
def get_frame(self, counter, flip):
|
46
|
-
i = self.
|
30
|
+
i = self.get_frame_index(counter)
|
47
31
|
return self.frames_flipX[i] if flip else self.frames[i]
|
48
32
|
|
49
|
-
def
|
50
|
-
if isinstance(
|
51
|
-
|
52
|
-
if len(
|
53
|
-
raise ValueError("
|
54
|
-
self.
|
55
|
-
self.
|
56
|
-
|
33
|
+
def set_frame_length_list(self,frame_length_list:list[int]|int):
|
34
|
+
if isinstance(frame_length_list,int):
|
35
|
+
frame_length_list = [frame_length_list] * len(self.frames)
|
36
|
+
if len(frame_length_list) != len(self.frames) :
|
37
|
+
raise ValueError("frame_length_list should have values for all frames")
|
38
|
+
self.frame_length_list = frame_length_list
|
39
|
+
self.ffl_length = sum(self.frame_length_list)
|
40
|
+
|
57
41
|
|
58
42
|
class AnimatedSprite(bf.DynamicEntity):
|
59
43
|
def __init__(self, size=None) -> None:
|
60
44
|
super().__init__(size, no_surface=True)
|
61
|
-
self.float_counter
|
45
|
+
self.float_counter = 0
|
62
46
|
self.animStates: dict[str, AnimState] = {}
|
63
|
-
self.
|
47
|
+
self.current_animState :str = ""
|
64
48
|
self.flipX = False
|
65
49
|
self._locked = False
|
66
|
-
self.paused: bool = False
|
67
|
-
|
68
|
-
def pause(self) -> None:
|
69
|
-
self.paused = True
|
70
|
-
|
71
|
-
def resume(self) -> None:
|
72
|
-
self.paused = False
|
73
50
|
|
74
|
-
def
|
75
|
-
self.paused = not self.paused
|
76
|
-
|
77
|
-
def set_counter(self, value: float) -> None:
|
51
|
+
def set_counter(self,value:float):
|
78
52
|
self.float_counter = value
|
53
|
+
|
79
54
|
|
80
|
-
def
|
81
|
-
if not self.current_state:
|
82
|
-
return
|
83
|
-
total = sum(self.current_state.duration_list)
|
84
|
-
frame_index = max(0, min(total, frame_index))
|
85
|
-
new_counter = 0
|
86
|
-
i = 0
|
87
|
-
while frame_index < total:
|
88
|
-
if self.current_state.counter_to_frame(new_counter) >= frame_index:
|
89
|
-
break
|
90
|
-
new_counter += self.current_state.duration_list[i]
|
91
|
-
i += 1
|
92
|
-
self.set_counter(new_counter)
|
93
|
-
|
94
|
-
def lock(self) -> None:
|
55
|
+
def lock_animState(self):
|
95
56
|
self._locked = True
|
96
57
|
|
97
|
-
def
|
58
|
+
def unlock_animState(self):
|
98
59
|
self._locked = False
|
99
60
|
|
100
|
-
def set_flipX(self, value)
|
61
|
+
def set_flipX(self, value):
|
101
62
|
self.flipX = value
|
102
63
|
|
103
|
-
def remove_animState(self, name:
|
104
|
-
if not name in self.animStates:
|
105
|
-
|
106
|
-
self.animStates.
|
107
|
-
if self.current_state and self.current_state.name == name:
|
108
|
-
self.current_animState = (
|
109
|
-
list(self.animStates.keys())[0] if self.animStates else ""
|
110
|
-
)
|
111
|
-
return True
|
64
|
+
def remove_animState(self, name:str):
|
65
|
+
if not name in self.animStates :return
|
66
|
+
self.animStates.pop(name)
|
67
|
+
if self.current_animState == name : self.current_animState = list(self.animStates.keys())[0] if self.animStates else ""
|
112
68
|
|
113
69
|
def add_animState(
|
114
|
-
self,
|
115
|
-
|
116
|
-
surface: pygame.Surface,
|
117
|
-
size: tuple[int, int],
|
118
|
-
duration_list: list[int],
|
119
|
-
convert_alpha: bool = True,
|
120
|
-
) -> bool:
|
70
|
+
self, name: str, file: str, size: tuple[int, int], frame_length_list: list[int]
|
71
|
+
):
|
121
72
|
if name in self.animStates:
|
122
|
-
return
|
123
|
-
self.animStates[name] = AnimState(
|
124
|
-
if len(self.animStates) == 1:
|
125
|
-
self.set_animState(name)
|
126
|
-
return True
|
73
|
+
return
|
74
|
+
self.animStates[name] = AnimState(file, *size, frame_length_list)
|
75
|
+
if len(self.animStates) == 1 : self.set_animState(name)
|
127
76
|
|
128
|
-
def set_animState(self, state:
|
77
|
+
def set_animState(self, state:str, reset_counter=True, lock=False):
|
129
78
|
if state not in self.animStates or self._locked:
|
130
79
|
return False
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
if reset_counter or self.float_counter > sum(
|
80
|
+
self.current_animState = state
|
81
|
+
self.rect = (
|
82
|
+
self.animStates[self.current_animState]
|
83
|
+
.frames[0]
|
84
|
+
.get_frect(center=self.rect.center)
|
85
|
+
)
|
86
|
+
if reset_counter or self.float_counter > sum(
|
87
|
+
self.get_state().frame_length_list
|
88
|
+
):
|
138
89
|
self.float_counter = 0
|
139
90
|
if lock:
|
140
|
-
self.
|
91
|
+
self.lock_animState()
|
141
92
|
return True
|
142
93
|
|
143
|
-
def
|
144
|
-
return self.
|
94
|
+
def get_state(self):
|
95
|
+
return self.animStates.get(self.current_animState,None)
|
145
96
|
|
146
|
-
def
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
97
|
+
def get_frame_index(self):
|
98
|
+
return self.animStates[self.current_animState].get_frame_index(
|
99
|
+
self.float_counter
|
100
|
+
)
|
101
|
+
|
102
|
+
def update(self, dt: float):
|
103
|
+
if not self.animStates : return
|
104
|
+
self.float_counter += 60 * dt
|
105
|
+
if self.float_counter > self.get_state().ffl_length:
|
106
|
+
self.float_counter = 0
|
154
107
|
self.do_update(dt)
|
155
108
|
|
156
|
-
def draw(self, camera: bf.Camera) ->
|
157
|
-
if (
|
158
|
-
|
159
|
-
|
160
|
-
or not self.current_state
|
161
|
-
):
|
162
|
-
return 0
|
109
|
+
def draw(self, camera: bf.Camera) -> bool:
|
110
|
+
if not self.visible or not camera.intersects(self.rect) or not self.animStates:
|
111
|
+
return False
|
112
|
+
# pygame.draw.rect(camera.surface,"purple",camera.transpose(self.rect).move(2,2))
|
163
113
|
camera.surface.blit(
|
164
|
-
self.
|
165
|
-
camera.
|
114
|
+
self.get_state().get_frame(self.float_counter, self.flipX),
|
115
|
+
camera.transpose(self.rect),
|
166
116
|
)
|
167
|
-
return
|
117
|
+
return True
|
batFramework/audioManager.py
CHANGED
@@ -5,26 +5,24 @@ pygame.mixer.init()
|
|
5
5
|
|
6
6
|
|
7
7
|
class AudioManager(metaclass=bf.Singleton):
|
8
|
-
def __init__(self)
|
9
|
-
self.sounds: dict = {}
|
10
|
-
self.musics: dict = {}
|
11
|
-
self.current_music
|
12
|
-
self.music_volume
|
13
|
-
self.sound_volume
|
8
|
+
def __init__(self):
|
9
|
+
self.sounds: dict[str : dict[str, pygame.mixer.Sound, bool]] = {}
|
10
|
+
self.musics: dict[str:str] = {}
|
11
|
+
self.current_music = None
|
12
|
+
self.music_volume = 1
|
13
|
+
self.sound_volume = 1
|
14
14
|
pygame.mixer_music.set_endevent(bf.const.MUSIC_END_EVENT)
|
15
15
|
|
16
|
-
def free_sounds(self, force
|
16
|
+
def free_sounds(self, force=False):
|
17
17
|
if force:
|
18
18
|
self.sounds = {}
|
19
19
|
return
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
to_remove = []
|
21
|
+
for name, data in self.sounds.items():
|
22
|
+
if not data["persistent"]:
|
23
|
+
to_remove.append(name)
|
23
24
|
|
24
|
-
|
25
|
-
if self.current_music:
|
26
|
-
pygame.mixer.music.unload(self.current_music)
|
27
|
-
|
25
|
+
_ = [self.sounds.pop(i) for i in to_remove]
|
28
26
|
|
29
27
|
def set_sound_volume(self, volume: float):
|
30
28
|
self.sound_volume = volume
|
@@ -33,19 +31,13 @@ class AudioManager(metaclass=bf.Singleton):
|
|
33
31
|
self.music_volume = volume
|
34
32
|
pygame.mixer_music.set_volume(volume)
|
35
33
|
|
36
|
-
def
|
37
|
-
return self.music_volume
|
38
|
-
|
39
|
-
def get_sound_volume(self) -> float:
|
40
|
-
return self.sound_volume
|
41
|
-
|
42
|
-
def has_sound(self, name: str):
|
34
|
+
def has_sound(self, name):
|
43
35
|
return name in self.sounds
|
44
36
|
|
45
37
|
def load_sound(self, name, path, persistent=False) -> pygame.mixer.Sound:
|
46
38
|
if name in self.sounds:
|
47
39
|
return self.sounds[name]["sound"]
|
48
|
-
path = bf.
|
40
|
+
path = bf.utils.get_path(path)
|
49
41
|
self.sounds[name] = {
|
50
42
|
"path": path,
|
51
43
|
"sound": pygame.mixer.Sound(path),
|
@@ -53,57 +45,24 @@ class AudioManager(metaclass=bf.Singleton):
|
|
53
45
|
}
|
54
46
|
return self.sounds[name]["sound"]
|
55
47
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
"""
|
63
|
-
Play the sound file with the given name.
|
64
|
-
returns True if the sound was played
|
65
|
-
|
66
|
-
"""
|
67
|
-
try:
|
68
|
-
self.sounds[name]["sound"].set_volume(volume * self.sound_volume)
|
69
|
-
self.sounds[name]["sound"].play()
|
70
|
-
return True
|
71
|
-
except KeyError:
|
72
|
-
# print(f"Sound '{name}' not loaded in AudioManager.")
|
73
|
-
return False
|
74
|
-
|
75
|
-
def stop_sound(self, name) -> bool:
|
76
|
-
try:
|
48
|
+
def play_sound(self, name, volume=1):
|
49
|
+
self.sounds[name]["sound"].set_volume(volume * self.sound_volume)
|
50
|
+
self.sounds[name]["sound"].play()
|
51
|
+
|
52
|
+
def stop_sound(self, name):
|
53
|
+
if name in self.sounds:
|
77
54
|
self.sounds[name]["sound"].stop()
|
78
|
-
return True
|
79
|
-
except KeyError:
|
80
|
-
return False
|
81
|
-
# print(f"Sound '{name}' not loaded in AudioManager.")
|
82
55
|
|
83
56
|
def load_music(self, name, path):
|
84
|
-
self.musics[name] = bf.
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
for data in music_data_list:
|
89
|
-
self.load_music(*data)
|
90
|
-
return
|
91
|
-
|
92
|
-
def play_music(self, name, loop=0, fade=500) -> bool:
|
93
|
-
"""
|
94
|
-
Play the sound file with the given 'name'.
|
95
|
-
Fades with the given 'fade' time in ms.
|
96
|
-
Music will loop 'loop' times (indefinitely if -1).
|
97
|
-
returns True if the sound was played
|
98
|
-
"""
|
99
|
-
try:
|
57
|
+
self.musics[name] = bf.utils.get_path(path)
|
58
|
+
|
59
|
+
def play_music(self, name, loop=0, fade=500):
|
60
|
+
if name in self.musics:
|
100
61
|
pygame.mixer_music.load(self.musics[name])
|
101
62
|
pygame.mixer_music.play(loop, fade_ms=fade)
|
102
63
|
self.current_music = name
|
103
|
-
|
104
|
-
|
105
|
-
return False
|
106
|
-
# print(f"Music '{name}' not loaded in AudioManager.")
|
64
|
+
else:
|
65
|
+
print(f"Music '{name}' not found in AudioManager.")
|
107
66
|
|
108
67
|
def stop_music(self):
|
109
68
|
if not self.current_music:
|
@@ -124,6 +83,3 @@ class AudioManager(metaclass=bf.Singleton):
|
|
124
83
|
if not self.current_music:
|
125
84
|
return
|
126
85
|
pygame.mixer_music.unpause()
|
127
|
-
|
128
|
-
def get_current_music(self) -> str | None:
|
129
|
-
return self.current_music
|