Skip to content

Colours Are Cool 🌈#8470

Draft
cheeezburga wants to merge 4 commits intoSkriptLang:dev/featurefrom
cheeezburga:cool-colours-again
Draft

Colours Are Cool 🌈#8470
cheeezburga wants to merge 4 commits intoSkriptLang:dev/featurefrom
cheeezburga:cool-colours-again

Conversation

@cheeezburga
Copy link
Member

Continuation of #7246. That PR was a bit messy in the end (changing files which didn't need to be changed, etc.), so this will be a cleaner version of it which I intend to maintain.

Problem

Skript doesn't currently have any colour-related syntax. This PR adds a few colour manipulation expressions and functions. While there is more that could be added, these are the main ones. Find below a list of new syntax:

  • Blend expression: blends colours together
  • Complement expression: returns the complement of a colour(s), optionally using HSL adjustments
  • shade function: shades a colour by a given amount, optionally using HSL adjustments
  • tint function: tints a colour by a given amount, optionally using HSL adjustments
  • colourBrightness function: adjusts the brightness of a colour by a given amount. This is similar to, but not the same as, the shade and tint functions
  • grayscale function: converts a colour to its grayscale equivalent
  • sepiatone function: converts a colour to its sepiatone equivalent

This PR also adds channel as an option in ExprARGB.

Solution

  • Implements new colour utility classes (ColorHSL, ColorHSB, ColorUtils).
  • Creates a ColorModule, and centralizes all the colour stuff.
  • Moves registration of the Color class into said module.
  • All syntax registration (including functions) uses the new registration API.
  • Removes serialization of colours using Yggdrasil stuff, as it didn't work with colours before anyway. The new method of serializing colours is by the serializer attached to the class during registration. This doesn't work for SkriptColors currently.

Testing Completed

  • Suite of testing scripts for new colour expressions and functions, and ensures compatibility with all other tests.
  • Tests are currently failing, I think primarily due to serialization as mentioned above.
I used this script to do some basic testing in the early stages of the PR, so feel free to try it:

on load:
    set {block} to "█"
    set {blocks} to {block} repeated 10 times

function hexTest():
    loop all colours:
        broadcast "%loop-value%: %hex of loop-value%"

function blendTest(colour1: colour, colour2: colour):
    set {_asHex1} to hex of {_colour1}
    set {_asHex2} to hex of {_colour2}
    send action bar (formatted "Testing blending of %{_asHex1}%%{blocks}% &fto %{_asHex2}%%{blocks}%") to all players
    loop integers from 0 to 100:
        set {_blendedColour} to {_colour1} blended with {_colour2} by a factor of loop-value
        set {_asHex} to hex of {_blendedColour}
        send title (formatted "%{_asHex}%%{blocks}%") to all players for 2 ticks with fade in 0 ticks and fade out 0 ticks
        send "%{_blendedColour}%: %loop-value%" to all players
        wait 1 tick

function complementTest(colour: colour):
    set {_asHex} to hex of {_colour}
    send action bar (formatted "Testing complement of %{_asHex}%%{blocks}%") to all players
    send title (formatted "%{_asHex}%%{blocks}%") to all players for 2 seconds with fade in 0 ticks and fade out 0 ticks
    wait 39 ticks
    set {_complement} to complement of {_colour}
    set {_asHex} to hex of {_complement}
    send title (formatted "%{_asHex}%%{blocks}%") to all players for 2 seconds with fade in 0 ticks and fade out 0 ticks
    wait 39 ticks
    set {_complement} to hsl complement of {_colour}
    set {_asHex} to hex of {_complement}
    send title (formatted "%{_asHex}%%{blocks}%") to all players for 2 seconds with fade in 0 ticks and fade out 0 ticks

function shadeTest(colour: colour):
    set {_asHex} to hex of {_colour}
    send action bar (formatted "Testing shading of %{_asHex}%%{blocks}%") to all players
    loop 100 times:
        set {_shadedColour} to shade({_colour}, loop-value)
        set {_asHex} to hex of {_shadedColour}
        send title (formatted "%{_asHex}%%{blocks}%") to all players for 2 ticks with fade in 0 ticks and fade out 0 ticks
        send {_shadedColour} to all players
        wait 1 tick

function tintTest(colour: colour):
    set {_asHex} to hex of {_colour}
    send action bar (formatted "Testing tinting of %{_asHex}%%{blocks}%") to all players
    loop 100 times:
        set {_tintedColour} to tint({_colour}, loop-value)
        set {_asHex} to hex of {_tintedColour}
        send title (formatted "%{_asHex}%%{blocks}%") to all players for 2 ticks with fade in 0 ticks and fade out 0 ticks
        send {_tintedColour} to all players
        wait 1 tick

function brightnessTest(colour: colour):
    set {_asHex} to hex of {_colour}
    send action bar (formatted "Testing brightness of %{_asHex}%%{blocks}%") to all players
    loop integers from -100 to 100:
        set {_tintedColour} to colourBrightness({_colour}, loop-value)
        set {_asHex} to hex of {_tintedColour}
        send title (formatted "%{_asHex}%%{blocks}%") to all players for 2 ticks with fade in 0 ticks and fade out 0 ticks
        send {_tintedColour} to all players
        wait 1 tick
    
function grayscaleTest(colour: colour):
    set {_asHex} to hex of {_colour}
    send action bar (formatted "Testing grayscale of shading of %{_asHex}%%{blocks}%") to all players
    loop 100 times:
        set {_shadedColour} to shade({_colour}, loop-value)
        set {_grayscale} to grayscale({_shadedColour})
        set {_asHex} to hex of {_grayscale}
        send title (formatted "%{_asHex}%%{blocks}%") to all players for 2 ticks with fade in 0 ticks and fade out 0 ticks
        send {_shadedColour} to all players
        wait 1 tick

function sepiatoneTest(colour: colour):
    set {_asHex} to hex of {_colour}
    send action bar (formatted "Testing sepiatone of shading of %{_asHex}%%{blocks}%") to all players
    loop 100 times:
        set {_shadedColour} to shade({_colour}, loop-value)
        set {_sepia} to sepiatone({_shadedColour})
        set {_asHex} to hex of {_sepia}
        send title (formatted "%{_asHex}%%{blocks}%") to all players for 2 ticks with fade in 0 ticks and fade out 0 ticks
        send {_shadedColour} to all players
        wait 1 tick

Supporting Information

Shouldn't be any breaking changes. Considering removing the SkriptColor class entirely, and defining each value as it's own static constant in ColorRGB, or a new class like ColorPreset or something, so that they can be properly serialized. Still not sure what exactly causes SkriptColors only not to be serialized.


Completes: none
Related: #7246 #
AI assistance: none

- Updated syntax registration to use new API, including functions and module
- Reimplement all colour utility classes (ColorHSL, ColorHSB, ColorUtils)
- Move Color class registration to module
- Has since been added to ColorRGB as a static method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant