@@ -206,7 +206,7 @@ class Stage extends FlxBasic implements IBeatReceiver {
206206 }
207207
208208 // idk lemme check anyways just in case scripts did smth - Nex
209- if (event != null ) PlayState .instance .scripts . event (" onPostStageCreation" , event );
209+ if (event != null ) PlayState .instance .gameAndCharsEvent (" onPostStageCreation" , event );
210210
211211 // shortlived scripts destroy when the stage finishes setting up - Nex
212212 for (info in xmlImportedScripts ) if (info .shortLived ) {
@@ -349,17 +349,37 @@ class Stage extends FlxBasic implements IBeatReceiver {
349349 }
350350 }
351351
352- public function beatHit (curBeat : Int ) {}
353-
354- public function stepHit (curStep : Int ) {}
352+ /**
353+ * Same of destroy, but doesn't call the various script events.
354+ * @param destroySprites Whether the stage sprites should be destroyed
355+ * @param destroyScript Whether the stage script should be destroyed
356+ **/
357+ public function destroySilently (destroySprites : Bool = true , destroyScript : Bool = true ) {
358+ if (destroyScript && stageScript != null ) {
359+ if (PlayState .instance == state && PlayState .instance .scripts != null ) PlayState .instance .scripts .remove (stageScript );
360+ stageScript .destroy ();
361+ }
355362
356- public function measureHit (curMeasure : Int ) {}
363+ if (destroySprites )
364+ for (e in stageSprites )
365+ e ?. destroy ();
357366
358- public override function destroy () {
359367 startCam .put ();
360368 super .destroy ();
361369 }
362370
371+ public override function destroy () {
372+ if (PlayState .instance == state && PlayState .instance .scripts != null ) PlayState .instance .gameAndCharsCall (" onStageDestroy" , [this ]);
373+ stageScript ?. call (" destroy" );
374+ destroySilently ();
375+ }
376+
377+ public function beatHit (curBeat : Int ) {}
378+
379+ public function stepHit (curStep : Int ) {}
380+
381+ public function measureHit (curMeasure : Int ) {}
382+
363383 /**
364384 * Gets a list of stages that are available to be used.
365385 * @param mods Whenever only the mods folder should be checked
0 commit comments