private async void btnAnalyzeMap_Click(object sender, EventArgs e) { if (txtMapID.Text.Length == 0) { CustomMessageBox.Show(this, "You forgot the key!", new Size(customMessageBoxWidthSize, 100)); return; } LoadingScreenHelper.SwitchToLoadingScreen(this, "Downloading map..."); if (!testJsonMode) { if (Directory.Exists("analyzedMap")) { Directory.Delete("analyzedMap", true); } Directory.CreateDirectory("analyzedMap"); try { await MapInstaller.InstallMap(mapData, "analyzedMap"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return; } } MapAnalyzer.AnalyzeMap(this, cmbCharacteristics, cmbDifficulty, testJsonMode); LoadingScreenHelper.HideLoadingScreen(this); }
private async void btnInstallMap_Click(object sender, EventArgs e) { if (!CanDownloadMap(txtMapID.Text, txtBeatsaverFolder.Text)) { CustomMessageBox.Show(this, "You have already downloaded this map!", new Size(customMessageBoxWidthSize, 100)); return; } else { LoadingScreenHelper.SwitchToLoadingScreen(this, "Installing map..."); } await MapInstaller.InstallMap(mapData, txtBeatsaverFolder.Text); LoadingScreenHelper.HideLoadingScreen(this); }
private async void btnRandomKey_Click(object sender, EventArgs e) { txtMapID.Text = ""; lblDifficulties.Text = ""; LoadingScreenHelper.SwitchToLoadingScreen(this, "Searching for a map..."); mapData = await RandomKeyGenerator.GenerateRandomMap(this, randomKeyFilter); if (mapData == null) { CustomMessageBox.Show(this, "Could not find a valid key. Try again!", new Size(customMessageBoxWidthSize, 100)); mapData = null; txtMapID.Text = ""; } else { UpdateMapDataText(); LoadingScreenHelper.HideLoadingScreen(this); } }
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); }