-
-
Notifications
You must be signed in to change notification settings - Fork 356
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
base: dev/feature
Are you sure you want to change the base?
Conversation
This reverts commit 20169a1.
and tests!
@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!"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
couldnt we do the sorting async? |
pikachu please you're killing me |
@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 😖 |
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