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

Merged
merged 17 commits into from
Jul 1, 2024

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
@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 😖

Copy link
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

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

super cool. i am wondering if it is a bit confusing to have both a sorting expression and effect? and if we do keep both, does it make sense for ExprFilter to get an effect equivalent?

src/test/skript/tests/syntaxes/effects/EffSort.sk Outdated Show resolved Hide resolved
}

@Override
public boolean isSingle() {
Copy link
Member

Choose a reason for hiding this comment

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

should be before return type

src/main/java/ch/njol/skript/effects/EffSort.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/expressions/ExprFilter.java Outdated Show resolved Hide resolved
@sovdeeth sovdeeth added the feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. label Jul 1, 2024
@sovdeeth sovdeeth merged commit 6065891 into SkriptLang:dev/feature Jul 1, 2024
5 checks passed
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. feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants