using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Policy; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Newtonsoft.Json; using radio42.Multimedia.Midi; namespace TJAPlayer3 { internal class SaveFile { public void tSaveFile(string filename) { path = @"Saves/" + filename + @".json"; name = filename; if (!File.Exists(path)) { this.data.Name = filename; tSaveFile(); } tLoadFile(); } #region [Medals] public void tEarnCoins(int amount) { data.Medals += amount; tSaveFile(); } // Return false if the current amount of coins is to low public bool tSpendCoins(int amount) { if (data.Medals < amount) return false; data.Medals -= amount; tSaveFile(); return true; } #endregion #region [Dan titles] public bool tUpdateDanTitle(string title, bool isGold, int clearStatus) { bool changed = false; bool iG = isGold; int cs = clearStatus; if (this.data.DanTitles == null) this.data.DanTitles = new Dictionary(); if (this.data.DanTitles.ContainsKey(title)) { if (this.data.DanTitles[title].clearStatus > cs) cs = this.data.DanTitles[title].clearStatus; if (this.data.DanTitles[title].isGold) iG = true; } // Automatically set the dan to nameplate if new // Add a function within the NamePlate.cs file to update the title texture if (!this.data.DanTitles.ContainsKey(title) || cs != clearStatus || iG != isGold) { changed = true; /* TJAPlayer3.NamePlateConfig.data.Dan[player] = title; TJAPlayer3.NamePlateConfig.data.DanGold[player] = iG; TJAPlayer3.NamePlateConfig.data.DanType[player] = cs; */ } CDanTitle danTitle = new CDanTitle(iG, cs); this.data.DanTitles[title] = danTitle; tSaveFile(); return changed; } #endregion #region [Auxilliary classes] public class CDanTitle { public CDanTitle(bool iG, int cs) { isGold = iG; clearStatus = cs; } [JsonProperty("isGold")] public bool isGold; [JsonProperty("clearStatus")] public int clearStatus; } public class CNamePlateTitle { public CNamePlateTitle(int type) { iType = type; cld = new CLocalizationData(); } [JsonProperty("iType")] public int iType; [JsonProperty("Localization")] public CLocalizationData cld; } public class CPassStatus { public CPassStatus() { d = new int[5] { -1, -1, -1, -1, -1 }; } public int[] d; } #endregion #region [Heya] public void tReindexCharacter(string[] characterNamesList) { string character = this.data.CharacterName; if (characterNamesList.Contains(character)) this.data.Character = characterNamesList.ToList().IndexOf(character); } public void tUpdateCharacterName(string newChara) { this.data.CharacterName = newChara; } public void tApplyHeyaChanges() { this.tSaveFile(); } #endregion #region [Player stats] public void tUpdateSongClearStatus(C曲リストノード node, int clearStatus, int difficulty) { if (difficulty > (int)Difficulty.Edit) return; string _id = node.uniqueId.data.id; var _sdp = data.standardPasses; if (!_sdp.ContainsKey(_id)) _sdp[_id] = new CPassStatus(); var cps = _sdp[_id]; var _values = cps.d; if (clearStatus > _values[difficulty]) { cps.d[difficulty] = clearStatus; tSaveFile(); } } #endregion public class Data { [JsonProperty("name")] public string Name = "プレイヤー1"; [JsonProperty("title")] public string Title = "初心者"; [JsonProperty("dan")] public string Dan = "新人"; [JsonProperty("danGold")] public bool DanGold = false; [JsonProperty("danType")] public int DanType = 0; [JsonProperty("titleType")] public int TitleType = 0; [JsonProperty("puchiChara")] public string PuchiChara = "0"; [JsonProperty("medals")] public int Medals = 0; [JsonProperty("character")] public int Character = 0; [JsonProperty("characterName")] public string CharacterName = "0"; [JsonProperty("danTitles")] public Dictionary DanTitles = new Dictionary(); [JsonProperty("namePlateTitles")] public Dictionary NamePlateTitles = new Dictionary(); [JsonProperty("unlockedCharacters")] public List UnlockedCharacters = new List(); [JsonProperty("unlockedPuchicharas")] public List UnlockedPuchicharas = new List(); [JsonProperty("activeTriggers")] public HashSet ActiveTriggers = new HashSet(); [JsonProperty("standardPasses")] public Dictionary standardPasses = new Dictionary(); } public Data data = new Data(); public string path = "Save.json"; public string name = "Save"; #region [private] private void tSaveFile() { ConfigManager.SaveConfig(data, path); } private void tLoadFile() { data = ConfigManager.GetConfig(path); } #endregion } }