From 0fc10b5bebcb05010010f4135f2c64b8171aaadf Mon Sep 17 00:00:00 2001 From: DetectiveBaldi <86160807+DetectiveBaldi@users.noreply.github.com> Date: Fri, 10 Jan 2025 17:33:01 -0500 Subject: [PATCH 1/4] base --- flixel/sound/FlxSound.hx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/flixel/sound/FlxSound.hx b/flixel/sound/FlxSound.hx index b45f6c8f1e..2c4338b80c 100644 --- a/flixel/sound/FlxSound.hx +++ b/flixel/sound/FlxSound.hx @@ -6,6 +6,7 @@ import flixel.math.FlxMath; import flixel.math.FlxPoint; import flixel.system.FlxAssets.FlxSoundAsset; import flixel.tweens.FlxTween; +import flixel.util.FlxSignal; import flixel.util.FlxStringUtil; import openfl.events.Event; import openfl.events.IEventDispatcher; @@ -69,10 +70,16 @@ class FlxSound extends FlxBasic */ public var autoDestroy:Bool; + /** + * Signal that is dispatched on sound complete. + */ + public var onFinish:FlxSignal; + /** * Tracker for sound complete callback. If assigned, will be called * each time when sound reaches its end. */ + @:deprecated("`FlxSound.onComplete` is deprecated! Use `FlxSound.onFinish` instead.") public var onComplete:Void->Void; /** @@ -245,11 +252,15 @@ class FlxSound extends FlxBasic amplitudeRight = 0; autoDestroy = false; + if (onFinish == null) + onFinish = new FlxSignal(); + if (_transform == null) _transform = new SoundTransform(); _transform.pan = 0; } + @:haxe.warning("-WDeprecated") override public function destroy():Void { // Prevents double destroy @@ -431,12 +442,15 @@ class FlxSound extends FlxBasic } #end + @:haxe.warning("-WDeprecated") function init(Looped:Bool = false, AutoDestroy:Bool = false, ?OnComplete:Void->Void):FlxSound { looped = Looped; autoDestroy = AutoDestroy; updateTransform(); exists = true; + onFinish.removeAll(); + onFinish.add(onComplete); onComplete = OnComplete; #if FLX_PITCH pitch = 1; @@ -636,8 +650,11 @@ class FlxSound extends FlxBasic * An internal helper function used to help Flash * clean up finished sounds or restart looped sounds. */ + @:haxe.warning("-WDeprecated") function stopped(?_):Void { + onFinish.dispatch(); + if (onComplete != null) onComplete(); From 1239f3f0dc983f3bfaac1ea9dc32de8ecec1ba25 Mon Sep 17 00:00:00 2001 From: DetectiveBaldi <86160807+DetectiveBaldi@users.noreply.github.com> Date: Fri, 10 Jan 2025 17:35:08 -0500 Subject: [PATCH 2/4] what was my thinking process here --- flixel/sound/FlxSound.hx | 1 - 1 file changed, 1 deletion(-) diff --git a/flixel/sound/FlxSound.hx b/flixel/sound/FlxSound.hx index 2c4338b80c..01478518a2 100644 --- a/flixel/sound/FlxSound.hx +++ b/flixel/sound/FlxSound.hx @@ -449,7 +449,6 @@ class FlxSound extends FlxBasic autoDestroy = AutoDestroy; updateTransform(); exists = true; - onFinish.removeAll(); onFinish.add(onComplete); onComplete = OnComplete; #if FLX_PITCH From 2d78ec5a3a5cdf874b18234ed9129a656d0369b4 Mon Sep 17 00:00:00 2001 From: DetectiveBaldi <86160807+DetectiveBaldi@users.noreply.github.com> Date: Fri, 10 Jan 2025 19:09:31 -0500 Subject: [PATCH 3/4] remove all callbacks on load + destroy --- flixel/sound/FlxSound.hx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/flixel/sound/FlxSound.hx b/flixel/sound/FlxSound.hx index 01478518a2..d8ed4a78af 100644 --- a/flixel/sound/FlxSound.hx +++ b/flixel/sound/FlxSound.hx @@ -231,6 +231,9 @@ class FlxSound extends FlxBasic */ function reset():Void { + if (onFinish == null) + onFinish = new FlxSignal(); + destroy(); x = 0; @@ -251,9 +254,6 @@ class FlxSound extends FlxBasic amplitudeLeft = 0; amplitudeRight = 0; autoDestroy = false; - - if (onFinish == null) - onFinish = new FlxSignal(); if (_transform == null) _transform = new SoundTransform(); @@ -287,6 +287,8 @@ class FlxSound extends FlxBasic _sound = null; } + onFinish.removeAll(); + onComplete = null; super.destroy(); @@ -449,6 +451,7 @@ class FlxSound extends FlxBasic autoDestroy = AutoDestroy; updateTransform(); exists = true; + onFinish.removeAll(); onFinish.add(onComplete); onComplete = OnComplete; #if FLX_PITCH From dde22c550137a151dda646a1aec56a026f43a011 Mon Sep 17 00:00:00 2001 From: DetectiveBaldi <86160807+DetectiveBaldi@users.noreply.github.com> Date: Fri, 10 Jan 2025 19:13:39 -0500 Subject: [PATCH 4/4] make onFinish final --- flixel/sound/FlxSound.hx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/flixel/sound/FlxSound.hx b/flixel/sound/FlxSound.hx index d8ed4a78af..4ee5a64570 100644 --- a/flixel/sound/FlxSound.hx +++ b/flixel/sound/FlxSound.hx @@ -73,7 +73,7 @@ class FlxSound extends FlxBasic /** * Signal that is dispatched on sound complete. */ - public var onFinish:FlxSignal; + public final onFinish:FlxSignal; /** * Tracker for sound complete callback. If assigned, will be called @@ -223,6 +223,7 @@ class FlxSound extends FlxBasic public function new() { super(); + onFinish = new FlxSignal(); reset(); } @@ -231,9 +232,6 @@ class FlxSound extends FlxBasic */ function reset():Void { - if (onFinish == null) - onFinish = new FlxSignal(); - destroy(); x = 0;