Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for beatmap link parsing #242

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

felipemarins
Copy link

Currently, if you paste a beatmap link into the beatmap ID text box, it just deletes all non-number characters and ends up leaving the beatmapset ID mixed up with the beatmap ID. In this pr, I turned it into an ExtendedLabelledTextBox with a regex filter on the SimulateScreen and BeatmapLeaderboardScreen classes to check for beatmap links and extracting the correct ID from them.

@stanriders stanriders self-requested a review January 4, 2025 17:59
@stanriders stanriders added the perfcalc-gui PerformanceCalculatorGUI label Jan 15, 2025
PerformanceCalculatorGUI/Screens/SimulateScreen.cs Outdated Show resolved Hide resolved
PerformanceCalculatorGUI/Screens/SimulateScreen.cs Outdated Show resolved Hide resolved
// Checks if the beatmap string contains only numbers or if it's a file path
if (!Regex.IsMatch(beatmap, @"\A\d+\z|\.osu\z"))
{
string beatmapLinkPattern = @"osu\.ppy\.sh/b.*/\d+\z";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem robust enough, I can name at least 4 ways of easily breaking it:

  1. Trailing slash
  2. osu.ppy.sh/b/ links
  3. osu.ppy.sh/beatmaps/ links
  4. Inconsistent casing

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the point 1, although I don't see a case where it happens if you did copy and paste the beatmap link from the browser URL bar or from in-game.
I don't understand the point 2 and 3, as from my tests, osu.ppy.sh/b/ and osu.ppy.sh/beatmaps/ links work on my current implementation.
You're right about point 4, I didn't consider casing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I misread the regex, 2 and 3 are indeed supported my bad. Would still prefer a more robust check though, because a completely incorrect link like osu.ppy.sh/boop/123 might match

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I made the regex only match osu.ppy.sh/beatmapsets/b/beatmaps links, would it be enough?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, assuming we're talking just about the matching here. Other regex-related comments still apply

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's only about the beatmap link match. I'll fix the other issues too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

private void calculate()
private void checkBeatmapIdAndCalculate()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for self: this (and a lot of other things) needs to be separated into components

Copy link
Member

@stanriders stanriders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a check that when the input isn't a file or a link it is a valid beatmap id (int.TryParse would be sufficient)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perfcalc-gui PerformanceCalculatorGUI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants