Work on SymponyRemasteered Music manager to be almost working, and fixed glitch with Happy Birthday when reading legacy save data.

This commit is contained in:
2018-01-30 12:46:04 -08:00
parent 5b894e32e8
commit b72de658a6
7 changed files with 172 additions and 47 deletions

View File

@ -100,6 +100,7 @@ namespace Omegasis.HappyBirthday
// load settings
this.MigrateLegacyData();
this.PlayerData = this.Helper.ReadJsonFile<PlayerData>(this.DataFilePath) ?? new PlayerData();
//this.SeenEvent = false;
//this.Dialogue = new Dictionary<string, Dialogue>();
}
@ -501,9 +502,14 @@ namespace Omegasis.HappyBirthday
private void MigrateLegacyData()
{
// skip if no legacy data or new data already exists
try
{
if (!File.Exists(this.LegacyDataFilePath) || File.Exists(this.DataFilePath))
if (this.PlayerData == null) this.PlayerData = new PlayerData();
return;
}
catch(Exception err)
{
// migrate to new file
try
{
@ -524,5 +530,7 @@ namespace Omegasis.HappyBirthday
this.Monitor.Log($"Error migrating data from the legacy 'Player_Birthdays' folder for the current player. Technical details:\n {ex}", LogLevel.Error);
}
}
}
}
}

View File

@ -4,7 +4,7 @@
"Version": {
"MajorVersion": 1,
"MinorVersion": 4,
"PatchVersion": 1,
"PatchVersion": 2,
"Build": null
},
"MinimumApiVersion": "1.15",

View File

@ -4,6 +4,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StardewSymphonyRemastered;
using StardewValley;
namespace StardewSymphonyRemastered.Framework
{
/// <summary>
@ -22,7 +24,8 @@ namespace StardewSymphonyRemastered.Framework
public MusicPack currentMusicPack;
Random packSelector;
Random songSelector;
/// <summary>
/// Constructor.
/// </summary>
@ -30,6 +33,8 @@ namespace StardewSymphonyRemastered.Framework
{
this.musicPacks = new Dictionary<string, MusicPack>();
this.currentMusicPack = null;
packSelector = new Random(Game1.random.Next(1,1000000));
songSelector = new Random(Game1.player.deepestMineLevel + Game1.player.facingDirection + packSelector.Next(0,10000));
}
/// <summary>
@ -108,6 +113,10 @@ namespace StardewSymphonyRemastered.Framework
}
}
/// <summary>
/// Get the information associated with the current music pack.
/// </summary>
/// <returns></returns>
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.
}
}
/// <summary>
/// Iterates across all music packs and determines which music packs contain songs that can be played right now.
/// </summary>
/// <param name="songListKey"></param>
/// <returns></returns>
public Dictionary<MusicPack,List<string>> getListOfApplicableMusicPacks(string songListKey)
{
Dictionary<MusicPack, List<string>> listOfValidDictionaries = new Dictionary<MusicPack, List<string>>();
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;
}
/// <summary>
/// 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.
/// </summary>
/// <param name="songListKey"></param>
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);
}
/// <summary>
/// TODO: Make WAV MUSIC PACKS
/// </summary>
/// <param name="wavMusicPack"></param>
public void addMusicPack(WavMusicPack wavMusicPack)
{
}
/// <summary>
/// Adds a valid xwb music pack to the list of music packs available.
/// </summary>
/// <param name="xwbMusicPack"></param>
public void addMusicPack(XwbMusicPack xwbMusicPack)
{
this.musicPacks.Add(xwbMusicPack.musicPackInformation.name,xwbMusicPack);
}
}
}

View File

@ -32,18 +32,27 @@ namespace StardewSymphonyRemastered.Framework
this.versionInfo = VersionInfo;
}
/// <summary>
/// Blank Const
/// Blank Constructor
/// </summary>
public MusicPackMetaData()
{
}
/// <summary>
/// Loads the music pack information from a json file.
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static MusicPackMetaData readFromJson(string path)
{
return StardewSymphony.ModHelper.ReadJsonFile<MusicPackMetaData>(path);
}
/// <summary>
/// Writes the music pack information to a json file.
/// </summary>
/// <param name="path"></param>
public void writeToJson(string path)
{
StardewSymphony.ModHelper.WriteJsonFile<MusicPackMetaData>(path,this);

View File

@ -30,7 +30,7 @@ namespace StardewSymphonyRemastered.Framework
string[] weather;
string[] daysOfWeek;
string[] timesOfDay;
char seperator = '_';
public static char seperator = '_';
/// <summary>
/// Constructor.
@ -87,6 +87,34 @@ namespace StardewSymphonyRemastered.Framework
// Static Methods //
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
#region
/// <summary>
/// TODO: Add functionality for events and festivals
/// Sum up some conditionals to parse the correct string key to access the songs list.
/// </summary>
/// <returns></returns>
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;
}
/// <summary>
/// Initialize the location lists with the names of all of the major locations in the game.
/// </summary>
@ -294,30 +322,6 @@ namespace StardewSymphonyRemastered.Framework
}
}
/// <summary>
/// TODO: Add functionality for events and festivals
/// Sum up some conditionals to parse the correct string key to access the songs list.
/// </summary>
/// <returns></returns>
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;
}
/// <summary>
/// Used to access the master list of songs this music pack contains.
@ -330,26 +334,34 @@ namespace StardewSymphonyRemastered.Framework
if (keyPhrase == "event")
{
/*
foreach (KeyValuePair<string, List<string>> pair in eventSongs)
{
if (pair.Key == key) return pair;
}
*/
return new KeyValuePair<string, List<string>>(key, eventSongs[key]);
}
else if (keyPhrase == "festival")
{
/*
foreach (KeyValuePair<string, List<string>> pair in festivalSongs)
{
if (pair.Key == key) return pair;
}
*/
return new KeyValuePair<string, List<string>>(key, festivalSongs[key]);
}
else
{
/*
foreach(KeyValuePair<string,List<string>> pair in listOfSongsWithTriggers)
{
if (pair.Key == key) return pair;
}
*/
return new KeyValuePair<string, List<string>>(key, listOfSongsWithTriggers[key]);
}
return new KeyValuePair<string, List<string>>();
}
/// <summary>

View File

@ -9,7 +9,7 @@ namespace StardewSymphonyRemastered.Framework
/// <summary>
/// TODO: Make this class
/// </summary>
class WavMusicPack : MusicPack
public class WavMusicPack : MusicPack
{
}
}

View File

@ -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.
}
/// <summary>
/// Raised when the player changes locations. This should determine the next song to play.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LocationEvents_CurrentLocationChanged(object sender, StardewModdingAPI.Events.EventArgsCurrentLocationChanged e)
{
musicManager.selectMusic(SongSpecifics.getCurrentConditionalString());
}
/// <summary>
@ -53,6 +71,10 @@ namespace StardewSymphonyRemastered
StardewSymphonyRemastered.Framework.SongSpecifics.addLocations();
StardewSymphonyRemastered.Framework.SongSpecifics.addFestivals();
StardewSymphonyRemastered.Framework.SongSpecifics.addEvents();
}