77/**
88 * <summary>SaveSystem: Manages FileI/O of configs and save files.</summary>
99 */
10- public static class SaveSystem
10+ public static class Configkeeper
1111{
1212 #region Config
1313 private const string UserConfigPath = "user://Options.cfg" ;
@@ -31,8 +31,6 @@ public static class SaveSystem
3131 private const bool DefaultTypeIsArrow = false ;
3232 private const bool DefaultVerticalScroll = true ;
3333 private const bool DefaultHighCon = false ;
34- private const bool DefaultFirstTime = true ;
35- private const bool DefaultHasWon = false ;
3634
3735 public enum ConfigSettings
3836 {
@@ -53,8 +51,6 @@ public enum ConfigSettings
5351 LanguageKey ,
5452 TypeIsArrow ,
5553 HighContrast ,
56- FirstTime ,
57- HasWon ,
5854 VerticalScroll ,
5955 }
6056
@@ -81,8 +77,6 @@ private static void InitConfig()
8177 UpdateConfig ( ConfigSettings . LanguageKey , DefaultLanguage ) ;
8278 UpdateConfig ( ConfigSettings . TypeIsArrow , DefaultTypeIsArrow ) ;
8379 UpdateConfig ( ConfigSettings . HighContrast , DefaultHighCon ) ;
84- UpdateConfig ( ConfigSettings . FirstTime , DefaultFirstTime ) ;
85- UpdateConfig ( ConfigSettings . HasWon , DefaultHasWon ) ;
8680 UpdateConfig ( ConfigSettings . VerticalScroll , DefaultVerticalScroll ) ;
8781 }
8882
@@ -151,12 +145,6 @@ public static void UpdateConfig(ConfigSettings setting, Variant value)
151145 case ConfigSettings . HighContrast :
152146 _curConfigData . SetValue ( "Options" , "HighContrast" , value ) ;
153147 break ;
154- case ConfigSettings . FirstTime :
155- _curConfigData . SetValue ( "Game" , "FirstTime" , value ) ;
156- break ;
157- case ConfigSettings . HasWon :
158- _curConfigData . SetValue ( "Game" , "HasWon" , value ) ;
159- break ;
160148 default :
161149 GD . PushError ( "SaveSystem.UpdateConfig: Invalid config setting passed. " + setting ) ;
162150 break ;
@@ -298,10 +286,6 @@ public static Variant GetConfigValue(ConfigSettings setting)
298286 return _curConfigData . GetValue ( "Options" , "VerticalScroll" , DefaultVerticalScroll ) ;
299287 case ConfigSettings . HighContrast :
300288 return _curConfigData . GetValue ( "Options" , "HighContrast" , DefaultHighCon ) ;
301- case ConfigSettings . FirstTime :
302- return _curConfigData . GetValue ( "Game" , "FirstTime" , DefaultFirstTime ) ;
303- case ConfigSettings . HasWon :
304- return _curConfigData . GetValue ( "Game" , "HasWon" , DefaultHasWon ) ;
305289 default :
306290 GD . PushError ( "Invalid config setting passed. " + setting ) ;
307291 return float . MinValue ;
@@ -399,110 +383,4 @@ public static void ClearConfig()
399383 InitConfig ( ) ;
400384 }
401385 #endregion
402-
403- #region Save
404-
405- private const string UserSavePath = "user://MidnighRiff.save" ;
406-
407- public class SaveFile
408- {
409- public ulong RngSeed { get ; init ; }
410- public ulong RngState { get ; init ; }
411- public int LastRoomIdx { get ; init ; }
412- public int Area { get ; init ; }
413-
414- public int Money { get ; init ; }
415- public int [ ] NoteIds { get ; init ; }
416- public int [ ] RelicIds { get ; init ; }
417- public int [ ] BattlePool { get ; init ; }
418- public int [ ] EventPool { get ; init ; }
419- public int PlayerHealth { get ; init ; }
420- public int Shortcuts { get ; init ; }
421- public int PlayerMaxCombo { get ; init ; }
422-
423- public SaveFile (
424- ulong rngSeed ,
425- ulong rngState ,
426- int lastRoomIdx ,
427- int [ ] noteIds ,
428- int [ ] relicIds ,
429- int [ ] battlePool ,
430- int [ ] eventPool ,
431- int playerHealth ,
432- int area ,
433- int money ,
434- int shortcuts ,
435- int playerMaxCombo
436- )
437- {
438- RngSeed = rngSeed ;
439- RngState = rngState ;
440- LastRoomIdx = lastRoomIdx ;
441- NoteIds = noteIds ;
442- RelicIds = relicIds ;
443- BattlePool = battlePool ?? [ ] ;
444- EventPool = eventPool ?? [ ] ;
445- PlayerHealth = playerHealth ;
446- Area = area ;
447- Money = money ;
448- Shortcuts = shortcuts ;
449- PlayerMaxCombo = playerMaxCombo ;
450- }
451- }
452-
453- public static void SaveGame ( )
454- {
455- int [ ] relicIds = StageProducer . PlayerStats . CurRelics . Select ( r => r . Id ) . ToArray ( ) ;
456- int [ ] noteIds = StageProducer . PlayerStats . CurNotes . Select ( r => r . Id ) . ToArray ( ) ;
457- SaveFile sv = new SaveFile (
458- StageProducer . GlobalRng . Seed ,
459- StageProducer . GlobalRng . State ,
460- StageProducer . CurRoom ,
461- noteIds ,
462- relicIds ,
463- StageProducer . BattlePool ? . ToArray ( ) ,
464- EventScene . EventPool ? . ToArray ( ) ,
465- StageProducer . PlayerStats . CurrentHealth ,
466- StageProducer . CurLevel . Id ,
467- StageProducer . PlayerStats . Money ,
468- StageProducer . PlayerStats . Shortcuts ,
469- StageProducer . PlayerStats . MaxComboBar
470- ) ;
471- string json = JsonSerializer . Serialize ( sv ) ;
472-
473- FileAccess file = FileAccess . Open ( UserSavePath , FileAccess . ModeFlags . Write ) ;
474-
475- file . StoreLine ( json ) ;
476- file . Close ( ) ;
477- }
478-
479- /**
480- * <remarks>Returns null if invalid save or save 404's.</remarks>
481- */
482- public static SaveFile LoadGame ( )
483- {
484- if ( ! FileAccess . FileExists ( UserSavePath ) )
485- return null ;
486- FileAccess file = FileAccess . Open ( UserSavePath , FileAccess . ModeFlags . Read ) ;
487- string json = file . GetAsText ( ) ;
488-
489- file . Close ( ) ;
490- SaveFile sv ;
491- try
492- {
493- sv = JsonSerializer . Deserialize < SaveFile > ( json ) ;
494- }
495- catch ( JsonException )
496- {
497- GD . PushWarning ( "Cannot deserialize save file, returning null." ) ;
498- return null ;
499- }
500- return sv ;
501- }
502-
503- public static void ClearSave ( )
504- {
505- DirAccess . RemoveAbsolute ( UserSavePath ) ;
506- }
507- #endregion
508386}
0 commit comments