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 EffSort, rework ExprInput to use ParserData #6737

Open
wants to merge 13 commits into
base: dev/feature
Choose a base branch
from

Conversation

sovdeeth
Copy link
Member

@sovdeeth sovdeeth commented May 28, 2024

Description

This PR supersedes @Pikachu920's #6342 PR to be more generic and extendable. Syntaxes can now implement InputSource to declare themselves as valid sources of input for ExprInput.

This also adds input index as a pattern for ExprInput, which will allow the accessing of a value's index when filtering/sorting a variable list.

Also added is EffSort, an effect for sorting variable lists. This effect allows a custom expression to map the values before sorting, so lists can now be sorted in a somewhat custom manner. The sorting is still done with the natural ordering of the mapped values, so this does not current support custom comparators.
If the custom expression has returns a null value at any point, the sort will be aborted and the list will remain the same, as null values cannot be compared. Alternatively, we could just strip out the invalid values, but I think that's a destructive failure state that could result in users losing valuable data if they make a small mistake.


Target Minecraft Versions: any
Requirements: none
Related Issues: #6715 #4327

@sovdeeth sovdeeth added enhancement Feature request, an issue about something that could be improved, or a PR improving something. feature Pull request adding a new feature. 2.9 Targeting a 2.9.X version release labels May 28, 2024
@Override
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
if (expressions[0].isSingle() || !(expressions[0] instanceof Variable)) {
Skript.error("You can only sort list variables!");
Copy link
Member

Choose a reason for hiding this comment

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

If something accepts the set changer (for the values its returning) do you think it would be safe to allow it here too? I'm 50/50 on this because I know some things don't have analogous setting and getting.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it'd be ok to do that, but I'd like some other opinions too

Copy link
Member

Choose a reason for hiding this comment

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

My only worry is stuff that returns things of a different format than what it should be set to. I guess we could just hope that if something accepts changes for set with the same class as it returns then it'll be okay.

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 seems like a bit of a nightmare to properly check the acceptChange classes against the returned class with all the convertedexpression stuff EffChange does, so I'd rather not do this unless I have to.

Copy link
Member

Choose a reason for hiding this comment

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

wdym about the convertedexpression stuff?

Copy link
Member Author

Choose a reason for hiding this comment

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

See EffChange's init method

src/main/java/ch/njol/skript/lang/InputSource.java Outdated Show resolved Hide resolved
@Pikachu920
Copy link
Member

couldnt we do the sorting async?

@sovdeeth
Copy link
Member Author

sovdeeth commented Jun 1, 2024

couldnt we do the sorting async?

pikachu please you're killing me
and yes I think so

@sovdeeth
Copy link
Member Author

sovdeeth commented Jun 3, 2024

couldnt we do the sorting async?

@Pikachu920 we can do the actual sorting asynchronously, but we cannot ensure the expression is safe to evaluate asynchronously, so this would be of limited assistance. Do you think it's still worth adding?

@Pikachu920
Copy link
Member

couldnt we do the sorting async?

@Pikachu920 we can do the actual sorting asynchronously, but we cannot ensure the expression is safe to evaluate asynchronously, so this would be of limited assistance. Do you think it's still worth adding?

yes please. I am imagining people will use this for things like "top" listings which might have a lot of elements to sort. I think you have pointed out a larger issue though. anything that uses asynceffect at the moment is probably calling getters async 😖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.9 Targeting a 2.9.X version release enhancement Feature request, an issue about something that could be improved, or a PR improving something. feature Pull request adding a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants