Funkin sound restarting music fix

This commit is contained in:
Lasercar 2025-03-06 11:37:05 +10:00
parent edb270d15e
commit 260f4f6132

View file

@ -313,13 +313,22 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
{
if (!(params.overrideExisting ?? false) && (FlxG.sound.music?.exists ?? false) && FlxG.sound.music.playing) return false;
var pathsFunction = params.pathsFunction ?? MUSIC;
var suffix = params.suffix ?? '';
var pathToUse = switch (pathsFunction)
{
case MUSIC: Paths.music('$key/$key');
case INST: Paths.inst('$key', suffix);
default: Paths.music('$key/$key');
}
if (!(params.restartTrack ?? false) && FlxG.sound.music?.playing)
{
if (FlxG.sound.music != null && Std.isOfType(FlxG.sound.music, FunkinSound))
{
var existingSound:FunkinSound = cast FlxG.sound.music;
// Stop here if we would play a matching music track.
if (existingSound._label == Paths.music('$key/$key'))
if (existingSound._label == pathToUse)
{
return false;
}
@ -348,15 +357,6 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
FlxG.log.warn('Tried and failed to find music metadata for $key');
}
}
var pathsFunction = params.pathsFunction ?? MUSIC;
var suffix = params.suffix ?? '';
var pathToUse = switch (pathsFunction)
{
case MUSIC: Paths.music('$key/$key');
case INST: Paths.inst('$key', suffix);
default: Paths.music('$key/$key');
}
var shouldLoadPartial = params.partialParams?.loadPartial ?? false;
// even if we arent' trying to partial load a song, we want to error out any songs in progress,
@ -514,7 +514,8 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
});
soundRequest.future.onComplete(function(partialSound) {
var snd = FunkinSound.load(partialSound, volume, looped, autoDestroy, autoPlay, false, onComplete, onLoad);
var snd:Null<FunkinSound> = FunkinSound.load(partialSound, volume, looped, autoDestroy, autoPlay, false, onComplete, onLoad);
if (snd != null) snd._label = path;
promise.complete(snd);
});
}