using System; using System.Collections; using System.Collections.Generic; using Ichni.RhythmGame; using Ichni.Story; using Sirenix.OdinInspector; using UnityEngine; namespace Ichni { public class GameSaveManager : SerializedMonoBehaviour { public static GameSaveManager instance; public SongSaveModule SongSaveModule; public StorySaveModule StorySaveModule; private void Awake() { if (instance == null) { instance = this; SongSaveModule = new SongSaveModule(); SongSaveModule.LoadSongStatuses(); StorySaveModule = new StorySaveModule(); StorySaveModule.LoadStoryVariables(); StorySaveModule.LoadChoices(); DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } } } public partial class SongSaveModule { public Dictionary songStatusSaves; private string SongSavePath => Application.streamingAssetsPath + "/GameSaves/SongSaves.json"; public SongSaveModule() { songStatusSaves = new Dictionary(); Debug.Log("Song save path: " + SongSavePath); } } public partial class SongSaveModule { [Button] public void SaveSongStatuses() { ES3.Save("SongSaves", songStatusSaves, SongSavePath); } public void LoadSongStatuses() { if (ES3.FileExists(SongSavePath)) { songStatusSaves = ES3.Load>("SongSaves", SongSavePath); } else { songStatusSaves = new Dictionary(); //TODO: delete songStatusSaves.Add("Chaos Zone", new SongStatusSave { isCompleted = false, additionalInfo = "", beatmapSaves = new Dictionary() { { "Easy", new BeatmapSave { accuracy = 0.0f, isFullCombo = false, isAllPerfect = false } }, { "Hard", new BeatmapSave { accuracy = 0.0f, isFullCombo = false, isAllPerfect = false } }, { "Chaos", new BeatmapSave { accuracy = 0.0f, isFullCombo = false, isAllPerfect = false } } } }); } } [Button] public void ClearBeatmapRecords() { foreach (var songStatus in songStatusSaves.Values) { foreach (var beatmapSave in songStatus.beatmapSaves.Values) { beatmapSave.accuracy = 0.0f; beatmapSave.isFullCombo = false; beatmapSave.isAllPerfect = false; } } SaveSongStatuses(); } } public partial class StorySaveModule { public Dictionary> tutorialBlockSaves; public Dictionary> songBlockSaves; public Dictionary> dialogBlockSaves; public Dictionary> connectorSaves; public Dictionary storyVariables; public Dictionary selectedChoices; private string GetStorySavePath(string chapterName) => Application.streamingAssetsPath + "/StorySaves/" + chapterName + ".json"; private string StoryVariablesPath => Application.streamingAssetsPath + "/StorySaves/StoryVariables.json"; private string ChoicesPath => Application.streamingAssetsPath + "/StorySaves/Choices.json"; public StorySaveModule() { tutorialBlockSaves = new Dictionary>(); songBlockSaves = new Dictionary>(); dialogBlockSaves = new Dictionary>(); connectorSaves = new Dictionary>(); storyVariables = new Dictionary(); selectedChoices = new Dictionary(); Debug.Log("Story Variables path: " + StoryVariablesPath); } } public partial class StorySaveModule { public void LoadStoryline(string chapterName) { tutorialBlockSaves[chapterName] = ES3.Load>("TutorialBlockSaves", GetStorySavePath(chapterName)); songBlockSaves[chapterName] = ES3.Load>("SongBlockSaves", GetStorySavePath(chapterName)); dialogBlockSaves[chapterName] = ES3.Load>("TextBlockSaves", GetStorySavePath(chapterName)); connectorSaves[chapterName] = ES3.Load>("BlockConnectorSaves", GetStorySavePath(chapterName)); } public void SaveStoryline(string chapterName, List tutorialBlocks, List songBlocks, List dialogBlocks, List connectors) { ES3.Save("TutorialBlockSaves", tutorialBlocks, GetStorySavePath(chapterName)); ES3.Save("SongBlockSaves", songBlocks, GetStorySavePath(chapterName)); ES3.Save("TextBlockSaves", dialogBlocks, GetStorySavePath(chapterName)); ES3.Save("BlockConnectorSaves", connectors, GetStorySavePath(chapterName)); SaveStoryVariables(); SaveChoices(); } } public partial class StorySaveModule { public void SaveStoryVariables() { string path = Application.streamingAssetsPath + "/StorySaves/" + "StoryVariables.json"; ES3.Save("StoryVariables", storyVariables, path); } public void LoadStoryVariables() { string path = Application.streamingAssetsPath + "/StorySaves/" + "StoryVariables.json"; if (ES3.FileExists(path)) { storyVariables = ES3.Load>("StoryVariables", path); } else { storyVariables = new Dictionary(); } } public void SaveChoices() { string path = Application.streamingAssetsPath + "/StorySaves/" + "Choices.json"; ES3.Save("Choices", selectedChoices, path); } public void LoadChoices() { string path = Application.streamingAssetsPath + "/StorySaves/" + "Choices.json"; if (ES3.FileExists(path)) { selectedChoices = ES3.Load>("Choices", path); } else { selectedChoices = new Dictionary(); } } } }