From a59bbe0ae3092980ec0b16efaf48565af81089e2 Mon Sep 17 00:00:00 2001 From: lulusuki Date: Mon, 23 Mar 2026 04:05:15 +0900 Subject: [PATCH] feat: update jukebox & maplist on deletion note: MapInfoContainer still does not update yet on map deletions --- scripts/SoundManager.cs | 28 +++++++++++++++++++++++++--- scripts/map/MapCache.cs | 7 ++++++- scripts/ui/menu/JukeboxPanel.cs | 7 +++++++ scripts/ui/menu/play/MapList.cs | 2 ++ 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/scripts/SoundManager.cs b/scripts/SoundManager.cs index 38fbf69..1c72a3e 100644 --- a/scripts/SoundManager.cs +++ b/scripts/SoundManager.cs @@ -13,8 +13,9 @@ public partial class SoundManager : Node, ISkinnable public static AudioStreamPlayer FailSound; public static AudioStreamPlayer Song; - [Signal] - public delegate void JukeboxPlayedEventHandler(Map map); + public Action JukeboxPlayed; + + public event Action JukeboxEmpty; public static int[] JukeboxQueue = []; public static int JukeboxIndex = 0; @@ -76,6 +77,27 @@ public override void _Ready() } }; + MapManager.MapDeleted += (map) => + { + UpdateJukeboxQueue(); + + if (Map != map) + { + return; + } + + if (JukeboxQueue.Length == 0) + { + Song.Stop(); + Map = null; + JukeboxEmpty?.Invoke(); + } + else + { + PlayJukebox(new Random().Next(0, JukeboxQueue.Length)); + } + }; + UpdateVolume(); static void start() @@ -159,7 +181,7 @@ public static void PlayJukebox(Map map, bool setRichPresence = true) Song.Stream = Util.Audio.LoadFromFile($"{MapUtil.MapsCacheFolder}/{map.Name}/audio.{map.AudioExt}"); Song.Play(); - Instance.EmitSignal(SignalName.JukeboxPlayed, map); + Instance.JukeboxPlayed?.Invoke(map); if (setRichPresence) { diff --git a/scripts/map/MapCache.cs b/scripts/map/MapCache.cs index c9fc517..58d7d44 100644 --- a/scripts/map/MapCache.cs +++ b/scripts/map/MapCache.cs @@ -252,7 +252,12 @@ public static void OrderAndSetMaps() if (map.Cover == Map.DefaultCover && File.Exists($"{path}/cover.png")) { byte[] coverBuffer = File.ReadAllBytes($"{path}/cover.png"); - Image image = Util.Misc.LoadImageFromBuffer(coverBuffer); + if (coverBuffer?.Length <= 0) + { + continue; + } + + Image image = Misc.LoadImageFromBuffer(coverBuffer); if (image != null) { diff --git a/scripts/ui/menu/JukeboxPanel.cs b/scripts/ui/menu/JukeboxPanel.cs index 3b9f6a0..24d90ef 100644 --- a/scripts/ui/menu/JukeboxPanel.cs +++ b/scripts/ui/menu/JukeboxPanel.cs @@ -57,6 +57,7 @@ public override void _Ready() UpdateSkin(); SoundManager.Instance.JukeboxPlayed += UpdateMap; + SoundManager.Instance.JukeboxEmpty += ClearMap; SkinManager.Instance.Loaded += UpdateSkin; } @@ -92,6 +93,12 @@ public override void _Input(InputEvent @event) } } + public void ClearMap() + { + title.Text = ""; + Map = null; + } + public void UpdateMap(Map map) { Map = map; diff --git a/scripts/ui/menu/play/MapList.cs b/scripts/ui/menu/play/MapList.cs index 0c9083d..0dec9c8 100644 --- a/scripts/ui/menu/play/MapList.cs +++ b/scripts/ui/menu/play/MapList.cs @@ -126,6 +126,8 @@ public override void _Ready() UpdateMaps(); }; + MapManager.MapDeleted += _ => UpdateMaps(); + Task.Run(() => UpdateMaps()); UpdateLayout(Layout);