コード例 #1
0
        public Dictionary <MusicPack, List <Song> > getLocationSpecificMusic()
        {
            Dictionary <MusicPack, List <Song> > listOfValidDictionaries = new Dictionary <MusicPack, List <Song> >();

            //StardewSymphony.ModMonitor.Log(SongSpecifics.getCurrentConditionalString(true));

            foreach (var v in this.musicPacks)
            {
                try
                {
                    var songList = v.Value.songInformation.getSongList(SongSpecifics.getCurrentConditionalString(true)).Value;
                    if (songList == null)
                    {
                        return(null);
                    }
                    if (songList.Count > 0)
                    {
                        listOfValidDictionaries.Add(v.Value, songList);
                    }
                }
                catch (Exception err)
                {
                    err.ToString();
                }
            }
            return(listOfValidDictionaries);
        }
コード例 #2
0
 /// <summary>Choose a new song when a delay runs out.</summary>
 private void OnTimerFinished(object source, ElapsedEventArgs e)
 {
     this.Timer.Enabled = false;
     if (!this.CurrentMusicPack.IsPlaying())
     {
         this.selectMusic(SongSpecifics.getCurrentConditionalString());
     }
 }
コード例 #3
0
        /// <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;
        }
コード例 #4
0
 public void onTimerFinished(System.Object source, ElapsedEventArgs e)
 {
     timer.Enabled = false;
     selectMusic(SongSpecifics.getCurrentConditionalString());
 }
