diff --git a/source/FreeplayState.hx b/source/FreeplayState.hx index 5148bf2..d4372e0 100644 --- a/source/FreeplayState.hx +++ b/source/FreeplayState.hx @@ -67,6 +67,7 @@ class FreeplayState extends MusicBeatState override function create() { + clean(); var initSonglist = CoolUtil.coolTextFile(Paths.txt('data/freeplaySonglist')); //var diffList = ""; @@ -398,6 +399,7 @@ class FreeplayState extends MusicBeatState PlayState.isSM = false; #end LoadingState.loadAndSwitchState(new PlayState()); + clean(); } } diff --git a/source/HelperFunctions.hx b/source/HelperFunctions.hx index 4b704c1..e6dc6a9 100644 --- a/source/HelperFunctions.hx +++ b/source/HelperFunctions.hx @@ -1,3 +1,4 @@ +import flixel.FlxG; import flixel.math.FlxMath; class HelperFunctions diff --git a/source/MainMenuState.hx b/source/MainMenuState.hx index 774dbae..7f60215 100644 --- a/source/MainMenuState.hx +++ b/source/MainMenuState.hx @@ -49,6 +49,7 @@ class MainMenuState extends MusicBeatState override function create() { + clean(); #if windows // Updating Discord Rich Presence DiscordClient.changePresence("In the Menus", null); diff --git a/source/MusicBeatState.hx b/source/MusicBeatState.hx index 47dac29..5575771 100644 --- a/source/MusicBeatState.hx +++ b/source/MusicBeatState.hx @@ -1,5 +1,6 @@ package; +import flixel.FlxBasic; #if windows import Discord.DiscordClient; #end @@ -22,6 +23,26 @@ class MusicBeatState extends FlxUIState inline function get_controls():Controls return PlayerSettings.player1.controls; + private var assets:Array = []; + + override function add(Object:flixel.FlxBasic):flixel.FlxBasic + { + if (FlxG.save.data.optimize) + assets.push(Object); + return super.add(Object); + } + + public function clean() + { + if (FlxG.save.data.optimize) + { + for(i in assets) + { + remove(i); + } + } + } + override function create() { TimingStruct.clearTimings(); diff --git a/source/OptionsMenu.hx b/source/OptionsMenu.hx index 95454c8..440df09 100644 --- a/source/OptionsMenu.hx +++ b/source/OptionsMenu.hx @@ -86,6 +86,7 @@ class OptionsMenu extends MusicBeatState var blackBorder:FlxSprite; override function create() { + clean(); instance = this; var menuBG:FlxSprite = new FlxSprite().loadGraphic(Paths.image("menuDesat")); @@ -139,7 +140,9 @@ class OptionsMenu extends MusicBeatState if (acceptInput) { if (controls.BACK && !isCat) + { FlxG.switchState(new MainMenuState()); + } else if (controls.BACK) { isCat = false; diff --git a/source/PauseSubState.hx b/source/PauseSubState.hx index 747c7cb..8f22367 100644 --- a/source/PauseSubState.hx +++ b/source/PauseSubState.hx @@ -209,6 +209,7 @@ class PauseSubState extends MusicBeatSubstate { var daSelected:String = menuItems[curSelected]; + switch (daSelected) { case "Resume": @@ -221,6 +222,7 @@ class PauseSubState extends MusicBeatSubstate PlayState.instance.remove(PlayState.instance.videoSprite); PlayState.instance.removedVideo = true; } + PlayState.instance.clean(); FlxG.resetState(); case "Exit to menu": PlayState.startTime = 0; @@ -247,6 +249,8 @@ class PauseSubState extends MusicBeatSubstate if (FlxG.save.data.fpsCap > 290) (cast (Lib.current.getChildAt(0), Main)).setFPSCap(290); + PlayState.instance.clean(); + if (PlayState.isStoryMode) FlxG.switchState(new StoryMenuState()); else diff --git a/source/PlayState.hx b/source/PlayState.hx index d287f8c..fa82e9d 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -2439,6 +2439,7 @@ class PlayState extends MusicBeatState { trace('GITAROO MAN EASTER EGG'); FlxG.switchState(new GitarooPause()); + clean(); } else openSubState(new PauseSubState(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y)); @@ -2460,7 +2461,9 @@ class PlayState extends MusicBeatState #if windows DiscordClient.changePresence("Chart Editor", null, null, true); #end + FlxG.switchState(new ChartingState()); + clean(); FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN, handleInput); FlxG.stage.removeEventListener(KeyboardEvent.KEY_UP, releaseInput); #if windows @@ -2514,6 +2517,7 @@ class PlayState extends MusicBeatState } FlxG.switchState(new AnimationDebug(SONG.player2)); + clean(); FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN, handleInput); FlxG.stage.removeEventListener(KeyboardEvent.KEY_UP, releaseInput); #if windows @@ -2528,6 +2532,7 @@ class PlayState extends MusicBeatState if (FlxG.keys.justPressed.ZERO) { FlxG.switchState(new AnimationDebug(SONG.player1)); + clean(); FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN, handleInput); FlxG.stage.removeEventListener(KeyboardEvent.KEY_UP, releaseInput); #if windows @@ -3388,6 +3393,7 @@ class PlayState extends MusicBeatState FlxG.sound.playMusic(Paths.music('freakyMenu')); offsetTesting = false; LoadingState.loadAndSwitchState(new OptionsMenu()); + clean(); FlxG.save.data.offset = offsetTest; } else @@ -3425,6 +3431,7 @@ class PlayState extends MusicBeatState FlxG.sound.playMusic(Paths.music('freakyMenu')); Conductor.changeBPM(102); FlxG.switchState(new StoryMenuState()); + clean(); } #if windows @@ -3479,6 +3486,7 @@ class PlayState extends MusicBeatState FlxG.sound.music.stop(); LoadingState.loadAndSwitchState(new PlayState()); + clean(); } } else @@ -3499,7 +3507,10 @@ class PlayState extends MusicBeatState }); } else + { FlxG.switchState(new FreeplayState()); + clean(); + } } } } diff --git a/source/ResultsScreen.hx b/source/ResultsScreen.hx index 7c7920a..66b5569 100644 --- a/source/ResultsScreen.hx +++ b/source/ResultsScreen.hx @@ -218,6 +218,7 @@ class ResultsScreen extends FlxSubState } else FlxG.switchState(new FreeplayState()); + PlayState.instance.clean(); } if (FlxG.keys.justPressed.F1 && !PlayState.loadRep) @@ -288,6 +289,7 @@ class ResultsScreen extends FlxSubState PlayState.isStoryMode = false; PlayState.storyDifficulty = PlayState.rep.replay.songDiff; LoadingState.loadAndSwitchState(new PlayState()); + PlayState.instance.clean(); } if (FlxG.keys.justPressed.F2 && !PlayState.loadRep) @@ -324,6 +326,7 @@ class ResultsScreen extends FlxSubState PlayState.isStoryMode = false; PlayState.storyDifficulty = PlayState.storyDifficulty; LoadingState.loadAndSwitchState(new PlayState()); + PlayState.instance.clean(); } super.update(elapsed); diff --git a/source/TitleState.hx b/source/TitleState.hx index 4860e3a..3c63121 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -99,8 +99,10 @@ class TitleState extends MusicBeatState #if FREEPLAY FlxG.switchState(new FreeplayState()); + clean(); #elseif CHARTING FlxG.switchState(new ChartingState()); + clean(); #else #if !cpp new FlxTimer().start(1, function(tmr:FlxTimer) @@ -305,16 +307,19 @@ class TitleState extends MusicBeatState OutdatedSubState.needVer = returnedData[0]; OutdatedSubState.currChanges = returnedData[1]; FlxG.switchState(new OutdatedSubState()); + clean(); } else { FlxG.switchState(new MainMenuState()); + clean(); } } http.onError = function (error) { trace('error: $error'); FlxG.switchState(new MainMenuState()); // fail but we go anyway + clean(); } http.request();