batframework 1.0.9a11__py3-none-any.whl → 1.0.9a13__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 +3 -11
- batFramework/action.py +280 -279
- batFramework/actionContainer.py +105 -82
- batFramework/animatedSprite.py +80 -58
- batFramework/animation.py +91 -77
- batFramework/audioManager.py +156 -131
- batFramework/baseScene.py +249 -240
- batFramework/camera.py +245 -317
- batFramework/constants.py +57 -51
- batFramework/cutscene.py +239 -253
- batFramework/cutsceneManager.py +34 -34
- batFramework/drawable.py +107 -77
- batFramework/dynamicEntity.py +30 -30
- batFramework/easingController.py +58 -58
- batFramework/entity.py +130 -130
- batFramework/enums.py +171 -135
- batFramework/fontManager.py +65 -65
- batFramework/gui/__init__.py +28 -25
- batFramework/gui/animatedLabel.py +90 -89
- batFramework/gui/button.py +17 -17
- batFramework/gui/clickableWidget.py +244 -244
- batFramework/gui/collapseContainer.py +98 -0
- batFramework/gui/constraints/__init__.py +1 -1
- batFramework/gui/constraints/constraints.py +1066 -980
- batFramework/gui/container.py +220 -206
- batFramework/gui/debugger.py +140 -130
- batFramework/gui/draggableWidget.py +63 -44
- batFramework/gui/image.py +61 -58
- batFramework/gui/indicator.py +116 -113
- batFramework/gui/interactiveWidget.py +243 -239
- batFramework/gui/label.py +147 -344
- batFramework/gui/layout.py +442 -429
- batFramework/gui/meter.py +155 -96
- batFramework/gui/radioButton.py +43 -35
- batFramework/gui/root.py +228 -228
- batFramework/gui/scrollingContainer.py +282 -0
- batFramework/gui/selector.py +232 -250
- batFramework/gui/shape.py +286 -276
- batFramework/gui/slider.py +353 -397
- batFramework/gui/style.py +10 -10
- batFramework/gui/styleManager.py +49 -54
- batFramework/gui/syncedVar.py +43 -49
- batFramework/gui/textInput.py +331 -306
- batFramework/gui/textWidget.py +308 -0
- batFramework/gui/toggle.py +140 -128
- batFramework/gui/tooltip.py +35 -30
- batFramework/gui/widget.py +546 -521
- batFramework/manager.py +131 -134
- batFramework/particle.py +118 -118
- batFramework/propertyEaser.py +79 -79
- batFramework/renderGroup.py +34 -34
- batFramework/resourceManager.py +130 -130
- batFramework/scene.py +31 -31
- batFramework/sceneLayer.py +134 -138
- batFramework/sceneManager.py +200 -197
- batFramework/scrollingSprite.py +115 -115
- batFramework/sprite.py +46 -51
- batFramework/stateMachine.py +49 -54
- batFramework/templates/__init__.py +2 -1
- batFramework/templates/character.py +15 -0
- batFramework/templates/controller.py +158 -97
- batFramework/templates/stateMachine.py +39 -0
- batFramework/tileset.py +46 -46
- batFramework/timeManager.py +213 -213
- batFramework/transition.py +162 -162
- batFramework/triggerZone.py +22 -22
- batFramework/utils.py +306 -306
- {batframework-1.0.9a11.dist-info → batframework-1.0.9a13.dist-info}/LICENSE +20 -20
- {batframework-1.0.9a11.dist-info → batframework-1.0.9a13.dist-info}/METADATA +24 -17
- batframework-1.0.9a13.dist-info/RECORD +72 -0
- batframework-1.0.9a11.dist-info/RECORD +0 -67
- {batframework-1.0.9a11.dist-info → batframework-1.0.9a13.dist-info}/WHEEL +0 -0
- {batframework-1.0.9a11.dist-info → batframework-1.0.9a13.dist-info}/top_level.txt +0 -0
batFramework/audioManager.py
CHANGED
@@ -1,131 +1,156 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
self.
|
10
|
-
self.
|
11
|
-
|
12
|
-
self.
|
13
|
-
self.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
pygame.mixer.
|
27
|
-
|
28
|
-
|
29
|
-
self.
|
30
|
-
|
31
|
-
def
|
32
|
-
self.
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
print(f"Sound '{name}' not loaded
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
def
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
def
|
126
|
-
if
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
def
|
131
|
-
|
1
|
+
import pygame
|
2
|
+
import batFramework as bf
|
3
|
+
|
4
|
+
class AudioManager(metaclass=bf.Singleton):
|
5
|
+
def __init__(self) -> None:
|
6
|
+
self._sounds: dict[str, dict] = {}
|
7
|
+
self._musics: dict[str, str] = {}
|
8
|
+
self._current_music: str | None = None
|
9
|
+
self._music_volume: float = 1.0
|
10
|
+
self._sound_volume: float = 1.0
|
11
|
+
|
12
|
+
self._channels: dict[str, pygame.mixer.Channel] = {}
|
13
|
+
self._channel_volumes: dict[str, float] = {}
|
14
|
+
self._use_custom_channels: bool = False
|
15
|
+
|
16
|
+
pygame.mixer.music.set_endevent(bf.const.MUSIC_END_EVENT)
|
17
|
+
|
18
|
+
# --- Channel management ---
|
19
|
+
def setup_channels(self, channels: dict[str, int]) -> None:
|
20
|
+
"""
|
21
|
+
Setup channels by providing a dict of {channel_name: channel_index}.
|
22
|
+
Enables custom channel management.
|
23
|
+
"""
|
24
|
+
pygame.mixer.set_num_channels(max(channels.values()) + 1)
|
25
|
+
self._channels = {
|
26
|
+
name: pygame.mixer.Channel(idx) for name, idx in channels.items()
|
27
|
+
}
|
28
|
+
self._channel_volumes = {name: 1.0 for name in channels.keys()}
|
29
|
+
self._use_custom_channels = True
|
30
|
+
|
31
|
+
def set_channel_volume(self, channel_name: str, volume: float) -> None:
|
32
|
+
if channel_name in self._channels:
|
33
|
+
clamped = max(0.0, min(volume, 1.0))
|
34
|
+
self._channel_volumes[channel_name] = clamped
|
35
|
+
self._channels[channel_name].set_volume(clamped)
|
36
|
+
|
37
|
+
def get_channel_volume(self, channel_name: str) -> float:
|
38
|
+
return self._channel_volumes.get(channel_name, 1.0)
|
39
|
+
|
40
|
+
# --- Sound management ---
|
41
|
+
def load_sound(self, name: str, path: str, persistent: bool = False) -> pygame.mixer.Sound:
|
42
|
+
if name in self._sounds:
|
43
|
+
return self._sounds[name]["sound"]
|
44
|
+
path = bf.ResourceManager().get_path(path)
|
45
|
+
sound = pygame.mixer.Sound(path)
|
46
|
+
self._sounds[name] = {
|
47
|
+
"sound": sound,
|
48
|
+
"path": path,
|
49
|
+
"persistent": persistent,
|
50
|
+
}
|
51
|
+
return sound
|
52
|
+
|
53
|
+
def load_sounds(self, sounds_data: list[tuple[str, str, bool]]) -> None:
|
54
|
+
for name, path, persistent in sounds_data:
|
55
|
+
self.load_sound(name, path, persistent)
|
56
|
+
|
57
|
+
def play_sound(self, name: str, volume: float = 1.0, channel_name: str | None = None) -> bool:
|
58
|
+
sound_data = self._sounds.get(name)
|
59
|
+
if not sound_data:
|
60
|
+
print(f"[AudioManager] Sound '{name}' not loaded.")
|
61
|
+
return False
|
62
|
+
sound = sound_data["sound"]
|
63
|
+
volume = max(0.0, min(volume, 1.0)) * self._sound_volume
|
64
|
+
|
65
|
+
if self._use_custom_channels and channel_name:
|
66
|
+
channel = self._channels.get(channel_name)
|
67
|
+
if not channel:
|
68
|
+
print(f"[AudioManager] Channel '{channel_name}' not found. Using default channel.")
|
69
|
+
sound.set_volume(volume)
|
70
|
+
sound.play()
|
71
|
+
return True
|
72
|
+
channel.set_volume(volume * self._channel_volumes.get(channel_name, 1.0))
|
73
|
+
channel.play(sound)
|
74
|
+
else:
|
75
|
+
# Default pygame behavior: auto assign a free channel
|
76
|
+
sound.set_volume(volume)
|
77
|
+
sound.play()
|
78
|
+
return True
|
79
|
+
|
80
|
+
def stop_sound(self, name: str) -> bool:
|
81
|
+
sound_data = self._sounds.get(name)
|
82
|
+
if not sound_data:
|
83
|
+
print(f"[AudioManager] Sound '{name}' not loaded.")
|
84
|
+
return False
|
85
|
+
sound_data["sound"].stop()
|
86
|
+
return True
|
87
|
+
|
88
|
+
def free_sounds(self, force: bool = False) -> None:
|
89
|
+
if force:
|
90
|
+
self._sounds.clear()
|
91
|
+
else:
|
92
|
+
self._sounds = {
|
93
|
+
name: data for name, data in self._sounds.items() if data["persistent"]
|
94
|
+
}
|
95
|
+
|
96
|
+
def set_sound_volume(self, volume: float) -> None:
|
97
|
+
self._sound_volume = max(0.0, min(volume, 1.0))
|
98
|
+
|
99
|
+
def get_sound_volume(self) -> float:
|
100
|
+
return self._sound_volume
|
101
|
+
|
102
|
+
# --- Music management ---
|
103
|
+
def load_music(self, name: str, path: str) -> None:
|
104
|
+
self._musics[name] = bf.ResourceManager().get_path(path)
|
105
|
+
|
106
|
+
def load_musics(self, musics_data: list[tuple[str, str]]) -> None:
|
107
|
+
for name, path in musics_data:
|
108
|
+
self.load_music(name, path)
|
109
|
+
|
110
|
+
def play_music(self, name: str, loops: int = 0, fade_ms: int = 500) -> bool:
|
111
|
+
path = self._musics.get(name)
|
112
|
+
if not path:
|
113
|
+
print(f"[AudioManager] Music '{name}' not loaded.")
|
114
|
+
return False
|
115
|
+
try:
|
116
|
+
pygame.mixer.music.load(path)
|
117
|
+
pygame.mixer.music.set_volume(self._music_volume)
|
118
|
+
pygame.mixer.music.play(loops=loops, fade_ms=fade_ms)
|
119
|
+
self._current_music = name
|
120
|
+
return True
|
121
|
+
except pygame.error as e:
|
122
|
+
print(f"[AudioManager] Failed to play music '{name}': {e}")
|
123
|
+
return False
|
124
|
+
|
125
|
+
def stop_music(self) -> None:
|
126
|
+
if self._current_music:
|
127
|
+
pygame.mixer.music.stop()
|
128
|
+
self._current_music = None
|
129
|
+
|
130
|
+
def fadeout_music(self, fade_ms: int) -> None:
|
131
|
+
if self._current_music:
|
132
|
+
pygame.mixer.music.fadeout(fade_ms)
|
133
|
+
self._current_music = None
|
134
|
+
|
135
|
+
def pause_music(self) -> None:
|
136
|
+
if self._current_music:
|
137
|
+
pygame.mixer.music.pause()
|
138
|
+
|
139
|
+
def resume_music(self) -> None:
|
140
|
+
if self._current_music:
|
141
|
+
pygame.mixer.music.unpause()
|
142
|
+
|
143
|
+
def free_music(self) -> None:
|
144
|
+
if self._current_music:
|
145
|
+
pygame.mixer.music.unload()
|
146
|
+
self._current_music = None
|
147
|
+
|
148
|
+
def set_music_volume(self, volume: float) -> None:
|
149
|
+
self._music_volume = max(0.0, min(volume, 1.0))
|
150
|
+
pygame.mixer.music.set_volume(self._music_volume)
|
151
|
+
|
152
|
+
def get_music_volume(self) -> float:
|
153
|
+
return self._music_volume
|
154
|
+
|
155
|
+
def get_current_music(self) -> str | None:
|
156
|
+
return self._current_music
|