コード例 #5
0
        /// <summary>Select the actual song to be played right now based on the selector key. The selector key should be called when the player's location changes.</summary>
        public void selectMusic(string songListKey, bool warpCheck = false)
        {
            StardewSymphony.DebugLog(SongSpecifics.GetKeySpecificity(songListKey).ToString());
            StardewSymphony.DebugLog(songListKey);
            //Prevent generic song changes when running about.
            if (SongSpecifics.GetKeySpecificity(songListKey) == SongSpecifics.SongKeyType.None)
            {
                return;
            }

            if (SongSpecifics.IsKeyGeneric(songListKey))
            {
                if (this.CurrentMusicPack != null)
                {
                    if (this.CurrentMusicPack.IsPlaying())
                    {
                        return;
                    }
                }
            }



            //If I have warped and the key only is to be played when time changes prevent a new song from playing.
            //If the key is more specific (I.E has a location associated with it) then music will change.
            if (warpCheck == true && SongSpecifics.IsKeyTimeSpecific(songListKey))
            {
                if (this.CurrentMusicPack != null)
                {
                    if (this.CurrentMusicPack.IsPlaying())
                    {
                        return;
                    }
                }
            }

            // stop timer timer when music is selected
            this.Timer.Enabled = false;

            // get applicable music packs
            var    listOfValidMusicPacks = this.GetApplicableMusicPacks(songListKey);
            string subKey = songListKey;

            //This chunk is to determine song specifics for location.
            while (listOfValidMusicPacks.Count == 0)
            {
                if (subKey.Length == 0)
                {
                    break;
                }

                string[] subList = subKey.Split(SongSpecifics.seperator);
                if (subList.Length == 0)
                {
                    break; //Because things would go bad otherwise.
                }
                subKey = "";
                for (int i = 0; i < subList.Length - 1; i++)
                {
                    subKey += subList[i];
                    if (i != subList.Length - 2)
                    {
                        subKey += SongSpecifics.seperator;
                    }
                }
                if (subKey == "")
                {
                    break;
                }

                if (StardewSymphony.Config.EnableDebugLog)
                {
                    StardewSymphony.ModMonitor.Log(subKey, StardewModdingAPI.LogLevel.Alert);
                }
                listOfValidMusicPacks = this.GetApplicableMusicPacks(subKey);
                if (listOfValidMusicPacks.Count == 0)
                {
                    //No valid songs to play at this time.
                    if (StardewSymphony.Config.EnableDebugLog)
                    {
                        StardewSymphony.ModMonitor.Log("Error: There are no songs to play across any music pack for the song key: " + subKey + ". 1 Are you sure you did this properly?");
                    }
                    //return;
                }
            }

            if (listOfValidMusicPacks.Count == 0)
            {
                //This chunk is used to determine more general seasonal specifics if song specifics couldn't be found.
                subKey = songListKey;
                string[] season = subKey.Split(SongSpecifics.seperator);
                subKey = "";
                for (int i = 1; i < season.Length; i++)
                {
                    subKey += season[i];
                    if (i != season.Length - 1)
                    {
                        subKey += SongSpecifics.seperator;
                    }
                }
                if (string.IsNullOrEmpty(subKey))
                {
                    if (!this.checkGenericMusic(songListKey))
                    {
                        if (StardewSymphony.Config.EnableDebugLog)
                        {
                            StardewSymphony.ModMonitor.Log("Error: There are no songs to play across any music pack for the song key: " + songListKey + ".2 Are you sure you did this properly?");
                        }
                        StardewSymphony.menuChangedMusic = false;
                        return;
                    }
                }
                if (StardewSymphony.Config.EnableDebugLog)
                {
                    StardewSymphony.ModMonitor.Log(subKey, StardewModdingAPI.LogLevel.Alert);
                }
                listOfValidMusicPacks = this.GetApplicableMusicPacks(subKey);
                if (listOfValidMusicPacks.Count == 0)
                {
                    //No valid songs to play at this time.
                    if (StardewSymphony.Config.EnableDebugLog)
                    {
                        StardewSymphony.ModMonitor.Log("Error: There are no songs to play across any music pack for the song key: " + subKey + ".3 Are you sure you did this properly?");
                    }
                    //return;
                }
                //Try to get more specific.


                //????? What does this part even do anymore???
                while (listOfValidMusicPacks.Count == 0)
                {
                    if (subKey.Length == 0)
                    {
                        break;
                    }
                    string[] subList = subKey.Split(SongSpecifics.seperator);
                    if (subList.Length == 0)
                    {
                        break;                      //Because things would go bad otherwise.
                    }
                    subKey = "";
                    for (int i = 0; i < subList.Length - 1; i++)
                    {
                        subKey += subList[i];
                        if (i != subList.Length - 2)
                        {
                            subKey += SongSpecifics.seperator;
                        }
                    }
                    if (subKey == "")
                    {
                        break;
                    }

                    if (StardewSymphony.Config.EnableDebugLog)
                    {
                        StardewSymphony.ModMonitor.Log(subKey, StardewModdingAPI.LogLevel.Alert);
                    }
                    listOfValidMusicPacks = this.GetApplicableMusicPacks(subKey);
                    if (listOfValidMusicPacks.Count == 0)
                    {
                        //No valid songs to play at this time.
                        if (StardewSymphony.Config.EnableDebugLog)
                        {
                            StardewSymphony.ModMonitor.Log("Error: There are no songs to play across any music pack for the song key: " + subKey + ".4 Are you sure you did this properly?");
                        }
                        //return;
                    }
                }
            }

            //If the list of valid packs are 0, check if I'm currently at an event or festival or get some location specific music and try to play a generalized song from there.
            if (listOfValidMusicPacks.Count == 0)
            {
                if (!this.checkGenericMusic(songListKey))
                {
                    //No valid songs to play at this time.
                    if (StardewSymphony.Config.EnableDebugLog)
                    {
                        StardewSymphony.ModMonitor.Log("Error: There are no songs to play across any music pack for the song key: " + songListKey + ".7 Are you sure you did this properly?");
                    }
                    StardewSymphony.menuChangedMusic = false;
                    return;
                }
            }

            string[] sizeList = subKey.Split(SongSpecifics.seperator);

            if (this.CurrentMusicPack != null)
            {
                //If I am trying to play a generic song and a generic song is playing don't change the music.
                //If I am trying to play a generic song and a non-generic song is playing, then play my generic song since I don't want to play the specific music anymore.
                if (sizeList.Length < 3 && (this.CurrentMusicPack.IsPlaying() && !this.lastSongWasLocationSpecific))
                {
                    if (StardewSymphony.Config.EnableDebugLog)
                    {
                        StardewSymphony.ModMonitor.Log("Non specific music change detected. Not going to change the music this time");
                    }
                    return;
                }
            }

            this.lastSongWasLocationSpecific = sizeList.Length >= 3;

            //If there is a valid key for the place/time/event/festival I am at, play it!

            int randInt = this.Random.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.Name);
            string songName = musicPackPair.Value.ElementAt(this.Random.Next(0, musicPackPair.Value.Count));

            this.CurrentMusicPack.PlaySong(songName);
        }