Transition crash fix again + changeable transition script (#493)
* 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>
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -53,6 +53,7 @@ class MainState extends FlxState {
|
||||
}
|
||||
#end
|
||||
|
||||
MusicBeatTransition.script = "";
|
||||
Main.refreshAssets();
|
||||
ModsFolder.onModSwitch.dispatch(ModsFolder.currentModFolder);
|
||||
DiscordUtil.init();
|
||||
|
||||
@@ -19,9 +19,11 @@ class FunkinParentDisabler extends FlxBasic {
|
||||
var __timers:Array<FlxTimer>;
|
||||
var __sounds:Array<FlxSound>;
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user