11package funkin .backend ;
22
3+ import funkin .backend .scripting .events .CancellableEvent ;
4+ import funkin .backend .scripting .events .TransitionCreationEvent ;
5+ import funkin .backend .scripting .Script ;
36import flixel .tweens .FlxTween ;
47import flixel .FlxState ;
58import funkin .backend .utils .FunkinParentDisabler ;
69
710class MusicBeatTransition extends MusicBeatSubstate {
11+ public static var script : String = " " ;
12+ public var transitionScript : Script ;
13+
814 var nextFrameSkip : Bool = false ;
915
1016 public var transitionTween : FlxTween = null ;
1117 public var transitionCamera : FlxCamera ;
1218 public var newState : FlxState ;
19+ public var transOut : Bool = false ;
20+
21+ public var allowSkip : Bool = true ;
1322
1423 public var blackSpr : FlxSprite ;
1524 public var transitionSprite : FunkinSprite ;
@@ -20,16 +29,30 @@ class MusicBeatTransition extends MusicBeatSubstate {
2029
2130 public override function create () {
2231 if (newState != null )
23- add (new FunkinParentDisabler (true ));
32+ add (new FunkinParentDisabler (true , false ));
2433
2534 transitionCamera = new FlxCamera ();
2635 transitionCamera .bgColor = 0 ;
2736 FlxG .cameras .add (transitionCamera , false );
2837
2938 cameras = [transitionCamera ];
30- var out = newState != null ;
3139
32- blackSpr = new FlxSprite (0 , out ? - transitionCamera .height : transitionCamera .height ).makeGraphic (1 , 1 , - 1 );
40+ transitionScript = Script .create (Paths .script (script ));
41+ transitionScript .setParent (this );
42+ transitionScript .load ();
43+
44+ var event = EventManager .get (TransitionCreationEvent ).recycle (newState != null , newState );
45+ transitionScript .call (' create' , [event ]);
46+
47+ transOut = event .transOut ;
48+ newState = event .newState ;
49+
50+ if (event .cancelled ) {
51+ super .create ();
52+ return ;
53+ }
54+
55+ blackSpr = new FlxSprite (0 , transOut ? - transitionCamera .height : transitionCamera .height ).makeGraphic (1 , 1 , - 1 );
3356 blackSpr .scale .set (transitionCamera .width , transitionCamera .height );
3457 blackSpr .color = 0xFF000000 ;
3558 blackSpr .updateHitbox ();
@@ -43,7 +66,7 @@ class MusicBeatTransition extends MusicBeatSubstate {
4366 } else {
4467 transitionSprite .screenCenter ();
4568 }
46- transitionCamera .flipY = ! out ;
69+ transitionCamera .flipY = ! transOut ;
4770 add (transitionSprite );
4871
4972 transitionCamera .scroll .y = transitionCamera .height ;
@@ -55,41 +78,59 @@ class MusicBeatTransition extends MusicBeatSubstate {
5578 });
5679
5780 super .create ();
81+ transitionScript .call (' postCreate' , [event ]);
5882 }
5983
6084 public override function update (elapsed : Float ) {
85+ transitionScript .call (' update' , [elapsed ]);
6186 super .update (elapsed );
6287
6388 if (nextFrameSkip ) {
64- finish ();
65- return ;
89+ var event = new CancellableEvent ();
90+ transitionScript .call (' onSkip' , [event ]);
91+ if (! event .cancelled ) {
92+ finish ();
93+ return ;
94+ }
6695 }
6796
68- if (! parent .persistentUpdate && FlxG .keys .pressed .SHIFT ) {
97+ if (allowSkip && ! parent .persistentUpdate && FlxG .keys .pressed .SHIFT ) {
6998 // skip
7099 if (newState != null ) {
71100 nextFrameSkip = true ;
72101 parent .persistentDraw = false ;
73102 } else {
74- finish ();
103+ var event = new CancellableEvent ();
104+ transitionScript .call (' onSkip' , [event ]);
105+ if (! event .cancelled ) {
106+ finish ();
107+ }
75108 }
76109 }
110+ transitionScript .call (' postUpdate' , [elapsed ]);
77111 }
78112
79113 public function finish () {
114+ var event = new CancellableEvent ();
115+ transitionScript .call (' onFinish' , [event ]);
116+ if (event .cancelled ) return ;
117+
80118 if (newState != null )
81119 FlxG .switchState (newState );
82120 close ();
121+
122+ transitionScript .call (' onPostFinish' );
83123 }
84124
85125 public override function destroy () {
86- if (transitionTween != null )
87- transitionTween .cancel ();
126+ transitionScript .call (' destroy' );
127+
128+ if (transitionTween != null ) transitionTween .cancel ();
88129 transitionTween = FlxDestroyUtil .destroy (transitionTween );
89- if (newState == null && FlxG .cameras .list .contains (transitionCamera ))
90- FlxG . cameras . remove ( transitionCamera ) ;
91- else
92- transitionCamera . bgColor = 0xFF000000 ;
130+ if (newState == null && FlxG .cameras .list .contains (transitionCamera )) FlxG . cameras . remove ( transitionCamera );
131+ else transitionCamera . bgColor = 0xFF000000 ;
132+
133+ transitionScript . destroy () ;
93134 super .destroy ();
94135 }
95136}
0 commit comments