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

Replace indexed skill access with skills.OfType<...>().Single() #30034

Merged
merged 8 commits into from
Jan 20, 2025

Conversation

stanriders
Copy link
Member

Something that shouldve been done long ago

Copy link
Collaborator

@bdach bdach left a comment

Choose a reason for hiding this comment

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

Since this is a code quality diffcalc change rather than just a diffcalc change, I'll bite.

I guess this is an improvement but I'm not sure this goes far enough? As in, if we're going to such lengths, then why not a custom thin wrapper data structure, e.g. your basic container?

public class SkillContainer
{
    private Dictionary<Type, object> skills;

    public Set<T>(T skill) => skills[typeof(T)] = skill;
    public Get<T>(T skill) => (T)skills[typeof(T)]!;
}

or something.

Heck, if it didn't fill incredibly gross to reuse it in this context, that's what DependencyContainer is.

@@ -40,7 +41,7 @@ protected override DifficultyAttributes CreateDifficultyAttributes(IBeatmap beat

CatchDifficultyAttributes attributes = new CatchDifficultyAttributes
{
StarRating = Math.Sqrt(skills[0].DifficultyValue()) * difficulty_multiplier,
StarRating = Math.Sqrt(skills.First(s => s is Movement).DifficultyValue()) * difficulty_multiplier,
Copy link
Collaborator

Choose a reason for hiding this comment

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

These should really say .Single().

/// <summary>
/// Represents the Aim skill that does not include sliders length in it's calculation
/// </summary>
public class AimWithoutSliders : Aim
Copy link
Collaborator

Choose a reason for hiding this comment

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

And this is... kinda weird? Why bother?

Why not expose WithSliders as public readonly on the skill, and then find it where you need it based on that flag alone? As in

skills.OfType<Aim>().SingleOrDefault(aim => aim.WithSliders)

or something.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's mostly for the tools, to be able to distinguish between two aim skills

Copy link
Contributor

Choose a reason for hiding this comment

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

Is that to say they can't distinguish by based on a property for some reason?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right now to display the skill name it just takes the type name. I could add an exception for aim, but I feel like it's an ugly way cos for example if someone works on aim revamping they'll need to remove it, or if someone add another multipass skill it'll need another exception and so on, and that'd need to happen not only in tools but in diffcalc itself. Creating a separate class seems like a more elegant solution to me

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. In general I'd expect that to be handled by a Name property or similar, but I suppose this is fine for now.

@stanriders
Copy link
Member Author

I guess this is an improvement but I'm not sure this goes far enough? As in, if we're going to such lengths, then why not a custom thin wrapper data structure, e.g. your basic container?

I'm not sure if that's really necessery honestly, since all this tries to achieve is save someone from inevitabely shooting themselves in a foot by messing up indices

@Givikap120
Copy link
Contributor

I guess this is an improvement but I'm not sure this goes far enough? As in, if we're going to such lengths, then why not a custom thin wrapper data structure, e.g. your basic container?

I'm not sure if that's really necessery honestly, since all this tries to achieve is save someone from inevitabely shooting themselves in a foot by messing up indices

this change is very good when you have something like Flashlight and Hidden at the same time
because in this case using indices is very painful

@smoogipoo

This comment was marked as off-topic.

@smoogipoo
Copy link
Contributor

Ignore the above suggestion - I'll be working on it as a separate solo effort.

@smoogipoo
Copy link
Contributor

!difficulty
RULESET=osu

@smoogipoo
Copy link
Contributor

!difficulty
RULESET=taiko

@smoogipoo
Copy link
Contributor

!difficulty
RULESET=catch

@smoogipoo
Copy link
Contributor

!difficulty
RULESET=mania

@smoogipoo smoogipoo requested a review from bdach December 13, 2024 08:48
smoogipoo
smoogipoo previously approved these changes Dec 13, 2024
@smoogipoo smoogipoo changed the base branch from master to pp-dev December 18, 2024 14:09
@smoogipoo smoogipoo dismissed their stale review December 18, 2024 14:09

The base branch was changed.

@bdach
Copy link
Collaborator

bdach commented Dec 19, 2024

@stanriders please double check merge conflict resolution in 9818f90

!difficulty
RULESET=taiko

bdach
bdach previously approved these changes Dec 19, 2024
@bdach
Copy link
Collaborator

bdach commented Dec 23, 2024

I can't with the merge conflicts here........

@stanriders
Copy link
Member Author

I can't with the merge conflicts here........

I'm planning to resolve and merge it after we're done actively finishing up and merging reworks, to not interfere with that

@stanriders stanriders changed the title Replace indexed skill access with skills.First(s is ...) Replace indexed skill access with skills.OfType<...>().Single() Jan 2, 2025
tsunyoku
tsunyoku previously approved these changes Jan 20, 2025
@tsunyoku tsunyoku enabled auto-merge (squash) January 20, 2025 09:33
@tsunyoku tsunyoku merged commit 22e839d into ppy:pp-dev Jan 20, 2025
6 of 8 checks passed
@stanriders stanriders deleted the fix-indexed-skills branch January 20, 2025 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Pending Deploy
Development

Successfully merging this pull request may close these issues.

5 participants