Fixed Stardew Symphony Remastered from numerous menu and music glitches.

This commit is contained in:
2018-09-01 00:26:18 -07:00
parent 704a15ad4d
commit a6257c5d28
8 changed files with 160 additions and 170 deletions

View File

@ -1586,7 +1586,7 @@ namespace StardewSymphonyRemastered.Framework.Menus
if (this.currentMusicPackAlbum == null || this.currentSelectedSong == null) return false;
var info = (KeyValuePair<string, MusicPack>)this.currentMusicPackAlbum.buttonFunctionality.leftClick.paramaters[0];
//Check for generic festival music.
if (this.drawMode == DrawMode.FestivalSelection)
if (this.drawMode == DrawMode.SelectedFestival)
{
var festivalSonglist = info.Value.songInformation.festivalSongs;
if (festivalSonglist == null) return false;
@ -1594,9 +1594,9 @@ namespace StardewSymphonyRemastered.Framework.Menus
else return true;
}
//Check for generic event music.
if (this.drawMode == DrawMode.EventSelection)
if (this.drawMode == DrawMode.SelectedEvent)
{
var eventSonglist = info.Value.songInformation.festivalSongs;
var eventSonglist = info.Value.songInformation.eventSongs;
if (eventSonglist == null) return false;
if (!eventSonglist.Contains(info.Value.songInformation.getSongFromList(eventSonglist, this.currentSelectedSong.name))) return false;
else return true;
@ -1894,6 +1894,7 @@ namespace StardewSymphonyRemastered.Framework.Menus
this.currentMusicPackAlbum.draw(b);
this.currentSelectedSong.draw(b);
this.currentlySelectedOption.draw(b);
/*
if (!doesPackContainMusic())
{
this.addButton.draw(b);
@ -1902,6 +1903,7 @@ namespace StardewSymphonyRemastered.Framework.Menus
{
this.deleteButton.draw(b);
}
*/
this.playButton.draw(b);
this.stopButton.draw(b);
@ -1952,6 +1954,7 @@ namespace StardewSymphonyRemastered.Framework.Menus
this.currentMusicPackAlbum.draw(b);
this.currentSelectedSong.draw(b);
this.currentlySelectedOption.draw(b);
/*
if (!doesPackContainMusic())
{
this.addButton.draw(b);
@ -1960,6 +1963,7 @@ namespace StardewSymphonyRemastered.Framework.Menus
{
this.deleteButton.draw(b);
}
*/
this.playButton.draw(b);
this.stopButton.draw(b);
@ -2010,6 +2014,7 @@ namespace StardewSymphonyRemastered.Framework.Menus
this.currentMusicPackAlbum.draw(b);
this.currentSelectedSong.draw(b);
this.currentlySelectedOption.draw(b);
/*
if (!doesPackContainMusic())
{
this.addButton.draw(b);
@ -2018,6 +2023,7 @@ namespace StardewSymphonyRemastered.Framework.Menus
{
this.deleteButton.draw(b);
}
*/
this.playButton.draw(b);
this.stopButton.draw(b);
@ -2161,13 +2167,16 @@ namespace StardewSymphonyRemastered.Framework.Menus
{
if (this.drawMode == DrawMode.WeatherSelection || this.drawMode == DrawMode.TimeSelection || this.drawMode == DrawMode.LocationSelection || this.drawMode == DrawMode.DaySelection || this.drawMode == DrawMode.NothingElseToDisplay)
{
if (!doesPackContainMusic())
if (this.selectedJustLocation==false)
{
this.addButton.draw(b);
}
else
{
this.deleteButton.draw(b);
if (!doesPackContainMusic())
{
this.addButton.draw(b);
}
else
{
this.deleteButton.draw(b);
}
}
}
this.playButton.draw(b);
@ -2248,19 +2257,18 @@ namespace StardewSymphonyRemastered.Framework.Menus
var info = (KeyValuePair<string, MusicPack>)this.currentMusicPackAlbum.buttonFunctionality.leftClick.paramaters[0];
StardewSymphony.ModMonitor.Log(generateSongTriggerKeyFromSelection());
//StardewSymphony.ModMonitor.Log(generateSongTriggerKeyFromSelection());
//Add generic festival music.
if (this.drawMode == DrawMode.FestivalSelection)
if (this.drawMode == DrawMode.SelectedFestival)
{
info.Value.songInformation.addSongToFestivalList(this.currentlySelectedFestival.label);
info.Value.songInformation.addSongToFestivalList(this.currentSelectedSong.label);
return;
}
//Add generic event music.
if(this.drawMode== DrawMode.EventSelection)
if(this.drawMode== DrawMode.SelectedEvent)
{
info.Value.songInformation.addSongToEventList(this.currentlySelectedEvent.label);
info.Value.songInformation.addSongToEventList(this.currentSelectedSong.label);
return;
}
@ -2274,7 +2282,25 @@ namespace StardewSymphonyRemastered.Framework.Menus
/// </summary>
public void deleteSong()
{
var info = (KeyValuePair<string, MusicPack>)this.currentMusicPackAlbum.buttonFunctionality.leftClick.paramaters[0];
if (this.drawMode == DrawMode.SelectedFestival)
{
info.Value.songInformation.removeSongFromFestivalList(this.currentSelectedSong.label);
return;
}
//Add generic event music.
if (this.drawMode == DrawMode.SelectedEvent)
{
info.Value.songInformation.removeSongFromEventList(this.currentSelectedSong.label);
return;
}
info.Value.songInformation.removeSongFromTriggerList(generateSongTriggerKeyFromSelection(), this.currentSelectedSong.label);
}
@ -2318,13 +2344,13 @@ namespace StardewSymphonyRemastered.Framework.Menus
else if (this.currentlySelectedOption.name == "WinterButton") key += "winter";
else
{
StardewSymphony.ModMonitor.Log("Error: You are not in a valid menu area to set the song information. Please make sure that a valid season is selected for the song options", StardewModdingAPI.LogLevel.Alert);
//StardewSymphony.ModMonitor.Log("Error: You are not in a valid menu area to set the song information. Please make sure that a valid season is selected for the song options", StardewModdingAPI.LogLevel.Alert);
return "";
}
}
else
{
StardewSymphony.ModMonitor.Log("Error: You are not in a valid menu area to set the song information. Please make sure that a valid season is selected for the song options", StardewModdingAPI.LogLevel.Alert);
//StardewSymphony.ModMonitor.Log("Error: You are not in a valid menu area to set the song information. Please make sure that a valid season is selected for the song options", StardewModdingAPI.LogLevel.Alert);
return "";
}
}

View File

@ -65,26 +65,55 @@ namespace StardewSymphonyRemastered.Framework
}
}
/// <summary>
/// Updtes the timer every second to check if a song is playing or not.
/// </summary>
public void updateTimer()
{
if (this.currentMusicPack == null) return;
if (this.currentMusicPack.isPlaying()) return;
if (this.currentMusicPack.isPlaying())
{
return;
}
else
{
Random r = new Random(Game1.random.Next());
int val = r.Next(StardewSymphony.Config.MinimumDelayBetweenSongsInMilliseconds, StardewSymphony.Config.MaximumDelayBetweenSongsInMilliseconds + 1);
timer = new Timer(val);
timer.Elapsed += onTimerFinished;
timer.Enabled = true;
if (timer == null)
{
Random r = new Random(Game1.random.Next());
int val = r.Next(StardewSymphony.Config.MinimumDelayBetweenSongsInMilliseconds, StardewSymphony.Config.MaximumDelayBetweenSongsInMilliseconds + 1);
//StardewSymphony.ModMonitor.Log("Music Pack is not playing! Generate a new timer! Delay: "+val.ToString());
timer = new Timer(val);
timer.Elapsed += onTimerFinished;
timer.Enabled = true;
}
else
{
timer.Enabled = true;
timer.Elapsed += onTimerFinished;
}
}
}
/// <summary>
/// Selects a new song when the timer delay runs out.
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
public void onTimerFinished(System.Object source, ElapsedEventArgs e)
{
if (this.currentMusicPack.isPlaying())
{
timer.Enabled = false;
timer = null;
return;
}
//StardewSymphony.ModMonitor.Log("AHH THE TIMER FINISHED!");
timer.Enabled = false;
timer.Elapsed -= onTimerFinished;
selectMusic(SongSpecifics.getCurrentConditionalString());
timer = null;
}
/// <summary>
@ -269,6 +298,11 @@ namespace StardewSymphonyRemastered.Framework
/// <param name="songListKey"></param>
public void selectMusic(string songListKey)
{
//Nullify the timer when new music is selected.
if (this.timer != null)
{
this.timer = null;
}
var listOfValidMusicPacks = getListOfApplicableMusicPacks(songListKey);

View File

@ -63,16 +63,19 @@ namespace StardewSymphonyRemastered.Framework
{
string json = Path.Combine(path, "MusicPackInformation.json");
var meta=StardewSymphony.ModHelper.ReadJsonFile<MusicPackMetaData>(json);
string[] pathParse = path.Split(new String[] { StardewSymphony.ModHelper.DirectoryPath },StringSplitOptions.None);
try
{
try
{
meta.Icon = new Texture2DExtended(StardewSymphony.ModHelper,StardewSymphony.Manifest, StardewSymphony.getRelativeDirectory(Path.Combine(path, meta.pathToMusicPackIcon + ".png")));
meta.Icon = new Texture2DExtended(StardewSymphony.ModHelper,StardewSymphony.Manifest, Path.Combine(pathParse[1], meta.pathToMusicPackIcon + ".png"));
}
catch(Exception errr)
{
errr.ToString();
meta.Icon = new Texture2DExtended(StardewSymphony.ModHelper,StardewSymphony.Manifest ,StardewSymphony.getRelativeDirectory(Path.Combine(path, meta.pathToMusicPackIcon)));
meta.Icon = new Texture2DExtended(StardewSymphony.ModHelper,StardewSymphony.Manifest ,Path.Combine(pathParse[1], meta.pathToMusicPackIcon));
}
}
catch(Exception err)

View File

@ -625,7 +625,6 @@ namespace StardewSymphonyRemastered.Framework
public void addSongToFestivalList(string songName)
{
var songKeyPair = this.festivalSongs;
var song = getSongFromList(listOfSongsWithoutTriggers, songName); //Get the song from the master song pool
if (song == null)
@ -634,7 +633,7 @@ namespace StardewSymphonyRemastered.Framework
StardewSymphony.ModMonitor.Log("For some reason you are trying to add a song that is null. The name of the song is " + songName);
return;
}
songKeyPair.Add(song); //add the song from master pool to the trigger list
this.festivalSongs.Add(song); //add the song from master pool to the trigger list
}
public void addSongToEventList(string songName)
@ -664,6 +663,28 @@ namespace StardewSymphonyRemastered.Framework
songKeyPair.Value.Remove(song);
}
/// <summary>
/// Remove a song from the event list.
/// </summary>
/// <param name="songListKey"></param>
/// <param name="songName"></param>
public void removeSongFromEventList( string songName)
{
var song = getSongFromList(this.eventSongs, songName);
this.eventSongs.Remove(song);
}
/// <summary>
/// Remove a song from the festival list.
/// </summary>
/// <param name="songListKey"></param>
/// <param name="songName"></param>
public void removeSongFromFestivalList( string songName)
{
var song = getSongFromList(this.festivalSongs, songName);
this.festivalSongs.Remove(song);
}
/// <summary>
/// Get the Song instance that is referenced with the song's name.
/// </summary>
@ -672,8 +693,10 @@ namespace StardewSymphonyRemastered.Framework
/// <returns></returns>
public Song getSongFromList(List<Song> songList,string songName)
{
//StardewSymphony.ModMonitor.Log("Get the song: " + songName);
foreach (var song in songList)
{
//StardewSymphony.ModMonitor.Log("Looking at song: " + song.name);
if (song.name == songName)
{
return song;

View File

@ -18,26 +18,12 @@ namespace StardewSymphonyRemastered.Framework
public Song currentSong;
public string songsDirectory;
/// <summary>
/// Used to actually play the song.
/// </summary>
DynamicSoundEffectInstance dynamicSound;
/// <summary>
/// Used to keep track of where in the song we are.
/// </summary>
int position;
/// <summary>
/// ???
/// </summary>
int count;
/// <summary>
/// Used to store the info for the song.
/// </summary>
byte[] byteArray;
public SoundEffectInstance sound;
bool loop;
public Dictionary<string,SoundEffectInstance> sounds;
/// <summary>
/// Constructor.
/// </summary>
@ -50,6 +36,7 @@ namespace StardewSymphonyRemastered.Framework
this.songInformation = new SongSpecifics();
this.musicPackInformation = MusicPackMetaData.readFromJson(directoryToMusicPack);
this.loop = Loop;
this.sounds = new Dictionary<string, SoundEffectInstance>();
/*
if (this.musicPackInformation == null)
{
@ -80,83 +67,21 @@ namespace StardewSymphonyRemastered.Framework
}
}
/*
/// <summary>
/// Load a wav file into the stream to be played.
/// </summary>
public void LoadWavFromFileToStream(string p)
public void LoadWavFromFileToStream(string file)
{
// Create a new SpriteBatch, which can be used to draw textures.
string file =p;
System.IO.Stream waveFileStream = File.OpenRead(file); //TitleContainer.OpenStream(file);
BinaryReader reader = new BinaryReader(waveFileStream);
int chunkID = reader.ReadInt32();
int fileSize = reader.ReadInt32();
int riffType = reader.ReadInt32();
int fmtID = reader.ReadInt32();
int fmtSize = reader.ReadInt32();
int fmtCode = reader.ReadInt16();
int channels = reader.ReadInt16();
int sampleRate = reader.ReadInt32();
int fmtAvgBPS = reader.ReadInt32();
int fmtBlockAlign = reader.ReadInt16();
int bitDepth = reader.ReadInt16();
if (fmtSize == 18)
{
// Read any extra values
int fmtExtraSize = reader.ReadInt16();
reader.ReadBytes(fmtExtraSize);
}
int dataID = reader.ReadInt32();
int dataSize = reader.ReadInt32();
byteArray = reader.ReadBytes(dataSize);
dynamicSound = new DynamicSoundEffectInstance(sampleRate, (AudioChannels)channels);
count = dynamicSound.GetSampleSizeInBytes(TimeSpan.FromMilliseconds(10000));
if (count > byteArray.Length)
{
count = byteArray.Length;
}
dynamicSound.BufferNeeded += new EventHandler<EventArgs>(DynamicSound_BufferNeeded);
this.currentSong = new Song(p);
this.effect = SoundEffect.FromStream(waveFileStream);
this.sound=this.effect.CreateInstance();
this.currentSong = new Song(file);
waveFileStream.Dispose();
}
void DynamicSound_BufferNeeded(object sender, EventArgs e)
{
//StardewSymphony.ModMonitor.Log(byteArray.Length.ToString());
//StardewSymphony.ModMonitor.Log(position.ToString());
//StardewSymphony.ModMonitor.Log(count.ToString());
try
{
dynamicSound.SubmitBuffer(byteArray, position, count);
}
catch(Exception err)
{
}
//dynamicSound.SubmitBuffer(byteArray);
//dynamicSound.SubmitBuffer(byteArray, position + count / 2, count / 2);
position += count;
if (position + count > byteArray.Length)
{
if (loop)
{
position = 0;
}
else
{
}
}
}
*/
/// <summary>
/// Returns the name of the currently playing song.
@ -177,10 +102,18 @@ namespace StardewSymphonyRemastered.Framework
List<Song> listOfSongs = new List<Song>();
foreach(var wav in wavFiles)
{
System.IO.Stream waveFileStream = File.OpenRead(wav); //TitleContainer.OpenStream(file);
SoundEffect eff = SoundEffect.FromStream(waveFileStream);
SoundEffectInstance instance = eff.CreateInstance();
string name = Path.GetFileNameWithoutExtension(wav);
this.sounds.Add(name, instance);
waveFileStream.Dispose();
Song song = new Song(wav);
listOfSongs.Add(song);
this.songInformation.listOfSongsWithoutTriggers.Add(song);
//listOfSongs.Add(song);
}
this.songInformation.listOfSongsWithoutTriggers = listOfSongs;
}
/// <summary>
@ -188,7 +121,7 @@ namespace StardewSymphonyRemastered.Framework
/// </summary>
public override void pauseSong()
{
if (dynamicSound != null) dynamicSound.Pause();
if (this.sound != null) sound.Pause();
}
/// <summary>
@ -198,8 +131,19 @@ namespace StardewSymphonyRemastered.Framework
public override void playSong(string name)
{
string pathToSong = getSongPathFromName(name);
LoadWavFromFileToStream(pathToSong);
dynamicSound.Play();
bool exists=this.sounds.TryGetValue(name,out this.sound);
if (exists)
{
this.currentSong = new Song(name);
sound.Play();
}
else
{
StardewSymphony.ModMonitor.Log("An error occured where we can't find the song anymore. Weird. Please contact Omegasis with a SMAPI Log and describe when/how the event occured.");
}
}
public override void playRandomSong()
@ -215,8 +159,8 @@ namespace StardewSymphonyRemastered.Framework
/// </summary>
public override void resumeSong()
{
if (dynamicSound == null) return;
dynamicSound.Resume();
if (sound == null) return;
sound.Resume();
}
/// <summary>
@ -226,15 +170,10 @@ namespace StardewSymphonyRemastered.Framework
{
if (Game1.currentSong != null) Game1.currentSong.Stop(AudioStopOptions.Immediate);
if (this.currentSong == null) return;
if (dynamicSound != null)
if (sound != null)
{
dynamicSound.Stop(true);
dynamicSound.BufferNeeded -= new EventHandler<EventArgs>(DynamicSound_BufferNeeded);
dynamicSound = null;
sound.Stop(true);
this.currentSong = null;
position = 0;
count = 0;
byteArray = new byte[0];
}
}
@ -252,7 +191,7 @@ namespace StardewSymphonyRemastered.Framework
/// Get the son's name from the path.
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
/// <returns></returns>11111111111111
public string getSongNameFromPath(string path)
{
foreach(var song in this.songInformation.listOfSongsWithoutTriggers)
@ -278,8 +217,8 @@ namespace StardewSymphonyRemastered.Framework
public override bool isPlaying()
{
if (this.dynamicSound == null) return false;
if (this.dynamicSound.State == SoundState.Playing) return true;
if (this.sound == null) return false;
if (this.sound.State == SoundState.Playing) return true;
else return false;
}
}

View File

@ -508,36 +508,6 @@ namespace StardewSymphonyRemastered
Game1.soundBank = DefaultSoundBank;
}
/// <summary>
/// Used to splice the mod directory to get relative paths.
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static string getShortenedDirectory(string path)
{
string lol = (string)path.Clone();
string[] spliter = lol.Split(new string[] { ModHelper.DirectoryPath }, StringSplitOptions.None);
try
{
return spliter[1];
}
catch (Exception err)
{
err.ToString();
return spliter[0];
}
}
/// <summary>
/// Used to finish cleaning up absolute asset paths into a shortened relative path.
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static string getRelativeDirectory(string path)
{
string s = getShortenedDirectory(path);
return s.Remove(0, 1);
}
public static void DebugLog(string s)
{

View File

@ -1,7 +1,7 @@
{
"Name": "Stardew Symphony Remastered",
"Author": "Alpha_Omegasis",
"Version": "2.1.5",
"Version": "2.1.6",
"Description": "Adding more music to the game one beep at a time. Now with streaming!",
"UniqueID": "Omegasis.StardewSymphonyRemastered",
"EntryDll": "StardewSymphonyRemastered.dll",

View File

@ -23,12 +23,7 @@ namespace StardustCore.NetCode.Graphics
}
public NetString currentAnimationName;
public NetInt currentAnimationListIndex;
public NetTexture2DExtended objectTexture;
public NetAnimation defaultDrawFrame;
public NetBool enabled;
public NetString animationDataString;
protected override void ReadDelta(BinaryReader reader, NetVersion version)
{
@ -64,13 +59,13 @@ namespace StardustCore.NetCode.Graphics
}
else
{
Value.currentAnimation = defaultDrawFrame.Value;
Value.currentAnimation = defaultAnimation.Value;
}
}
protected override void WriteDelta(BinaryWriter writer)
{
NetString curentAnimationName = new NetString(Value.currentAnimationName);
NetString currentAnimationName = new NetString(Value.currentAnimationName);
currentAnimationName.Write(writer);