diff --git a/PerformanceCalculatorGUI/Screens/SimulateScreen.cs b/PerformanceCalculatorGUI/Screens/SimulateScreen.cs index 735049deb5..a014857570 100644 --- a/PerformanceCalculatorGUI/Screens/SimulateScreen.cs +++ b/PerformanceCalculatorGUI/Screens/SimulateScreen.cs @@ -61,7 +61,7 @@ public partial class SimulateScreen : PerformanceCalculatorScreen private LimitedLabelledNumberBox comboTextBox; private LimitedLabelledNumberBox scoreTextBox; - private LabelledNumberBox scoreIdTextBox; + private LabelledTextBox scoreIdTextBox; private StatefulButton scoreIdPopulateButton; private GridContainer accuracyContainer; @@ -226,12 +226,12 @@ private void load(OsuColour osuColour) Direction = FillDirection.Horizontal, Children = new Drawable[] { - scoreIdTextBox = new LabelledNumberBox + scoreIdTextBox = new LabelledTextBox { RelativeSizeAxes = Axes.X, Width = 0.7f, Label = "Score ID", - PlaceholderText = "0", + PlaceholderText = "0 or osu/0", }, scoreIdPopulateButton = new StatefulButton("Populate from score") { @@ -239,9 +239,9 @@ private void load(OsuColour osuColour) Width = 0.3f, Action = () => { - if (!string.IsNullOrEmpty(scoreIdTextBox.Current.Value)) + if (validateScoreId(scoreIdTextBox.Current.Value)) { - populateSettingsFromScore(long.Parse(scoreIdTextBox.Current.Value)); + populateSettingsFromScore(scoreIdTextBox.Current.Value); } else { @@ -991,7 +991,7 @@ private void showError(string message, bool log = true) private long? legacyTotalScore; - private void populateSettingsFromScore(long scoreId) + private void populateSettingsFromScore(string scoreId) { if (scoreIdPopulateButton.State.Value == ButtonState.Loading) return; @@ -1118,5 +1118,31 @@ private void updateMissesTextboxes() fixupTextBox(missesTextBox); } } + + private static bool validateScoreId(string scoreId) + { + string[] validRulesetNames = { "osu", "taiko", "fruits", "mania" }; + + if (string.IsNullOrWhiteSpace(scoreId)) + return false; + + // Check if it's just a numeric id from lazer leaderboard + if (long.TryParse(scoreId, out _)) + return true; + + // Check if it's valid legacy database score id + string[] parts = scoreId.Split('/'); + + if (parts.Length == 2) + { + string rulesetPart = parts[0]; + string idPart = parts[1]; + + if (validRulesetNames.Contains(rulesetPart) && long.TryParse(idPart, out _)) + return true; + } + + return false; + } } }