Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions PerformanceCalculatorGUI/Screens/SimulateScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -226,22 +226,22 @@ 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")
{
RelativeSizeAxes = Axes.X,
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
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Loading