-
-
Notifications
You must be signed in to change notification settings - Fork 373
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
Rework number parser and angle support #7139
Open
Efnilite
wants to merge
39
commits into
SkriptLang:dev/feature
Choose a base branch
from
Efnilite:angle
base: dev/feature
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
1001e4f
init commit
Efnilite f461b24
oops
Efnilite b3849ce
Merge branch 'dev/feature' into angle
Efnilite 9998616
removed unnecessary checks
Efnilite efbb1af
Merge remote-tracking branch 'origin/angle' into angle
Efnilite 52d028a
update other syntaxes
Efnilite b4a1f37
move to parser
Efnilite cef8b87
oops
Efnilite c5d5c25
big work
Efnilite b378a30
forgot !
Efnilite 036adf3
fix doubleValue call
Efnilite 491c7cf
fix parenthesis
Efnilite fcd2c60
add expression
Efnilite 46b507e
update tests
Efnilite 8d552b9
requested changes
Efnilite 27d0c78
oops
Efnilite 6ee87f1
remove unnecessary converter application
Efnilite 79ce823
remove converter
Efnilite 87b9e84
le fix
Efnilite a0212de
Merge branch 'dev/feature' into angle
Efnilite 18bf9c7
fix merge w/ display entities
Efnilite ad27be8
most "regular" regex
Efnilite cfd09ce
Merge branch 'dev/feature' into angle
sovdeeth 38543ca
fix tests
Efnilite 983e376
fix _ support
Efnilite a6b27bc
fix rotate
Efnilite e392b57
Merge branch 'dev/feature' into angle
Efnilite 8d0e8c5
Merge branch 'dev/feature' into angle
Efnilite 686ddc3
minor changes
Efnilite b5168cc
remove double return
Efnilite 6707d0d
fix ExprRotate
Efnilite f9afddb
Merge branch 'dev/feature' into angle
Efnilite e4cd70b
Merge branch 'dev/feature' into angle
Efnilite d8daf93
Merge branch 'dev/feature' into angle
sovdeeth 656e4ad
Merge branch 'dev/feature' into angle
Efnilite a9402b5
Merge branch 'dev/feature' into angle
Efnilite dacf629
oopsie
Efnilite ae2765a
Merge branch 'dev/feature' into angle
Moderocky 28742ef
Merge branch 'dev/feature' into angle
Efnilite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1,055 changes: 588 additions & 467 deletions
1,055
src/main/java/ch/njol/skript/classes/data/JavaClasses.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package ch.njol.skript.expressions; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.Since; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.ExpressionType; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.skript.lang.util.SimpleExpression; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@Name("Angle") | ||
@Description({ | ||
"Represents the passed number value in degrees.", | ||
"If radians is specified, converts the passed value to degrees. This conversion may not be entirely accurate, " + | ||
"due to floating point precision.", | ||
}) | ||
@Examples({ | ||
"set {_angle} to 90 degrees", | ||
"{_angle} is 90 # true", | ||
"180 degrees is pi # true", | ||
"pi radians is 180 degrees # true" | ||
}) | ||
@Since("INSERT VERSION") | ||
public class ExprAngle extends SimpleExpression<Number> { | ||
|
||
static { | ||
Skript.registerExpression(ExprAngle.class, Number.class, ExpressionType.SIMPLE, | ||
"%number% [in] deg[ree][s]", | ||
"%number% [in] rad[ian][s]", | ||
"%numbers% in deg[ree][s]", | ||
"%numbers% in rad[ian][s]"); | ||
} | ||
|
||
private Expression<Number> angle; | ||
private boolean isRadians; | ||
|
||
@Override | ||
public boolean init(Expression<?>[] expressions, int matchedPattern, | ||
Kleenean isDelayed, ParseResult parseResult) { | ||
//noinspection unchecked | ||
angle = (Expression<Number>) expressions[0]; | ||
isRadians = matchedPattern % 2 != 0; | ||
return true; | ||
} | ||
|
||
@Override | ||
protected Number @Nullable [] get(Event event) { | ||
Number[] numbers = angle.getArray(event); | ||
|
||
if (isRadians) | ||
for (int i = 0; i < numbers.length; i++) | ||
numbers[i] = Math.toDegrees(numbers[i].doubleValue()); | ||
|
||
return numbers; | ||
} | ||
|
||
@Override | ||
public boolean isSingle() { | ||
return angle.isSingle(); | ||
} | ||
|
||
@Override | ||
public Class<? extends Number> getReturnType() { | ||
return Number.class; | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return angle.toString(event, debug) + " in " + (isRadians ? "degrees" : "radians"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
test "angle": | ||
Efnilite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert 90 degrees is 90 with "90 degrees is not 90" | ||
assert -10.5 degrees is -10.5 with "-10.5 degrees is not -10.5" | ||
assert 354698306983560 degrees is 354698306983560 with "354698306983560 degrees is not 354698306983560" | ||
|
||
assert pi radians is 180.0 degrees with "pi radians is not 180 degrees" | ||
assert 2 * pi in radians is 360.0 degrees with "2pi radians is not 360 degrees" | ||
|
||
assert 180.0 degrees is pi radians with "180 degrees is not pi radians" | ||
assert 360.0 in degrees is 2 * pi radians with "360 degrees is not 2pi radians" | ||
|
||
assert infinity value degrees is infinity value with "infinity degrees is not infinity" | ||
assert -infinity value degrees is -infinity value with "-infinity degrees is not -infinity" | ||
assert infinity value radians is infinity value with "infinity radians is not infinity" | ||
assert -infinity value radians is -infinity value with "-infinity radians is not -infinity" | ||
|
||
assert ("90 degrees" parsed as number) is 90 with "90 degrees parsed as number is not 90" | ||
assert ("3.141592653589793 radians" parsed as number) is 180.0 with "pi radians parsed as number is not 180 degrees" | ||
assert ("90 degrees" parsed as number) is 90 degrees with "90 degrees parsed as number is not 90 degrees" | ||
assert ("3.141592653589793 radians" parsed as number) is 180.0 degrees with "pi radians parsed as number is not 180 degrees" | ||
assert ("90 degrees" parsed as number) is 0.5 * pi radians with "90 degrees parsed as number is not 0.5pi radians" | ||
assert ("3.141592653589793 radians" parsed as number) is pi radians with "pi radians parsed as number is not pi radians" | ||
|
||
assert 90, 180 and 270 in degrees is 90, 180 and 270 with "90, 180 and 270 degrees is not 90, 180 and 270" | ||
assert 0.5 * pi, pi and 1.5 * pi in radians is 90.0, 180.0 and 270.0 with "0.5pi, pi and 1.5pi radians is not 90, 180 and 270" | ||
|
||
assert ("n" parsed as number) degrees is not set with "'n' parsed as number degrees is set" | ||
assert ("n" parsed as number) radians is not set with "'n' parsed as number radians is set" | ||
assert ("n degrees" parsed as number) is not set with "'n' parsed as number degrees is set" | ||
assert ("n radians" parsed as number) is not set with "'n' parsed as number radians is set" | ||
|
||
assert isNaN(NaN value degrees) is true with "NaN degrees is not NaN" | ||
assert isNaN(NaN value radians) is true with "NaN radians is not NaN" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do you want to support gradians (grad[s]/gon) while you're here?
They're pretty obscure nowadays so I don't mind, but you do occasionally see them used in map stuff and cartography.