private void btnFilter_Click(object sender, EventArgs e)
 {
     if (randomKeyFilter == null)
     {
         randomKeyFilter          = new RandomKeyFilter();
         randomKeyFilter.Location = new Point(Size.Width / 2 - randomKeyFilter.Size.Width / 2, Size.Height / 2 - randomKeyFilter.Size.Height / 2);
         Controls.Add(randomKeyFilter);
         randomKeyFilter.BringToFront();
     }
     else
     {
         randomKeyFilter.Visible = true;
     }
 }
Beispiel #2
0
        public static async Task <Beatmap> GetMapData(Form1 form, RandomKeyFilter randomKeyFilter, string randomKey, bool showError = false)
        {
            try
            {
                Beatmap mapData = await Form1.beatsaverClient.Key(randomKey);

                if (mapData == null)
                {
                    throw new Exception();
                }
                bool isBeatSage = mapData.Metadata.Automapper != null;

                if (isBeatSage)
                {
                    CustomMessageBox.Show(form, "WARNING: This is an autogenerated map!", new Size(Form1.customMessageBoxWidthSize, 100));
                }

                #region NPS Filter
                BeatmapCharacteristicDifficulty highestDifficulty = mapData.Metadata.Characteristics[0].Difficulties.GetHighestDifficulty();
                if (randomKeyFilter != null && !randomKeyFilter.MatchingFilters(highestDifficulty, mapData))
                {
                    mapData = null;
                    return(null);
                }
                #endregion

                return(mapData);
            }
            catch (Exception ex)
            {
                if (showError)
                {
                    CustomMessageBox.Show(form, "There is no map with this key!", new Size(Form1.customMessageBoxWidthSize, 100));
                }
                return(null);
            }
        }
        public static async Task <Beatmap> GenerateRandomMap(Form1 form, RandomKeyFilter randomKeyFilter)
        {
            int tries    = 0;
            int maxTries = 10;

            if (randomKeyFilter != null && randomKeyFilter.UsingFilters)
            {
                maxTries = 50;
            }

            string randomKey = null;

            Beatmap mapData = null;

            var latestMaps = await Form1.beatsaverClient.Latest();

            string latestKey = latestMaps.Docs[0].Key;

            int keyAsDecimal = int.Parse(latestKey, System.Globalization.NumberStyles.HexNumber);

            if (randomKey == null)
            {
                if (randomKeyFilter != null && randomKeyFilter.Rating.HasValue)
                {
                    await FilterHelper.SetFilterPageNumbers(Form1.client, (int)(randomKeyFilter.Rating.Value * 100), "minRatingAPIPage");
                }

                while (true)
                {
                    if (randomKeyFilter != null && randomKeyFilter.Rating.HasValue)
                    {
                        await FilterHelper.SetRandomKey(Form1.client, Form1.rnd);

                        randomKey = FilterHelper.RandomKey;
                    }
                    else
                    {
                        int randomNumber = Form1.rnd.Next(0, keyAsDecimal + 1);
                        randomKey = randomNumber.ToString("x");
                    }

                    mapData = await MapDataHelper.GetMapData(form, randomKeyFilter, randomKey, false);

                    if (mapData != null)
                    {
                        break;
                    }

                    if (tries == maxTries)
                    {
                        break;
                    }

                    tries++;
                }
            }

            if (maxTries > 10)
            {
                LoadingScreenHelper.HideLoadingScreen(form);
            }

            if (tries == maxTries)
            {
                return(null);
            }

            return(mapData);
        }