diff --git a/GeneralMods/HappyBirthday/HappyBirthday.cs b/GeneralMods/HappyBirthday/HappyBirthday.cs index cf928916..869e4829 100644 --- a/GeneralMods/HappyBirthday/HappyBirthday.cs +++ b/GeneralMods/HappyBirthday/HappyBirthday.cs @@ -100,6 +100,7 @@ namespace Omegasis.HappyBirthday // load settings this.MigrateLegacyData(); this.PlayerData = this.Helper.ReadJsonFile(this.DataFilePath) ?? new PlayerData(); + //this.SeenEvent = false; //this.Dialogue = new Dictionary(); } @@ -501,28 +502,35 @@ namespace Omegasis.HappyBirthday private void MigrateLegacyData() { // skip if no legacy data or new data already exists - if (!File.Exists(this.LegacyDataFilePath) || File.Exists(this.DataFilePath)) - return; - - // migrate to new file try { - string[] text = File.ReadAllLines(this.LegacyDataFilePath); - this.Helper.WriteJsonFile(this.DataFilePath, new PlayerData - { - BirthdaySeason = text[3], - BirthdayDay = Convert.ToInt32(text[5]) - }); - - FileInfo file = new FileInfo(this.LegacyDataFilePath); - file.Delete(); - if (!file.Directory.EnumerateFiles().Any()) - file.Directory.Delete(); + if (!File.Exists(this.LegacyDataFilePath) || File.Exists(this.DataFilePath)) + if (this.PlayerData == null) this.PlayerData = new PlayerData(); + return; } - catch (Exception ex) + catch(Exception err) { - this.Monitor.Log($"Error migrating data from the legacy 'Player_Birthdays' folder for the current player. Technical details:\n {ex}", LogLevel.Error); + // migrate to new file + try + { + string[] text = File.ReadAllLines(this.LegacyDataFilePath); + this.Helper.WriteJsonFile(this.DataFilePath, new PlayerData + { + BirthdaySeason = text[3], + BirthdayDay = Convert.ToInt32(text[5]) + }); + + FileInfo file = new FileInfo(this.LegacyDataFilePath); + file.Delete(); + if (!file.Directory.EnumerateFiles().Any()) + file.Directory.Delete(); + } + catch (Exception ex) + { + this.Monitor.Log($"Error migrating data from the legacy 'Player_Birthdays' folder for the current player. Technical details:\n {ex}", LogLevel.Error); + } } + } } } diff --git a/GeneralMods/HappyBirthday/manifest.json b/GeneralMods/HappyBirthday/manifest.json index 1a0d213b..9c5cd1ef 100644 --- a/GeneralMods/HappyBirthday/manifest.json +++ b/GeneralMods/HappyBirthday/manifest.json @@ -4,7 +4,7 @@ "Version": { "MajorVersion": 1, "MinorVersion": 4, - "PatchVersion": 1, + "PatchVersion": 2, "Build": null }, "MinimumApiVersion": "1.15", diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/MusicManager.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/MusicManager.cs index 2d02a99f..fece56bb 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/MusicManager.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/MusicManager.cs @@ -4,6 +4,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using StardewSymphonyRemastered; +using StardewValley; + namespace StardewSymphonyRemastered.Framework { /// @@ -22,7 +24,8 @@ namespace StardewSymphonyRemastered.Framework public MusicPack currentMusicPack; - + Random packSelector; + Random songSelector; /// /// Constructor. /// @@ -30,6 +33,8 @@ namespace StardewSymphonyRemastered.Framework { this.musicPacks = new Dictionary(); this.currentMusicPack = null; + packSelector = new Random(Game1.random.Next(1,1000000)); + songSelector = new Random(Game1.player.deepestMineLevel + Game1.player.facingDirection + packSelector.Next(0,10000)); } /// @@ -108,6 +113,10 @@ namespace StardewSymphonyRemastered.Framework } } + /// + /// Get the information associated with the current music pack. + /// + /// public MusicPackMetaData getMusicPackInformation() { if (this.currentMusicPack.isNull() == false) @@ -153,5 +162,70 @@ namespace StardewSymphonyRemastered.Framework return null; //Needed I suppose to ensure this function compiles. } } + + /// + /// Iterates across all music packs and determines which music packs contain songs that can be played right now. + /// + /// + /// + public Dictionary> getListOfApplicableMusicPacks(string songListKey) + { + Dictionary> listOfValidDictionaries = new Dictionary>(); + foreach(var v in this.musicPacks) + { + var songList= v.Value.songInformation.getSongList(songListKey).Value; + if (songList.Count > 0) + { + listOfValidDictionaries.Add(v.Value, songList); + } + } + return listOfValidDictionaries; + } + + /// + /// Selects the actual song to be played right now based off of the selector key. The selector key should be called when the player's location changes. + /// + /// + public void selectMusic(string songListKey) + { + var listOfValidMusicPacks = getListOfApplicableMusicPacks(songListKey); + if (listOfValidMusicPacks.Count == 0) + { + //No valid songs to play at this time. + StardewSymphony.ModMonitor.Log("Error: There are no songs to play across any music pack. Are you sure you did this properly?"); + return; + } + + int randInt = packSelector.Next(0, listOfValidMusicPacks.Count-1); + + var musicPackPair = listOfValidMusicPacks.ElementAt(randInt); + + //used to swap the music packs and stop the last playing song. + this.swapMusicPacks(musicPackPair.Key.musicPackInformation.name); + + int randInt2 = songSelector.Next(0, musicPackPair.Value.Count); + + var songName = musicPackPair.Value.ElementAt(randInt2); + + this.currentMusicPack.playSong(songName); + } + + /// + /// TODO: Make WAV MUSIC PACKS + /// + /// + public void addMusicPack(WavMusicPack wavMusicPack) + { + + } + + /// + /// Adds a valid xwb music pack to the list of music packs available. + /// + /// + public void addMusicPack(XwbMusicPack xwbMusicPack) + { + this.musicPacks.Add(xwbMusicPack.musicPackInformation.name,xwbMusicPack); + } } } diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/MusicPackMetaData.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/MusicPackMetaData.cs index 65be6fc1..bb0bb2b9 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/MusicPackMetaData.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/MusicPackMetaData.cs @@ -32,18 +32,27 @@ namespace StardewSymphonyRemastered.Framework this.versionInfo = VersionInfo; } /// - /// Blank Const + /// Blank Constructor /// public MusicPackMetaData() { } + /// + /// Loads the music pack information from a json file. + /// + /// + /// public static MusicPackMetaData readFromJson(string path) { return StardewSymphony.ModHelper.ReadJsonFile(path); } + /// + /// Writes the music pack information to a json file. + /// + /// public void writeToJson(string path) { StardewSymphony.ModHelper.WriteJsonFile(path,this); diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/SongSpecifics.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/SongSpecifics.cs index 0c7643bf..f4822747 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/SongSpecifics.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/SongSpecifics.cs @@ -30,7 +30,7 @@ namespace StardewSymphonyRemastered.Framework string[] weather; string[] daysOfWeek; string[] timesOfDay; - char seperator = '_'; + public static char seperator = '_'; /// /// Constructor. @@ -87,6 +87,34 @@ namespace StardewSymphonyRemastered.Framework // Static Methods // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// #region + + /// + /// TODO: Add functionality for events and festivals + /// Sum up some conditionals to parse the correct string key to access the songs list. + /// + /// + public static string getCurrentConditionalString() + { + string key = ""; + if (Game1.eventUp == true) + { + //Get the event id an hijack it with some different music + //String key="Event_EventName"; + } + else if (Game1.isFestival()) + { + //hijack the name of the festival and load some different songs + // string s="Festival_FestivalName"; + } + else + { + key = getLocationString() + seperator + getSeasonNameString() + seperator + getWeatherString() + seperator + getDayOfWeekString() + seperator + getTimeOfDayString(); + } + return key; + } + + + /// /// Initialize the location lists with the names of all of the major locations in the game. /// @@ -294,30 +322,6 @@ namespace StardewSymphonyRemastered.Framework } } - /// - /// TODO: Add functionality for events and festivals - /// Sum up some conditionals to parse the correct string key to access the songs list. - /// - /// - public string getCurrentConditionalString() - { - string key = ""; - if (Game1.eventUp == true) - { - //Get the event id an hijack it with some different music - //String key="Event_EventName"; - } - else if (Game1.isFestival()) - { - //hijack the name of the festival and load some different songs - // string s="Festival_FestivalName"; - } - else - { - key = getLocationString()+seperator+ getSeasonNameString() + seperator + getWeatherString() + seperator + getDayOfWeekString() + seperator + getTimeOfDayString(); - } - return key; - } /// /// Used to access the master list of songs this music pack contains. @@ -330,26 +334,34 @@ namespace StardewSymphonyRemastered.Framework if (keyPhrase == "event") { + /* foreach (KeyValuePair> pair in eventSongs) { if (pair.Key == key) return pair; } + */ + return new KeyValuePair>(key, eventSongs[key]); } else if (keyPhrase == "festival") { + /* foreach (KeyValuePair> pair in festivalSongs) { if (pair.Key == key) return pair; } + */ + return new KeyValuePair>(key, festivalSongs[key]); } else { + /* foreach(KeyValuePair> pair in listOfSongsWithTriggers) { if (pair.Key == key) return pair; } + */ + return new KeyValuePair>(key, listOfSongsWithTriggers[key]); } - return new KeyValuePair>(); } /// diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/WavMusicPack.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/WavMusicPack.cs index 271638a4..061e07bb 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/WavMusicPack.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/WavMusicPack.cs @@ -9,7 +9,7 @@ namespace StardewSymphonyRemastered.Framework /// /// TODO: Make this class /// - class WavMusicPack : MusicPack + public class WavMusicPack : MusicPack { } } diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs index ee118a4f..289888ac 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Microsoft.Xna.Framework.Audio; using StardewModdingAPI; using StardewValley; +using StardewSymphonyRemastered.Framework; namespace StardewSymphonyRemastered { @@ -15,6 +16,7 @@ namespace StardewSymphonyRemastered /// BIG WIP. Don't use this at all because it does nothing right now. /// TODO: /// 1.Make Xwb packs work + /// 1.5. Make way to load in music packs. /// 2.Make stream files work /// 2.5. Make Music Manager /// 3.Make interface. @@ -32,6 +34,8 @@ namespace StardewSymphonyRemastered public static IModHelper ModHelper; public static IMonitor ModMonitor; + public static MusicManager musicManager; + public override void Entry(IModHelper helper) { @@ -41,6 +45,20 @@ namespace StardewSymphonyRemastered ModMonitor = Monitor; StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad; + StardewModdingAPI.Events.LocationEvents.CurrentLocationChanged += LocationEvents_CurrentLocationChanged; + + musicManager = new MusicManager(); + //load in all packs here. + } + + /// + /// Raised when the player changes locations. This should determine the next song to play. + /// + /// + /// + private void LocationEvents_CurrentLocationChanged(object sender, StardewModdingAPI.Events.EventArgsCurrentLocationChanged e) + { + musicManager.selectMusic(SongSpecifics.getCurrentConditionalString()); } /// @@ -53,6 +71,10 @@ namespace StardewSymphonyRemastered StardewSymphonyRemastered.Framework.SongSpecifics.addLocations(); StardewSymphonyRemastered.Framework.SongSpecifics.addFestivals(); StardewSymphonyRemastered.Framework.SongSpecifics.addEvents(); + + + + }