From 6e2877c2a9dc2d6de1ef793d35b6746f766d86b5 Mon Sep 17 00:00:00 2001 From: Microkat <89645987+KadePleaseHelpMe@users.noreply.github.com> Date: Sat, 14 Dec 2024 09:47:47 -0500 Subject: [PATCH 1/2] Added flipX and flipY to loadSpriteFromXML() (#487) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #478 * Added flipX and flipY to loadSpriteFromXML() why was this not already implemented? Nevermind I'm pretty sure it's because parseBool isn't a thing * WHOOPS gotta update my heckin repo * Wow neo is good at simplifying stuff rip parseBool but HAXE MAKE IT A THING * sigma ¯\_(ツ)_/¯ * Allow for flipx and flipy as opposed to flipX and flipY (cammel text) * gaming chair 🪑 --------- Co-authored-by: ⍚~Nex <87421482+NexIsDumb@users.noreply.github.com> --- source/funkin/backend/utils/XMLUtil.hx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/funkin/backend/utils/XMLUtil.hx b/source/funkin/backend/utils/XMLUtil.hx index df5519859..a074f97d3 100644 --- a/source/funkin/backend/utils/XMLUtil.hx +++ b/source/funkin/backend/utils/XMLUtil.hx @@ -143,6 +143,8 @@ class XMLUtil { var graphicSizey:Null = Std.parseInt(node.att.graphicSizey); if (graphicSizey.isNotNull()) spr.setGraphicSize(0, graphicSizey); } + if (node.has.flipX) spr.flipX = node.att.flipX == "true"; + if (node.has.flipY) spr.flipY = node.att.flipY == "true"; if (node.has.updateHitbox && node.att.updateHitbox == "true") spr.updateHitbox(); if (node.has.zoomfactor) @@ -392,4 +394,4 @@ typedef BeatAnim = { interface IXMLEvents { public function onPropertySet(property:String, value:Dynamic):Void; -} \ No newline at end of file +} From e2a39517025e38832d24ce999be872963a19d105 Mon Sep 17 00:00:00 2001 From: TheZoroForce240 <86524550+TheZoroForce240@users.noreply.github.com> Date: Sat, 14 Dec 2024 15:48:58 +0000 Subject: [PATCH 2/2] Transition crash fix again + changeable transition script (#493) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix transition crash when skipping * transition crash fix again * rename transition script var * better transition scripting * add more transition script functions * move post create to actually be after * change this * actually destroy the script * add a variable to disable skipping the transition * opa idk felt better like this --------- Co-authored-by: ⍚~Nex <87421482+NexIsDumb@users.noreply.github.com> --- source/funkin/backend/MusicBeatTransition.hx | 69 +++++++++++++++---- .../events/TransitionCreationEvent.hx | 18 +++++ source/funkin/backend/system/MainState.hx | 1 + .../backend/utils/FunkinParentDisabler.hx | 9 ++- 4 files changed, 82 insertions(+), 15 deletions(-) create mode 100644 source/funkin/backend/scripting/events/TransitionCreationEvent.hx diff --git a/source/funkin/backend/MusicBeatTransition.hx b/source/funkin/backend/MusicBeatTransition.hx index 34b02388d..58ddc2c5a 100644 --- a/source/funkin/backend/MusicBeatTransition.hx +++ b/source/funkin/backend/MusicBeatTransition.hx @@ -1,15 +1,24 @@ package funkin.backend; +import funkin.backend.scripting.events.CancellableEvent; +import funkin.backend.scripting.events.TransitionCreationEvent; +import funkin.backend.scripting.Script; import flixel.tweens.FlxTween; import flixel.FlxState; import funkin.backend.utils.FunkinParentDisabler; class MusicBeatTransition extends MusicBeatSubstate { + public static var script:String = ""; + public var transitionScript:Script; + var nextFrameSkip:Bool = false; public var transitionTween:FlxTween = null; public var transitionCamera:FlxCamera; public var newState:FlxState; + public var transOut:Bool = false; + + public var allowSkip:Bool = true; public var blackSpr:FlxSprite; public var transitionSprite:FunkinSprite; @@ -20,16 +29,30 @@ class MusicBeatTransition extends MusicBeatSubstate { public override function create() { if (newState != null) - add(new FunkinParentDisabler(true)); + add(new FunkinParentDisabler(true, false)); transitionCamera = new FlxCamera(); transitionCamera.bgColor = 0; FlxG.cameras.add(transitionCamera, false); cameras = [transitionCamera]; - var out = newState != null; - blackSpr = new FlxSprite(0, out ? -transitionCamera.height : transitionCamera.height).makeGraphic(1, 1, -1); + transitionScript = Script.create(Paths.script(script)); + transitionScript.setParent(this); + transitionScript.load(); + + var event = EventManager.get(TransitionCreationEvent).recycle(newState != null, newState); + transitionScript.call('create', [event]); + + transOut = event.transOut; + newState = event.newState; + + if (event.cancelled) { + super.create(); + return; + } + + blackSpr = new FlxSprite(0, transOut ? -transitionCamera.height : transitionCamera.height).makeGraphic(1, 1, -1); blackSpr.scale.set(transitionCamera.width, transitionCamera.height); blackSpr.color = 0xFF000000; blackSpr.updateHitbox(); @@ -43,7 +66,7 @@ class MusicBeatTransition extends MusicBeatSubstate { } else { transitionSprite.screenCenter(); } - transitionCamera.flipY = !out; + transitionCamera.flipY = !transOut; add(transitionSprite); transitionCamera.scroll.y = transitionCamera.height; @@ -55,41 +78,59 @@ class MusicBeatTransition extends MusicBeatSubstate { }); super.create(); + transitionScript.call('postCreate', [event]); } public override function update(elapsed:Float) { + transitionScript.call('update', [elapsed]); super.update(elapsed); if (nextFrameSkip) { - finish(); - return; + var event = new CancellableEvent(); + transitionScript.call('onSkip', [event]); + if (!event.cancelled) { + finish(); + return; + } } - if (!parent.persistentUpdate && FlxG.keys.pressed.SHIFT) { + if (allowSkip && !parent.persistentUpdate && FlxG.keys.pressed.SHIFT) { // skip if (newState != null) { nextFrameSkip = true; parent.persistentDraw = false; } else { - finish(); + var event = new CancellableEvent(); + transitionScript.call('onSkip', [event]); + if (!event.cancelled) { + finish(); + } } } + transitionScript.call('postUpdate', [elapsed]); } public function finish() { + var event = new CancellableEvent(); + transitionScript.call('onFinish', [event]); + if (event.cancelled) return; + if (newState != null) FlxG.switchState(newState); close(); + + transitionScript.call('onPostFinish'); } public override function destroy() { - if (transitionTween != null) - transitionTween.cancel(); + transitionScript.call('destroy'); + + if (transitionTween != null) transitionTween.cancel(); transitionTween = FlxDestroyUtil.destroy(transitionTween); - if (newState == null && FlxG.cameras.list.contains(transitionCamera)) - FlxG.cameras.remove(transitionCamera); - else - transitionCamera.bgColor = 0xFF000000; + if (newState == null && FlxG.cameras.list.contains(transitionCamera)) FlxG.cameras.remove(transitionCamera); + else transitionCamera.bgColor = 0xFF000000; + + transitionScript.destroy(); super.destroy(); } } \ No newline at end of file diff --git a/source/funkin/backend/scripting/events/TransitionCreationEvent.hx b/source/funkin/backend/scripting/events/TransitionCreationEvent.hx new file mode 100644 index 000000000..e72a56c22 --- /dev/null +++ b/source/funkin/backend/scripting/events/TransitionCreationEvent.hx @@ -0,0 +1,18 @@ +package funkin.backend.scripting.events; + +import flixel.FlxState; + +/** + * CANCEL this event to prevent default behaviour! + */ +final class TransitionCreationEvent extends CancellableEvent { + /** + * If the transition is going out into another state + */ + public var transOut:Bool; + + /** + * The state that is about to be loaded (only on trans out) + */ + public var newState:FlxState; +} \ No newline at end of file diff --git a/source/funkin/backend/system/MainState.hx b/source/funkin/backend/system/MainState.hx index 14c40aff8..a5011d6d6 100644 --- a/source/funkin/backend/system/MainState.hx +++ b/source/funkin/backend/system/MainState.hx @@ -53,6 +53,7 @@ class MainState extends FlxState { } #end + MusicBeatTransition.script = ""; Main.refreshAssets(); ModsFolder.onModSwitch.dispatch(ModsFolder.currentModFolder); DiscordUtil.init(); diff --git a/source/funkin/backend/utils/FunkinParentDisabler.hx b/source/funkin/backend/utils/FunkinParentDisabler.hx index 29e076bef..bd8b16840 100644 --- a/source/funkin/backend/utils/FunkinParentDisabler.hx +++ b/source/funkin/backend/utils/FunkinParentDisabler.hx @@ -19,9 +19,11 @@ class FunkinParentDisabler extends FlxBasic { var __timers:Array; var __sounds:Array; var __replaceUponDestroy:Bool; - public function new(replaceUponDestroy:Bool = false) { + var __restoreUponDestroy:Bool; + public function new(replaceUponDestroy:Bool = false, restoreUponDestroy:Bool = true) { super(); __replaceUponDestroy = replaceUponDestroy; + __restoreUponDestroy = restoreUponDestroy; @:privateAccess { // tweens __tweens = FlxTween.globalManager._tweens.copy(); @@ -53,6 +55,11 @@ class FunkinParentDisabler extends FlxBasic { public override function destroy() { super.destroy(); @:privateAccess { + if (!__restoreUponDestroy) { + for(t in __tweens) { t.cancel(); t.destroy(); }; + for(t in __timers) { t.cancel(); t.destroy(); }; + return; + } if (__replaceUponDestroy) { FlxTween.globalManager._tweens = __tweens; FlxTimer.globalManager._timers = __timers;