From 7bbe356009cf68d7b0d1e7fee6c1938120a6e54b Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Wed, 27 Aug 2025 18:50:36 -0400 Subject: [PATCH] move a buncho stuff from Save.hx to SaveSystem.hx to rebase --- source/funkin/Preferences.hx | 43 ++--- source/funkin/api/newgrounds/NGSaveSlot.hx | 7 +- source/funkin/save/Save.hx | 175 +++++------------- source/funkin/save/SaveSystem.hx | 81 ++++++++ .../funkin/save/migrator/SaveDataMigrator.hx | 20 +- .../ui/debug/stageeditor/StageEditorState.hx | 4 +- source/funkin/ui/options/SaveDataMenu.hx | 9 +- source/funkin/util/Constants.hx | 6 + 8 files changed, 176 insertions(+), 169 deletions(-) create mode 100644 source/funkin/save/SaveSystem.hx diff --git a/source/funkin/Preferences.hx b/source/funkin/Preferences.hx index 91db2e9e0..83c6c783b 100644 --- a/source/funkin/Preferences.hx +++ b/source/funkin/Preferences.hx @@ -44,7 +44,7 @@ class Preferences #else var save:Save = Save.instance; save.options.framerate = value; - save.flush(); + Save.system.flush(); FlxG.updateFramerate = value; FlxG.drawFramerate = value; return value; @@ -74,7 +74,7 @@ class Preferences var save:Save = Save.instance; save.options.naughtyness = value; - save.flush(); + Save.system.flush(); return value; } @@ -93,7 +93,7 @@ class Preferences { var save:Save = Save.instance; save.options.downscroll = value; - save.flush(); + Save.system.flush(); return value; } @@ -112,7 +112,7 @@ class Preferences { var save:Save = Save.instance; save.options.flashingLights = value; - save.flush(); + Save.system.flush(); return value; } @@ -131,7 +131,7 @@ class Preferences { var save:Save = Save.instance; save.options.zoomCamera = value; - save.flush(); + Save.system.flush(); return value; } @@ -156,8 +156,9 @@ class Preferences if (value != Save.instance.options.debugDisplay) setDebugDisplayMode(value); var save = Save.instance; + save.options.debugDisplay = value; - save.flush(); + Save.system.flush(); return value; } @@ -178,7 +179,7 @@ class Preferences var save:Save = Save.instance; save.options.debugDisplayBGOpacity = value; - save.flush(); + Save.system.flush(); return value; } @@ -219,7 +220,7 @@ class Preferences var save:Save = Save.instance; save.options.hapticsMode = string; - save.flush(); + Save.system.flush(); return value; } @@ -238,7 +239,7 @@ class Preferences { var save:Save = Save.instance; save.options.hapticsIntensityMultiplier = value; - save.flush(); + Save.system.flush(); return value; } @@ -263,7 +264,7 @@ class Preferences var save:Save = Save.instance; save.options.autoPause = value; - save.flush(); + Save.system.flush(); return value; } @@ -282,7 +283,7 @@ class Preferences { var save:Save = Save.instance; save.options.autoFullscreen = value; - save.flush(); + Save.system.flush(); return value; } @@ -302,7 +303,7 @@ class Preferences { var save:Save = Save.instance; save.options.globalOffset = value; - save.flush(); + Save.system.flush(); return value; } @@ -349,7 +350,7 @@ class Preferences var save:Save = Save.instance; save.options.vsyncMode = string; - save.flush(); + Save.system.flush(); return value; } @@ -371,7 +372,7 @@ class Preferences var save:Save = Save.instance; save.options.unlockedFramerate = value; - save.flush(); + Save.system.flush(); return value; } @@ -411,7 +412,7 @@ class Preferences { var save:Save = Save.instance; save.options.strumlineBackgroundOpacity = value; - save.flush(); + Save.system.flush(); return value; } @@ -430,7 +431,7 @@ class Preferences { var save:Save = Save.instance; save.options.screenshot.shouldHideMouse = value; - save.flush(); + Save.system.flush(); return value; } @@ -449,7 +450,7 @@ class Preferences { var save:Save = Save.instance; save.options.screenshot.fancyPreview = value; - save.flush(); + Save.system.flush(); return value; } @@ -468,7 +469,7 @@ class Preferences { var save:Save = Save.instance; save.options.screenshot.previewOnSave = value; - save.flush(); + Save.system.flush(); return value; } @@ -557,7 +558,7 @@ class Preferences var save:Save = Save.instance; save.mobileOptions.screenTimeout = value; - save.flush(); + Save.system.flush(); return value; } @@ -576,7 +577,7 @@ class Preferences { var save:Save = Save.instance; save.mobileOptions.controlsScheme = value; - save.flush(); + Save.system.flush(); return value; } @@ -601,7 +602,7 @@ class Preferences { var save:Save = Save.instance; save.mobileOptions.noAds = value; - save.flush(); + Save.system.flush(); return value; } #end diff --git a/source/funkin/api/newgrounds/NGSaveSlot.hx b/source/funkin/api/newgrounds/NGSaveSlot.hx index aedc1c8c0..e34c57a4a 100644 --- a/source/funkin/api/newgrounds/NGSaveSlot.hx +++ b/source/funkin/api/newgrounds/NGSaveSlot.hx @@ -25,7 +25,7 @@ class NGSaveSlot public static function loadInstance():NGSaveSlot { - var loadedSave:NGSaveSlot = loadSlot(Save.BASE_SAVE_SLOT); + var loadedSave:NGSaveSlot = loadSlot(Constants.BASE_SAVE_SLOT); if (_instance == null) _instance = loadedSave; return loadedSave; @@ -46,11 +46,6 @@ class NGSaveSlot public function new(?ngSaveSlot:Null) { this.ngSaveSlot = ngSaveSlot; - - #if FLX_DEBUG - FlxG.console.registerClass(NGSaveSlot); - FlxG.console.registerClass(Save); - #end } /** diff --git a/source/funkin/save/Save.hx b/source/funkin/save/Save.hx index a67b283ec..d6423ea71 100644 --- a/source/funkin/save/Save.hx +++ b/source/funkin/save/Save.hx @@ -26,11 +26,7 @@ class Save implements ConsoleClass public static final SAVE_DATA_VERSION:thx.semver.Version = "2.1.1"; public static final SAVE_DATA_VERSION_RULE:thx.semver.VersionRule = ">=2.1.0 <2.2.0"; - /** - * We always use this save slot. - * Alter this if you want to use a different save slot. - */ - static final BASE_SAVE_SLOT:Int = 1; + public static var system:SaveSystem = new SaveSystem(); /** * Singleton for our Save class @@ -52,7 +48,7 @@ class Save implements ConsoleClass trace("[SAVE] Loading save..."); // Bind save data. - final loadedSave:Save = loadFromSlot(BASE_SAVE_SLOT); + final loadedSave:Save = loadFromSlot(Constants.BASE_SAVE_SLOT); _instance ??= loadedSave; return loadedSave; @@ -60,7 +56,7 @@ class Save implements ConsoleClass public static function clearData():Void { - _instance = clearSlot(BASE_SAVE_SLOT); + _instance = Save.system.clearSlot(Constants.BASE_SAVE_SLOT); } /** @@ -68,13 +64,13 @@ class Save implements ConsoleClass */ public function new(?data:RawSaveData) { - this.data = data ?? Save.getDefault(); + this.data = data ?? Save.getDefaultData(); // Make sure the verison number is up to date before we flush. updateVersionToLatest(); } - public static function getDefault():RawSaveData + public static function getDefaultData():RawSaveData { #if mobile var refreshRate:Int = FlxG.stage.window.displayMode.refreshRate; @@ -251,7 +247,7 @@ class Save implements ConsoleClass function set_ngSessionId(value:Null):Null { data.api.newgrounds.sessionId = value; - flush(); + Save.system.flush(); return data.api.newgrounds.sessionId; } @@ -265,7 +261,7 @@ class Save implements ConsoleClass function set_enabledModIds(value:Array):Array { data.mods.enabledMods = value; - flush(); + Save.system.flush(); return data.mods.enabledMods; } @@ -282,7 +278,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsChartEditor.previousFiles = value; - flush(); + Save.system.flush(); return data.optionsChartEditor.previousFiles; } @@ -299,7 +295,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsChartEditor.hasBackup = value; - flush(); + Save.system.flush(); return data.optionsChartEditor.hasBackup; } @@ -316,7 +312,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsChartEditor.noteQuant = value; - flush(); + Save.system.flush(); return data.optionsChartEditor.noteQuant; } @@ -333,7 +329,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsChartEditor.chartEditorLiveInputStyle = value; - flush(); + Save.system.flush(); return data.optionsChartEditor.chartEditorLiveInputStyle; } @@ -350,7 +346,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsChartEditor.downscroll = value; - flush(); + Save.system.flush(); return data.optionsChartEditor.downscroll; } @@ -367,7 +363,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsChartEditor.showNoteKinds = value; - flush(); + Save.system.flush(); return data.optionsChartEditor.showNoteKinds; } @@ -401,7 +397,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsChartEditor.playtestStartTime = value; - flush(); + Save.system.flush(); return data.optionsChartEditor.playtestStartTime; } @@ -418,7 +414,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsChartEditor.theme = value; - flush(); + Save.system.flush(); return data.optionsChartEditor.theme; } @@ -435,7 +431,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsChartEditor.metronomeVolume = value; - flush(); + Save.system.flush(); return data.optionsChartEditor.metronomeVolume; } @@ -452,7 +448,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsChartEditor.hitsoundVolumePlayer = value; - flush(); + Save.system.flush(); return data.optionsChartEditor.hitsoundVolumePlayer; } @@ -469,7 +465,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsChartEditor.hitsoundVolumeOpponent = value; - flush(); + Save.system.flush(); return data.optionsChartEditor.hitsoundVolumeOpponent; } @@ -486,7 +482,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsChartEditor.instVolume = value; - flush(); + Save.system.flush(); return data.optionsChartEditor.instVolume; } @@ -503,7 +499,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsChartEditor.playerVoiceVolume = value; - flush(); + Save.system.flush(); return data.optionsChartEditor.playerVoiceVolume; } @@ -520,7 +516,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsChartEditor.opponentVoiceVolume = value; - flush(); + Save.system.flush(); return data.optionsChartEditor.opponentVoiceVolume; } @@ -537,7 +533,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsChartEditor.themeMusic = value; - flush(); + Save.system.flush(); return data.optionsChartEditor.themeMusic; } @@ -554,7 +550,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsChartEditor.playbackSpeed = value; - flush(); + Save.system.flush(); return data.optionsChartEditor.playbackSpeed; } @@ -578,7 +574,7 @@ class Save implements ConsoleClass function set_oldChar(value:Bool):Bool { data.unlocks.oldChar = value; - flush(); + Save.system.flush(); return data.unlocks.oldChar; } @@ -595,7 +591,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsStageEditor.previousFiles = value; - flush(); + Save.system.flush(); return data.optionsStageEditor.previousFiles; } @@ -612,7 +608,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsStageEditor.hasBackup = value; - flush(); + Save.system.flush(); return data.optionsStageEditor.hasBackup; } @@ -629,7 +625,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsStageEditor.moveStep = value; - flush(); + Save.system.flush(); return data.optionsStageEditor.moveStep; } @@ -646,7 +642,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsStageEditor.angleStep = value; - flush(); + Save.system.flush(); return data.optionsStageEditor.angleStep; } @@ -663,7 +659,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsStageEditor.theme = value; - flush(); + Save.system.flush(); return data.optionsStageEditor.theme; } @@ -681,7 +677,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsStageEditor.bfChar = value; - flush(); + Save.system.flush(); return data.optionsStageEditor.bfChar; } @@ -699,7 +695,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsStageEditor.gfChar = value; - flush(); + Save.system.flush(); return data.optionsStageEditor.gfChar; } @@ -717,7 +713,7 @@ class Save implements ConsoleClass { // Set and apply. data.optionsStageEditor.dadChar = value; - flush(); + Save.system.flush(); return data.optionsStageEditor.dadChar; } @@ -732,7 +728,7 @@ class Save implements ConsoleClass trace('Character seen: ' + character); data.unlocks.charactersSeen.push(character); trace('New characters seen list: ' + data.unlocks.charactersSeen); - flush(); + Save.system.flush(); } } @@ -784,7 +780,7 @@ class Save implements ConsoleClass } level.set(difficultyId, score); - flush(); + Save.system.flush(); } public function isLevelHighScore(levelId:String, difficultyId:String = 'normal', score:SaveScoreData):Bool @@ -882,7 +878,7 @@ class Save implements ConsoleClass } song.set(difficultyId, score); - flush(); + Save.system.flush(); } /** @@ -922,7 +918,7 @@ class Save implements ConsoleClass song.set(difficultyId, newScore); - flush(); + Save.system.flush(); } /** @@ -1037,7 +1033,7 @@ class Save implements ConsoleClass if (data.favoriteSongs == null) { data.favoriteSongs = []; - flush(); + Save.system.flush(); }; return data.favoriteSongs.contains(id); @@ -1048,7 +1044,7 @@ class Save implements ConsoleClass if (!isSongFavorited(id)) { data.favoriteSongs.push(id); - flush(); + Save.system.flush(); } } @@ -1057,7 +1053,7 @@ class Save implements ConsoleClass if (isSongFavorited(id)) { data.favoriteSongs.remove(id); - flush(); + Save.system.flush(); } } @@ -1083,7 +1079,7 @@ class Save implements ConsoleClass public function setControls(playerId:Int, inputType:Device, controls:SaveControlsData):Void { - var getPlayer:String->PlayerControlData = function(id) return id == 0 ? data.options.controls.p1 : data.options.controls.p2; + final getPlayer:Int->PlayerControlData = function(id) return id == 0 ? data.options.controls.p1 : data.options.controls.p2; switch (inputType) { @@ -1092,8 +1088,6 @@ class Save implements ConsoleClass case Gamepad(_): getPlayer(playerId).gamepad = controls; } - - flush(); } public function isCharacterUnlocked(characterId:String):Bool @@ -1140,14 +1134,6 @@ class Save implements ConsoleClass return data.mute = value; } - /** - * Call this to make sure the save data is written to disk. - */ - public function flush():Void - { - FlxG.save.flush(); - } - /** * If you set slot to `2`, it will load an independent save file from slot 2. * @param slot @@ -1164,7 +1150,7 @@ class Save implements ConsoleClass case EMPTY: trace('[SAVE] Save data in slot ${slot} is empty, checking for legacy save data...'); - switch (fetchLegacySaveData()) + switch (Save.system.fetchLegacySaveData()) { case None: trace('[SAVE] No legacy save data found.'); @@ -1194,20 +1180,6 @@ class Save implements ConsoleClass } } - static function clearSlot(slot:Int):Save - { - FlxG.save.bind(Constants.SAVE_NAME + slot, Constants.SAVE_PATH); - - if (FlxG.save.status == EMPTY) return new Save(); - - // Archive the save data just in case. - // Not reliable but better than nothing. - var backupSlot:Int = Save.archiveBadSaveData(FlxG.save.data); - - FlxG.save.erase(); - return new Save(); - } - /** * Call this when there is an error loading the save data in slot X. */ @@ -1225,15 +1197,6 @@ class Save implements ConsoleClass return loadFromSlot(nextSlot); } - public static function archiveBadSaveData(data:Dynamic):Int - { - // We want to save this somewhere so we can try to recover it for the user in the future! - - final RECOVERY_SLOT_START = 1000; - - return writeToAvailableSlot(RECOVERY_SLOT_START, data); - } - public static function debug_queryBadSaveData():Void { final RECOVERY_SLOT_START = 1000; @@ -1256,27 +1219,6 @@ class Save implements ConsoleClass return targetSaveData.data; } - static function writeToAvailableSlot(slot:Int, data:Dynamic):Int - { - trace('[SAVE] Finding slot to write data to (starting with ${slot})...'); - - var targetSaveData:FlxSave = new FlxSave(); - targetSaveData.bind(Constants.SAVE_NAME + slot, Constants.SAVE_PATH); - while (!targetSaveData.isEmpty()) - { - // Keep trying to bind to slots until we find an empty slot. - trace('[SAVE] Slot ${slot} is taken, continuing...'); - slot++; - targetSaveData.bind(Constants.SAVE_NAME + slot, Constants.SAVE_PATH); - } - - trace('[SAVE] Writing data to slot ${slot}...'); - targetSaveData.mergeData(data, true); - - trace('[SAVE] Data written to slot ${slot}!'); - return slot; - } - /** * Return true if the given save slot is not empty. * @param slot The slot number to check. @@ -1318,31 +1260,13 @@ class Save implements ConsoleClass return -1; } - static function fetchLegacySaveData():Option - { - trace("[SAVE] Checking for legacy save data..."); - var legacySave:FlxSave = new FlxSave(); - legacySave.bind(Constants.SAVE_NAME_LEGACY, Constants.SAVE_PATH_LEGACY); - - if (legacySave.isEmpty()) - { - trace("[SAVE] No legacy save data found."); - return None; - } - else - { - trace("[SAVE] Legacy save data found."); - return Some(cast legacySave.data); - } - } - /** * Serialize this Save into a JSON string. * @param pretty Whether the JSON should be big ol string (false), * or pretty printed formatted with tabs (true) * @return The JSON string. */ - public function serialize(pretty:Bool = true):String + public function serializeJson(pretty:Bool = true):String { var ignoreNullOptionals:Bool = true; var writer = new json2object.JsonWriter(ignoreNullOptionals); @@ -1356,12 +1280,12 @@ class Save implements ConsoleClass public function debug_dumpSaveJsonSave():Void { - FileUtil.saveFile(haxe.io.Bytes.ofString(this.serialize()), [FileUtil.FILE_FILTER_JSON], null, null, './save.json', 'Write save data as JSON...'); + FileUtil.saveFile(haxe.io.Bytes.ofString(this.serializeJson()), [FileUtil.FILE_FILTER_JSON], null, null, './save.json', 'Write save data as JSON...'); } public function debug_dumpSaveJsonPrint():Void { - trace(this.serialize()); + trace(this.serializeJson()); } #if FEATURE_NEWGROUNDS @@ -1375,24 +1299,25 @@ class Save implements ConsoleClass public static function loadFromNewgrounds(onFinish:Void->Void):Void { trace('[SAVE] Loading Save Data from Newgrounds...'); - funkin.api.newgrounds.NGSaveSlot.instance.load(function(data:Dynamic) { - FlxG.save.bind(Constants.SAVE_NAME + BASE_SAVE_SLOT, Constants.SAVE_PATH); + + funkin.api.newgrounds.NGSaveSlot.instance.load((data:Dynamic) -> { + FlxG.save.bind(Constants.SAVE_NAME + Constants.BASE_SAVE_SLOT, Constants.SAVE_PATH); if (FlxG.save.status != EMPTY) { // best i can do in case the NG file is corrupted or something along those lines - var backupSlot:Int = Save.archiveBadSaveData(FlxG.save.data); + var backupSlot:Int = Save.system.archiveBadSaveData(FlxG.save.data); trace('[SAVE] Backed up current save data in case of emergency to $backupSlot!'); } FlxG.save.erase(); - FlxG.save.bind(Constants.SAVE_NAME + BASE_SAVE_SLOT, Constants.SAVE_PATH); // forces regeneration of the file as erase deletes it + FlxG.save.bind(Constants.SAVE_NAME + Constants.BASE_SAVE_SLOT, Constants.SAVE_PATH); // forces regeneration of the file as erase deletes it var gameSave = SaveDataMigrator.migrate(data); FlxG.save.mergeData(gameSave.data, true); _instance = gameSave; onFinish(); - }, function(error:io.newgrounds.Call.CallError) { + }, (error:io.newgrounds.Call.CallError) -> { var errorMsg:String = io.newgrounds.Call.CallErrorTools.toString(error); var msg = 'There was an error loading your save data from Newgrounds.'; diff --git a/source/funkin/save/SaveSystem.hx b/source/funkin/save/SaveSystem.hx new file mode 100644 index 000000000..d269bffef --- /dev/null +++ b/source/funkin/save/SaveSystem.hx @@ -0,0 +1,81 @@ +package funkin.save; + +import funkin.save.migrator.RawSaveData_v1_0_0; +import funkin.save.migrator.SaveDataMigrator; +import flixel.util.FlxSave; + +/** + * A bit more of the backend and nitty gritty of FNF's save system + */ +class SaveSystem +{ + public function new():Void {} + + /** + * Call this to make sure the save data is written to disk. + */ + public function flush():Void + { + FlxG.save.flush(); + } + + public function clearSlot(slot:Int):Save + { + FlxG.save.bind(Constants.SAVE_NAME + slot, Constants.SAVE_PATH); + + if (FlxG.save.status == EMPTY) return new Save(); + + // Archive the save data just in case. + // Not reliable but better than nothing. + var backupSlot:Int = Save.system.archiveBadSaveData(FlxG.save.data); + + FlxG.save.erase(); + return new Save(); + } + + public function fetchLegacySaveData():Option + { + trace("[SAVE] Checking for legacy save data..."); + var legacySave:FlxSave = new FlxSave(); + legacySave.bind(Constants.SAVE_NAME_LEGACY, Constants.SAVE_PATH_LEGACY); + + if (legacySave.isEmpty()) + { + trace("[SAVE] No legacy save data found."); + return None; + } + else + { + trace("[SAVE] Legacy save data found."); + return Some(cast legacySave.data); + } + } + + public function archiveBadSaveData(data:Dynamic):Int + { + // We want to save this somewhere so we can try to recover it for the user in the future! + final RECOVERY_SLOT_START = 1000; + return writeToAvailableSlot(RECOVERY_SLOT_START, data); + } + + function writeToAvailableSlot(slot:Int, data:Dynamic):Int + { + trace('[SAVE] Finding slot to write data to (starting with ${slot})...'); + + var targetSaveData:FlxSave = new FlxSave(); + targetSaveData.bind(Constants.SAVE_NAME + slot, Constants.SAVE_PATH); + while (!targetSaveData.isEmpty()) + { + // Keep trying to bind to slots until we find an empty slot. + trace('[SAVE] Slot ${slot} is taken, continuing...'); + slot++; + targetSaveData.bind(Constants.SAVE_NAME + slot, Constants.SAVE_PATH); + } + + trace('[SAVE] Writing data to slot ${slot}...'); + targetSaveData.mergeData(data, true); + + trace('[SAVE] Data written to slot ${slot}!'); + return slot; + } +} diff --git a/source/funkin/save/migrator/SaveDataMigrator.hx b/source/funkin/save/migrator/SaveDataMigrator.hx index 42b2d4657..1421e078f 100644 --- a/source/funkin/save/migrator/SaveDataMigrator.hx +++ b/source/funkin/save/migrator/SaveDataMigrator.hx @@ -19,7 +19,7 @@ class SaveDataMigrator { trace('[SAVE] No version found in save data! Returning blank data.'); trace(inputData); - return new Save(Save.getDefault()); + return new Save(Save.getDefaultData()); } else { @@ -28,7 +28,7 @@ class SaveDataMigrator if (VersionUtil.validateVersion(version, Save.SAVE_DATA_VERSION_RULE)) { // Import the structured data. - var saveDataWithDefaults:RawSaveData = cast thx.Objects.deepCombine(Save.getDefault(), inputData); + var saveDataWithDefaults:RawSaveData = cast thx.Objects.deepCombine(Save.getDefaultData(), inputData); var save:Save = new Save(saveDataWithDefaults); return save; } @@ -38,11 +38,13 @@ class SaveDataMigrator } else { - var message:String = 'Error migrating save data, expected ${Save.SAVE_DATA_VERSION}.'; - var slot:Int = Save.archiveBadSaveData(inputData); - var fullMessage:String = 'An error occurred migrating your save data.\n${message}\nInvalid data has been moved to save slot ${slot}.'; - funkin.util.WindowUtil.showError("Save Data Failure", fullMessage); - return new Save(Save.getDefault()); + var slot:Int = Save.system.archiveBadSaveData(inputData); + var message:String = 'An error occurred migrating your save data.' + + '\nError migrating save data, expected ${Save.SAVE_DATA_VERSION}.' + + '\nInvalid data has been moved to save slot ${slot}.'; + + funkin.util.WindowUtil.showError("Save Data Failure", message); + return new Save(Save.getDefaultData()); } } } @@ -50,7 +52,7 @@ class SaveDataMigrator static function migrate_v2_0_0(inputData:Dynamic):Save { // Import the structured data. - var saveDataWithDefaults:RawSaveData = cast thx.Objects.deepCombine(Save.getDefault(), inputData); + var saveDataWithDefaults:RawSaveData = cast thx.Objects.deepCombine(Save.getDefaultData(), inputData); // Reset these values to valid ones. saveDataWithDefaults.optionsChartEditor.chartEditorLiveInputStyle = funkin.ui.debug.charting.ChartEditorState.ChartEditorLiveInputStyle.None; @@ -68,7 +70,7 @@ class SaveDataMigrator { var inputSaveData:RawSaveData_v1_0_0 = cast inputData; - var result:Save = new Save(Save.getDefault()); + var result:Save = new Save(Save.getDefaultData()); result.volume = inputSaveData.volume; result.mute = inputSaveData.mute; diff --git a/source/funkin/ui/debug/stageeditor/StageEditorState.hx b/source/funkin/ui/debug/stageeditor/StageEditorState.hx index ee32f1c79..931a21e9c 100644 --- a/source/funkin/ui/debug/stageeditor/StageEditorState.hx +++ b/source/funkin/ui/debug/stageeditor/StageEditorState.hx @@ -856,7 +856,7 @@ class StageEditorState extends UIState files.pop(); Save.instance.stageEditorPreviousFiles = files; - Save.instance.flush(); + Save.system.flush(); } public function updateMarkerPos() @@ -1487,7 +1487,7 @@ class StageEditorState extends UIState saved = true; Save.instance.stageEditorHasBackup = true; - Save.instance.flush(); + Save.system.flush(); notifyChange("Auto-Save", "A Backup of this Stage has been made."); } diff --git a/source/funkin/ui/options/SaveDataMenu.hx b/source/funkin/ui/options/SaveDataMenu.hx index e5f3d34ca..2339064fb 100644 --- a/source/funkin/ui/options/SaveDataMenu.hx +++ b/source/funkin/ui/options/SaveDataMenu.hx @@ -23,12 +23,8 @@ class SaveDataMenu extends Page createItem("LOAD FROM NG", function() { openConfirmPrompt("This will overwrite \nALL your save data. - \nAre you sure? - ", "Overwrite", function() { - Save.loadFromNewgrounds(function() { - FlxG.switchState(() -> new funkin.InitState()); - }); - }); + \nAre you sure?", "Overwrite", + () -> Save.loadFromNewgrounds(() -> FlxG.switchState(() -> new funkin.InitState()))); }); createItem("SAVE TO NG", function() { @@ -101,6 +97,7 @@ class SaveDataMenu extends Page prompt = null; } } + public function openSaveDataPrompt() { openConfirmPrompt("This will delete diff --git a/source/funkin/util/Constants.hx b/source/funkin/util/Constants.hx index cb77403df..73e229613 100644 --- a/source/funkin/util/Constants.hx +++ b/source/funkin/util/Constants.hx @@ -660,4 +660,10 @@ class Constants * The legacy save slot name, used for backwards compatibility. */ public inline static final SAVE_NAME_LEGACY:String = 'funkin'; + + /** + * We always use this save slot. + * Alter this if you want to use a different save slot. + */ + public inline static final BASE_SAVE_SLOT:Int = 1; }