Added in ability to save and load music packs. Needs lots of work. Next step, menus.

This commit is contained in:
2018-02-05 19:07:29 -08:00
parent 45bfa5731f
commit ff6456d9ec
6 changed files with 99 additions and 8 deletions

View File

@ -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);
}
}
}
}
}

View File

@ -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<Song> songList;
public SongListNode()
{
}
public SongListNode(string Trigger, List<Song> 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<SongListNode>(path);
}
}
}

View File

@ -14,11 +14,11 @@ namespace StardewSymphonyRemastered.Framework
/// </summary>
public class SongSpecifics
{
Dictionary<string, List<Song>> listOfSongsWithTriggers; //triggerName, <songs>
public Dictionary<string, List<Song>> listOfSongsWithTriggers; //triggerName, <songs>
Dictionary<string, List<Song>> eventSongs;
public Dictionary<string, List<Song>> eventSongs;
Dictionary<string, List<Song>> festivalSongs;
public Dictionary<string, List<Song>> festivalSongs;
public List<Song> listOfSongsWithoutTriggers;
@ -72,7 +72,8 @@ namespace StardewSymphonyRemastered.Framework
"night"
};
menus = new List<string>();
menus.Add(typeof(StardewValley.Menus.TitleMenu).ToString());
menus.Add(typeof(StardewValley.Menus.TitleMenu).ToString().Replace('.', seperator));
listOfSongsWithTriggers = new Dictionary<string, List<Song>>();
@ -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;
}

View File

@ -233,8 +233,5 @@ namespace StardewSymphonyRemastered.Framework
}
return "";
}
}
}

View File

@ -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();
}
}

View File

@ -45,6 +45,7 @@
<Compile Include="Framework\Menus\MusicManagerMenu.cs" />
<Compile Include="Framework\MusicPackMetaData.cs" />
<Compile Include="Framework\Song.cs" />
<Compile Include="Framework\SongListNode.cs" />
<Compile Include="StaticExtentions.cs" />
<Compile Include="StardewSymphony.cs" />
<Compile Include="Framework\MusicHexProcessor.cs" />