Fix music not looping

This commit is contained in:
Sofia 2026-07-29 00:57:42 +03:00
parent f8759423bc
commit 5ccb0cd794
2 changed files with 10 additions and 8 deletions

View File

@ -9,4 +9,3 @@ main_menu_songs = Array[AudioStream]([ExtResource("1_xy4vl"), ExtResource("2_t25
[node name="audio_stream_player" type="AudioStreamPlayer" parent="." unique_id=1469531096] [node name="audio_stream_player" type="AudioStreamPlayer" parent="." unique_id=1469531096]
bus = &"Music" bus = &"Music"
playback_type = 1

View File

@ -27,12 +27,9 @@ pub struct MusicManager {
base: Base<Node3D>, base: Base<Node3D>,
} }
impl MusicManager { #[godot_api]
pub fn singleton() -> Gd<MusicManager> { impl INode3D for MusicManager {
get_autoload_by_name::<MusicManager>(MUSIC_MANAGER_GLOBAL) fn ready(&mut self) {
}
pub fn ready(&mut self) {
if let Some(player) = self.player.clone() { if let Some(player) = self.player.clone() {
player.signals().finished().connect_other(self, |s| { player.signals().finished().connect_other(self, |s| {
if let Some(playing) = s.currently_playing { if let Some(playing) = s.currently_playing {
@ -41,9 +38,15 @@ impl MusicManager {
}); });
} }
} }
}
impl MusicManager {
pub fn singleton() -> Gd<MusicManager> {
get_autoload_by_name::<MusicManager>(MUSIC_MANAGER_GLOBAL)
}
pub fn play(&mut self, music: Option<Music>, force: bool) { pub fn play(&mut self, music: Option<Music>, force: bool) {
if self.currently_playing == music { if self.currently_playing == music && !force {
return; return;
} }
self.currently_playing = music; self.currently_playing = music;