-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split image.sk to multiple sk files, within a subfolder
scripts/image.sk/
- Loading branch information
1 parent
9b72853
commit a738e35
Showing
33 changed files
with
1,484 additions
and
1,305 deletions.
There are no files selected for viewing
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,68 @@ | ||
# ############################## | ||
# Main file of image.sk | ||
# | ||
# https://github.com/Blueyescat/image.sk | ||
# | ||
# Please don't change this file, write your script in another sk file. | ||
# ############################## | ||
|
||
options: | ||
# If changing this is really important for you, you need to change it in all image.sk files. | ||
variable: imagesk # {imagesk::xxx} | ||
|
||
import: | ||
java.awt.Color | ||
java.util.Base64 | ||
|
||
org.bukkit.Bukkit | ||
|
||
ch.njol.skript.Skript | ||
ch.njol.skript.util.Color as SkriptColor | ||
ch.njol.skript.variables.Variables | ||
|
||
on load: | ||
set {{@variable}::Logger} to Bukkit.getServer().getLogger() | ||
set {{@variable}::Decoder} to Base64.getDecoder() | ||
set {{@variable}::Encoder} to Base64.getEncoder() | ||
|
||
# Workaround for a skript-mirror limitation | ||
delete {{@variable}::useFloatColorMethod} | ||
set {_color} to try new Color(255, 255, 255) | ||
if "%last java error%" contains "Color parameter outside of expected range": | ||
set {{@variable}::useFloatColorMethod} to true | ||
|
||
on skript unload: | ||
loop {{@variable}::*}: | ||
if loop-index is not "lastImage": | ||
delete {{@variable}::%loop-index%} and {{@variable}::%loop-index%::*} | ||
|
||
# You shouldn't use the syntaxes below in your scripts | ||
effect imagesk [(1¦parse)] error %string%: | ||
trigger: | ||
if parse mark is 1: | ||
Skript.error(expression-1) | ||
else: | ||
{{@variable}::Logger}.severe("[image.sk] %expression-1%") | ||
|
||
effect imagesk warning %string%: | ||
trigger: | ||
{{@variable}::Logger}.warning("[image.sk] %expression-1%") | ||
|
||
effect imagesk set variable %object% to %object% in %event%: | ||
trigger: | ||
set {_variable} to expression-1 | ||
set {_name} to {_variable}.getName().toString(expression-3) | ||
Variables.setVariable({_name}, expression-2, expression-3, {_variable}.isLocal()) | ||
|
||
expression imagesk java color %object%: | ||
get: | ||
if expression-1 is instance of SkriptColor: | ||
return new Color(expression-1.getBukkitColor().asRGB()) | ||
return expression-1 | ||
# You shouldn't use the syntaxes above in your scripts | ||
|
||
expression [the] [last[ly]] [(created|generated|received|taken)] (image|img): | ||
get: | ||
return {{@variable}::lastImage} | ||
delete: | ||
delete {{@variable}::lastImage} |
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,13 @@ | ||
import: | ||
java.awt.Color | ||
java.awt.image.BufferedImage | ||
|
||
function imagesk_pixelColor(image: object, x: number, y: number) :: object: | ||
set {_rgb} to {_image}.getRGB({_x} and {_y}) | ||
return new Color((bits 16-23 of {_rgb}), (bits 8-15 of {_rgb}) and (bits 0-7 of {_rgb})) | ||
|
||
function imagesk_setPixelColor(image: object, x: number, y: number, rgb: number): | ||
{_image}.setRGB({_x}, {_y} and {_rgb}) | ||
|
||
function imagesk_copiedImage(image: object) :: object: | ||
return new BufferedImage(({_image}.getColorModel()), ({_image}.copyData(null)), ({_image}.isAlphaPremultiplied()) and null) |
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 @@ | ||
import: | ||
java.awt.Color | ||
|
||
object property condition similar to %object% [with (tolerance %-number% [percent]|%-number% [percent] tolerance)]: | ||
check: | ||
if (imagesk java color expression-1) or (imagesk java color expression-2) isn't instance of Color: | ||
stop | ||
if expression-3 is set: | ||
set {_tolerance} to expression-3 | ||
else if expression-4 is set: | ||
set {_tolerance} to expression-4 | ||
else: | ||
set {_tolerance} to 0 | ||
if {_tolerance} is greater than 100: | ||
set {_tolerance} to 100 | ||
else if {_tolerance} is smaller than 0: | ||
set {_tolerance} to 0 | ||
set {_tolerance} to (255 / 100) * {_tolerance} | ||
set {_color1} to imagesk java color expression-1 | ||
set {_color2} to imagesk java color expression-2 | ||
set {_r1} to {_color1}.getRed() | ||
set {_g1} to {_color1}.getGreen() | ||
set {_b1} to {_color1}.getBlue() | ||
set {_minR} to max({_r1} - {_tolerance} and 0) | ||
set {_minG} to max({_g1} - {_tolerance} and 0) | ||
set {_minB} to max({_b1} - {_tolerance} and 0) | ||
set {_maxR} to min({_r1} + {_tolerance} and 255) | ||
set {_maxG} to min({_g1} + {_tolerance} and 255) | ||
set {_maxB} to min({_b1} + {_tolerance} and 255) | ||
if {_color2}.getRed() is between {_minR} and {_maxR}: | ||
if {_color2}.getGreen() is between {_minG} and {_maxG}: | ||
if {_color2}.getBlue() is between {_minB} and {_maxB}: | ||
continue |
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,62 @@ | ||
import: | ||
java.awt.Point | ||
java.util.LinkedList | ||
|
||
ch.njol.skript.lang.Variable | ||
|
||
effect [(flood|bucket)] fill [on] [(image|img)] %object% (with|using) [replace[ment]] [colo[u]r] %object% at [location] %number%( and|,) %number% [with (tolerance %-number% [percent]|%-number% [percent] tolerance)] [[and] (store|save) ([[the] result]|it) (in|to) [variable] %-object%]: | ||
parse: | ||
if expression-7 is set: | ||
if expression-7 isn't instance of Variable: | ||
imagesk parse error "'%expression-7%' is not a variable." | ||
stop | ||
continue | ||
trigger: | ||
if raw expression-7 is set: | ||
set {_image} to imagesk_copiedImage(expression-1) | ||
else: | ||
set {_image} to expression-1 | ||
if expression-3 or expression-4 is smaller than 0: | ||
stop | ||
if expression-3 is greater than or equal to {_image}.getWidth(): | ||
stop | ||
if expression-4 is greater than or equal to {_image}.getHeight(): | ||
stop | ||
set {_target} to imagesk_pixelColor({_image}, expression-3, expression-4) | ||
set {_replacement} to imagesk java color expression-2 | ||
if {_target} is {_replacement}: | ||
stop | ||
if expression-5 is set: | ||
set {_tolerance} to expression-5 | ||
else if expression-6 is set: | ||
set {_tolerance} to expression-6 | ||
else: | ||
set {_tolerance} to 0 | ||
if {_tolerance} is greater than 100: | ||
set {_tolerance} to 100 | ||
else if {_tolerance} is smaller than 0: | ||
set {_tolerance} to 0 | ||
set {_tolerance} to ({_tolerance} / 255) * 120 | ||
if imagesk_pixelColor({_image}, expression-3, expression-4) isn't similar to {_target} with tolerance {_tolerance}: | ||
stop | ||
delay the current effect | ||
set {_queue} to new LinkedList() | ||
{_queue}.add(new Point(expression-3 and expression-4)) | ||
while {_queue}.isEmpty() is false: | ||
set {_pixel} to {_queue}.removeFirst() | ||
if imagesk_pixelColor({_image}, ({_pixel}.x!) + 1, {_pixel}.y!) is similar to {_target} with tolerance {_tolerance}: | ||
imagesk_setPixelColor({_image}, ({_pixel}.x!) + 1, {_pixel}.y!, {_replacement}.getRGB()) | ||
{_queue}.addLast(new Point((({_pixel}.x!) + 1) and {_pixel}.y!)) | ||
if imagesk_pixelColor({_image}, ({_pixel}.x!) - 1, {_pixel}.y!) is similar to {_target} with tolerance {_tolerance}: | ||
imagesk_setPixelColor({_image}, ({_pixel}.x!) - 1, {_pixel}.y!, {_replacement}.getRGB()) | ||
{_queue}.addLast(new Point((({_pixel}.x!) - 1) and {_pixel}.y!)) | ||
if imagesk_pixelColor({_image}, {_pixel}.x!, ({_pixel}.y!) + 1) is similar to {_target} with tolerance {_tolerance}: | ||
imagesk_setPixelColor({_image}, {_pixel}.x!, ({_pixel}.y! + 1), {_replacement}.getRGB()) | ||
{_queue}.addLast(new Point({_pixel}.x! and ({_pixel}.y! + 1))) | ||
if imagesk_pixelColor({_image}, {_pixel}.x!, ({_pixel}.y!) - 1) is similar to {_target} with tolerance {_tolerance}: | ||
imagesk_setPixelColor({_image}, {_pixel}.x!, ({_pixel}.y! - 1), {_replacement}.getRGB()) | ||
{_queue}.addLast(new Point({_pixel}.x! and ({_pixel}.y! - 1))) | ||
delete {_queue} | ||
if raw expression-7 is set: | ||
imagesk set variable (raw expression-7) to {_image} in event | ||
continue |
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,40 @@ | ||
options: | ||
# If changing this is really important for you, you need to change it in all image.sk files. | ||
variable: imagesk # {imagesk::xxx} | ||
|
||
import: | ||
java.awt.Color | ||
java.awt.image.BufferedImage | ||
|
||
ch.njol.skript.lang.Variable | ||
|
||
effect create [a[n]] [new] image with (0¦width %-number%[( and|,)] [with] height %-number%|1¦height %-number%[( and|,)] [with] width %-number%)[[( and|,)] [with] b[ack]g[round] %-object%] [[and] (store|save) ([[the] result]|it) (in|to) [variable] %-object%]: | ||
parse: | ||
if expression-6 is set: | ||
if expression-6 isn't instance of Variable: | ||
imagesk parse error "'%expression-6%' is not a variable." | ||
stop | ||
continue | ||
trigger: | ||
delay the current effect | ||
if parse mark is 0: | ||
set {_width} to rounded expression-1 | ||
set {_height} to rounded expression-2 | ||
else if parse mark is 1: | ||
set {_height} to rounded expression-3 | ||
set {_width} to rounded expression-4 | ||
if {_width} is smaller than 1: | ||
set {_width} to 1 | ||
if {_height} is smaller than 1: | ||
set {_height} to 1 | ||
set {_image} to new BufferedImage({_width}, {_height} and BufferedImage.TYPE_INT_ARGB!) | ||
if imagesk java color expression-5 is instance of Color: | ||
set {_g} to {_image}.createGraphics() | ||
{_g}.setColor(imagesk java color expression-5) | ||
{_g}.fillRect(0, 0, {_width} and {_height}) | ||
{_g}.dispose() | ||
if raw expression-6 is set: | ||
imagesk set variable (raw expression-6) to {_image} in event | ||
else: | ||
set {{@variable}::lastImage} to {_image} | ||
continue |
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,18 @@ | ||
options: | ||
# If changing this is really important for you, you need to change it in all image.sk files. | ||
variable: imagesk # {imagesk::xxx} | ||
|
||
import: | ||
java.awt.Color | ||
java.awt.Font | ||
|
||
effect (create|generate) [a[n]] [new] [(image|img)] (text|string) [(with (id|name)|named)] %string% [[and] with text %-string%]: | ||
trigger: | ||
if {{@variable}::texts::%expression-1%} is set: | ||
delete {{@variable}::texts::%expression-1%::*} | ||
set {{@variable}::texts::%expression-1%} to true | ||
if expression-2 is set: | ||
set {{@variable}::texts::%expression-1%::text} to expression-2 | ||
set {{@variable}::texts::%expression-1%::font} to Font.DIALOG! | ||
set {{@variable}::texts::%expression-1%::size} to 12 | ||
set {{@variable}::texts::%expression-1%::foreground} to Color.WHITE! |
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,50 @@ | ||
import: | ||
java.awt.BasicStroke | ||
java.awt.Color | ||
java.awt.RenderingHints | ||
java.awt.image.BufferedImage | ||
|
||
ch.njol.skript.lang.Variable | ||
|
||
effect draw [a[n]] circle [(1¦outline [with width %-number%])] on [(image|img)] %object% with (radius|width|height) %number%[[( and|,)] [with] %-object%] [at [[center] location] %-number%( and|,) %-number%] [[and] (store|save) ([[the] result]|it) (in|to) [variable] %-object%]: | ||
parse: | ||
if expression-7 is set: | ||
if expression-7 isn't instance of Variable: | ||
imagesk parse error "'%expression-7%' is not a variable." | ||
stop | ||
continue | ||
trigger: | ||
if expression-2 isn't instance of BufferedImage: | ||
stop | ||
delay the current effect | ||
if expression-5 is set: | ||
set {_x} to expression-5 | ||
set {_x} to {_x} - 1 | ||
else: | ||
set {_x} to 0 | ||
if expression-6 is set: | ||
set {_y} to expression-6 | ||
set {_y} to {_y} - 1 | ||
else: | ||
set {_y} to 0 | ||
if raw expression-7 is set: | ||
set {_image} to imagesk_copiedImage(expression-2) | ||
else: | ||
set {_image} to expression-2 | ||
set {_g} to {_image}.createGraphics() | ||
if imagesk java color expression-4 is instance of Color: | ||
{_g}.setColor(imagesk java color expression-4) | ||
{_g}.setRenderingHint((RenderingHints.KEY_ANTIALIASING!) and (RenderingHints.VALUE_ANTIALIAS_ON!)) | ||
if parse mark is 1: | ||
if expression-1 is set: | ||
set {_outlineWidth} to expression-1 | ||
else: | ||
set {_outlineWidth} to 1 | ||
{_g}.setStroke(new BasicStroke({_outlineWidth}, (BasicStroke.CAP_ROUND!) and 2)) | ||
{_g}.drawOval(({_x} - expression-3), ({_y} - expression-3), (expression-3 * 2) and (expression-3 * 2)) | ||
else: | ||
{_g}.fillOval(({_x} - expression-3), ({_y} - expression-3), (expression-3 * 2) and (expression-3 * 2)) | ||
{_g}.dispose() | ||
if raw expression-7 is set: | ||
imagesk set variable (raw expression-7) to {_image} in event | ||
continue |
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,36 @@ | ||
import: | ||
java.awt.image.BufferedImage | ||
|
||
ch.njol.skript.lang.Variable | ||
|
||
effect (draw|merge) [(image|img)] %object% (on|with) [(image|img)] %object% [at [location] %-number%( and|,) %-number%] [[and] (store|save) ([[the] result]|it) (in|to) [variable] %-object%]: | ||
parse: | ||
if expression-5 is set: | ||
if expression-5 isn't instance of Variable: | ||
imagesk parse error "'%expression-5%' is not a variable." | ||
stop | ||
continue | ||
trigger: | ||
if expression-1 or expression-2 isn't instance of BufferedImage: | ||
stop | ||
if expression-3 is set: | ||
set {_x} to expression-3 | ||
set {_x} to {_x} - 1 | ||
else: | ||
set {_x} to 0 | ||
if expression-4 is set: | ||
set {_y} to expression-4 | ||
set {_y} to {_y} - 1 | ||
else: | ||
set {_y} to 0 | ||
if raw expression-5 is set: | ||
set {_image} to imagesk_copiedImage(expression-2) | ||
else: | ||
set {_image} to expression-2 | ||
delay the current effect | ||
set {_g} to {_image}.createGraphics() | ||
{_g}.drawImage(expression-1, {_x}, {_y} and null) | ||
{_g}.dispose() | ||
if raw expression-5 is set: | ||
imagesk set variable (raw expression-5) to {_image} in event | ||
continue |
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,51 @@ | ||
import: | ||
java.awt.BasicStroke | ||
java.awt.Color | ||
java.awt.RenderingHints | ||
java.awt.geom.Line2D$Float as Line2DFloat | ||
java.awt.image.BufferedImage | ||
|
||
ch.njol.skript.lang.Variable | ||
|
||
effect draw [a] line [(10¦with ((flat|square) (cap|edge[s])))] on [(image|img)] %object% [with width %-number%][[( and|,)] [with] %-object%] (0¦from [location] %-number%( and|,) %-number% to [location] %-number%( and|,) %-number%|1¦between locations %-number%( and|,) %-number% and %-number%( and|,) %-number%) [[and] (store|save) ([[the] result]|it) (in|to) [variable] %-object%]: | ||
parse: | ||
if expression-12 is set: | ||
if expression-12 isn't instance of Variable: | ||
imagesk parse error "'%expression-12%' is not a variable." | ||
stop | ||
continue | ||
trigger: | ||
if expression-1 isn't instance of BufferedImage: | ||
stop | ||
delay the current effect | ||
if parse mark is 0 or 10: | ||
set {_x1} to expression-4 | ||
set {_y1} to expression-5 | ||
set {_x2} to expression-6 | ||
set {_y2} to expression-7 | ||
else if parse mark is 1 or 11: | ||
set {_x1} to expression-8 | ||
set {_y1} to expression-9 | ||
set {_x2} to expression-10 | ||
set {_y2} to expression-11 | ||
if raw expression-12 is set: | ||
set {_image} to imagesk_copiedImage(expression-1) | ||
else: | ||
set {_image} to expression-1 | ||
set {_g} to {_image}.createGraphics() | ||
if expression-2 is set: | ||
set {_width} to expression-2 | ||
else: | ||
set {_width} to 1 | ||
if parse mark is 10 or 11: | ||
{_g}.setStroke(new BasicStroke({_width})) | ||
else: | ||
{_g}.setStroke(new BasicStroke({_width}, (BasicStroke.CAP_ROUND!) and 2)) | ||
if imagesk java color expression-3 is instance of Color: | ||
{_g}.setColor(imagesk java color expression-3) | ||
{_g}.setRenderingHint((RenderingHints.KEY_ANTIALIASING!) and (RenderingHints.VALUE_ANTIALIAS_ON!)) | ||
{_g}.draw(new Line2DFloat({_x1}, {_y1}, {_x2} and {_y2})) | ||
{_g}.dispose() | ||
if raw expression-12 is set: | ||
imagesk set variable (raw expression-12) to {_image} in event | ||
continue |
Oops, something went wrong.