Exemplo n.º 1
0
        private static void GetRandomSong()
        {
            songSelect = GameObject.FindObjectOfType <SongSelect>();
            songs      = songSelect.songSelectItems.mItems;
            int maxLength = songs.Count - 1;

            if (!availableSongListsSetup)
            {
                availableSongListsSetup = true;

                for (int i = 0; i < mainSongCount; i++)
                {
                    availableMainSongs.Add(i);
                }

                for (int i = mainSongCount; i < maxLength; i++)
                {
                    availableExtrasSongs.Add(i);
                }

                for (int i = 0; i < maxLength; i++)
                {
                    availableSongs.Add(i);
                }
            }
            SongSelect.Filter filter = songSelect.GetListFilter();

            var rand = new System.Random();
            int index;

            if (filter == SongSelect.Filter.All)
            {
                index = availableSongs[rand.Next(0, availableSongs.Count - 1)];
            }
            else if (filter == SongSelect.Filter.Main)
            {
                index = availableMainSongs[rand.Next(0, availableMainSongs.Count - 1)];
                if (availableMainSongs.Count > 0)
                {
                    availableMainSongs.Remove(index);
                }
            }
            else
            {
                index = availableExtrasSongs[rand.Next(0, availableExtrasSongs.Count - 1)];
                if (availableExtrasSongs.Count > 0)
                {
                    availableExtrasSongs.Remove(index);
                }
            }
            songs[index].OnSelect();
            lastPickedSongs.Add(index);
            if (availableSongs.Count > 0)
            {
                availableSongs.Remove(index);
            }


            if (lastPickedSongs.Count > randomSongBagSize)
            {
                int oldestIndex = lastPickedSongs[0];
                lastPickedSongs.Remove(oldestIndex);
                availableSongs.Add(oldestIndex);
                if (oldestIndex < 33)
                {
                    availableMainSongs.Add(index);
                }
                else
                {
                    availableExtrasSongs.Add(index);
                }
            }
        }
Exemplo n.º 2
0
        private static void OnRandomSongButtonShot()
        {
            songSelect = GameObject.FindObjectOfType <SongSelect>();
            songs      = songSelect.songSelectItems.mItems;
            int maxLength = songs.Count;

            if (!availableSongListsSetup)
            {
                availableSongListsSetup = true;

                for (int i = 0; i < mainSongCount; i++)
                {
                    availableMainSongs.Add(i);
                }

                for (int i = mainSongCount; i < maxLength; i++)
                {
                    availableExtrasSongs.Add(i);
                }

                for (int i = 0; i < maxLength; i++)
                {
                    availableSongs.Add(i);
                }

                foreach (string song in FilterPanel.favorites.songIDs)
                {
                    availableFavouritesSongs.Add(song);
                }
            }

            SongSelect.Filter filter = songSelect.GetListFilter();

            var rand = new System.Random();
            int index;

            if (FilterPanel.filteringFavorites && availableFavouritesSongs.Count > 0)
            {
                string id = availableFavouritesSongs[rand.Next(0, availableFavouritesSongs.Count)];
                for (int i = 0; i < songs.Count; i++)
                {
                    if (id == songs[i].mSongData.songID)
                    {
                        lastPickedFavouritesSongs.Add(id);
                        availableFavouritesSongs.Remove(id);
                        songs[i].OnSelect();
                        break;
                    }
                }

                if (availableFavouritesSongs.Count < 1)
                {
                    foreach (string s in lastPickedFavouritesSongs)
                    {
                        availableFavouritesSongs.Add(s);
                    }
                    lastPickedFavouritesSongs = new System.Collections.Generic.List <string>();
                }
                return;
            }
            else if (filter == SongSelect.Filter.All)
            {
                index = availableSongs[rand.Next(0, availableSongs.Count)];
            }
            else if (filter == SongSelect.Filter.Main)
            {
                index = availableMainSongs[rand.Next(0, availableMainSongs.Count)];
                if (availableMainSongs.Count > 0)
                {
                    availableMainSongs.Remove(index);
                }
            }
            else
            {
                if (availableExtrasSongs.Count < 1)
                {
                    foreach (int i in lastPickedSongs)
                    {
                        availableSongs.Add(i);
                        if (i < 33)
                        {
                            availableMainSongs.Add(i);
                        }
                        else
                        {
                            availableExtrasSongs.Add(i);
                        }
                    }
                    lastPickedSongs.Clear();
                }

                index = availableExtrasSongs[rand.Next(0, availableExtrasSongs.Count)];
                availableExtrasSongs.Remove(index);
            }

            songs[index].OnSelect();
            lastPickedSongs.Add(index);
            if (availableSongs.Count > 0)
            {
                availableSongs.Remove(index);
            }


            if (lastPickedSongs.Count > randomSongBagSize)
            {
                int oldestIndex = lastPickedSongs[0];
                lastPickedSongs.Remove(oldestIndex);
                availableSongs.Add(oldestIndex);
                if (oldestIndex < 33)
                {
                    availableMainSongs.Add(oldestIndex);                   //was index before but why did i do that?
                }
                else
                {
                    availableExtrasSongs.Add(oldestIndex);  //was index before but why did i do that?
                }
            }
        }