Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions scripts/SoundManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Map> JukeboxPlayed;

public event Action JukeboxEmpty;

public static int[] JukeboxQueue = [];
public static int JukeboxIndex = 0;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
{
Expand Down
7 changes: 6 additions & 1 deletion scripts/map/MapCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
7 changes: 7 additions & 0 deletions scripts/ui/menu/JukeboxPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public override void _Ready()
UpdateSkin();

SoundManager.Instance.JukeboxPlayed += UpdateMap;
SoundManager.Instance.JukeboxEmpty += ClearMap;
SkinManager.Instance.Loaded += UpdateSkin;
}

Expand Down Expand Up @@ -92,6 +93,12 @@ public override void _Input(InputEvent @event)
}
}

public void ClearMap()
{
title.Text = "";
Map = null;
}

public void UpdateMap(Map map)
{
Map = map;
Expand Down
2 changes: 2 additions & 0 deletions scripts/ui/menu/play/MapList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public override void _Ready()
UpdateMaps();
};

MapManager.MapDeleted += _ => UpdateMaps();

Task.Run(() => UpdateMaps());

UpdateLayout(Layout);
Expand Down
Loading