diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/MusicPack.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/MusicPack.cs index 4bbad6d1..b4f954da 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/MusicPack.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/MusicPack.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -57,5 +58,43 @@ namespace StardewSymphonyRemastered.Framework { } + + + public virtual void writeToJson() + { + StardewSymphony.ModMonitor.Log("Loading in music for this pack:"+this.musicPackInformation.name+". Please wait."); + string data = Path.Combine(this.directory, "data"); + if (!Directory.Exists(data)) + { + Directory.CreateDirectory(data); + } + foreach (var list in this.songInformation.listOfSongsWithTriggers) + { + if (list.Value.Count == 0) continue; + SongListNode node = new SongListNode(list.Key, list.Value); + node.WriteToJson(Path.Combine(data, node.trigger+".json")); + } + } + + public virtual void readFromJson() + { + StardewSymphony.ModMonitor.Log("Saving music for this pack:" + this.musicPackInformation.name + ". Please wait as this will take quite soem time."); + string data = Path.Combine(this.directory, "data"); + if (!Directory.Exists(data)) + { + Directory.CreateDirectory(data); + } + string[] files = Directory.GetFiles(data); + foreach (var file in files) + { + SongListNode node = SongListNode.ReadFromJson(Path.Combine(data,file)); + var pair = this.songInformation.getSongList(node.trigger+".json"); + foreach (var v in node.songList) + { + this.songInformation.addSongToList(node.trigger, v.name); + } + } + + } } } diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/SongListNode.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/SongListNode.cs new file mode 100644 index 00000000..524ee58f --- /dev/null +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/SongListNode.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewSymphonyRemastered.Framework +{ + class SongListNode + { + public string trigger; + public List songList; + + public SongListNode() + { + + } + + public SongListNode(string Trigger, List SongList) + { + this.trigger = Trigger; + this.songList = SongList; + } + + public void WriteToJson(string path) + { + StardewSymphony.ModHelper.WriteJsonFile(path, this); + } + + public static SongListNode ReadFromJson(string path) + { + return StardewSymphony.ModHelper.ReadJsonFile(path); + } + + } +} diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/SongSpecifics.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/SongSpecifics.cs index 253c8e17..689cc377 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/SongSpecifics.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/SongSpecifics.cs @@ -14,11 +14,11 @@ namespace StardewSymphonyRemastered.Framework /// public class SongSpecifics { - Dictionary> listOfSongsWithTriggers; //triggerName, + public Dictionary> listOfSongsWithTriggers; //triggerName, - Dictionary> eventSongs; + public Dictionary> eventSongs; - Dictionary> festivalSongs; + public Dictionary> festivalSongs; public List listOfSongsWithoutTriggers; @@ -72,7 +72,8 @@ namespace StardewSymphonyRemastered.Framework "night" }; menus = new List(); - menus.Add(typeof(StardewValley.Menus.TitleMenu).ToString()); + + menus.Add(typeof(StardewValley.Menus.TitleMenu).ToString().Replace('.', seperator)); listOfSongsWithTriggers = new Dictionary>(); @@ -113,7 +114,7 @@ namespace StardewSymphonyRemastered.Framework { if (Game1.activeClickableMenu.GetType() == typeof(StardewValley.Menus.TitleMenu)) { - key = Game1.activeClickableMenu.GetType().ToString(); + key = Game1.activeClickableMenu.GetType().ToString().Replace('.',seperator); foundMenuString = true; } diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/WavMusicPack.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/WavMusicPack.cs index 4c3d9bb3..1c3ee009 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/WavMusicPack.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/WavMusicPack.cs @@ -233,8 +233,5 @@ namespace StardewSymphonyRemastered.Framework } return ""; } - - - } } diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs index 02c31a83..5f080d7d 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs @@ -57,6 +57,7 @@ namespace StardewSymphonyRemastered StardewModdingAPI.Events.LocationEvents.CurrentLocationChanged += LocationEvents_CurrentLocationChanged; StardewModdingAPI.Events.GameEvents.UpdateTick += GameEvents_UpdateTick; StardewModdingAPI.Events.ControlEvents.KeyPressed += ControlEvents_KeyPressed; + StardewModdingAPI.Events.SaveEvents.BeforeSave += SaveEvents_BeforeSave; musicManager = new MusicManager(); MusicPath = Path.Combine(ModHelper.DirectoryPath, "Content", "Music"); @@ -71,6 +72,16 @@ namespace StardewSymphonyRemastered musicPacksInitialized = false; } + private void SaveEvents_BeforeSave(object sender, EventArgs e) + { + /* THIS IS WAY TO LONG to run. Better make it save individual lists when I am editing songs. + foreach(var musicPack in musicManager.musicPacks) + { + musicPack.Value.writeToJson(); + } + */ + } + private void ControlEvents_KeyPressed(object sender, StardewModdingAPI.Events.EventArgsKeyPressed e) { if (e.KeyPressed == Microsoft.Xna.Framework.Input.Keys.O) @@ -210,6 +221,9 @@ namespace StardewSymphonyRemastered } StardewSymphonyRemastered.Framework.XACTMusicPack musicPack = new XACTMusicPack(folder, waveBank,soundBank); musicManager.addMusicPack(musicPack,true,true); + + musicPack.readFromJson(); + } } @@ -230,6 +244,9 @@ namespace StardewSymphonyRemastered StardewSymphonyRemastered.Framework.WavMusicPack musicPack = new WavMusicPack(folder); musicManager.addMusicPack(musicPack,true,true); + + musicPack.readFromJson(); + } } diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphonyRemastered.csproj b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphonyRemastered.csproj index 0e523462..fd6de3f7 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphonyRemastered.csproj +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphonyRemastered.csproj @@ -45,6 +45,7 @@ +