SethBling / cbscript

CBScript for Minecraft
1.13k stars 28 forks source link

Add custom color support to tell #24

Open Mystievous opened 3 months ago

Mystievous commented 3 months ago

Text components in game support custom hex colors in addition to the specific named ones.

This PR adds support for that to the parsing for tell.

Examples:

function test_tell()
    tell @a "{#FF00FFHello"
end

image

function test_tell_2()
    tell @a "{#317cbdThese {#fc8a3dare {#c309e8colors"
end

image

ike709 commented 2 months ago

Why is there no closing } bracket? It hurts readability with no separator between the color and the text.

Plus, if you parsed for a closing bracket you could then remove the length check and support other inputs such as 3-char hex (e.g. writing {#FFF} would be evaluated the same as {#FFFFFF}.

Mystievous commented 2 months ago

I agree with both points about readability and supporting more than just 6-char hex. However, I believe using a closing brace would require changing the existing convention set by some of the other features of the tell command, where { is used as a "formatting start" character rather than an actual open brace that's meant to be closed.

You can see all of the already existing formatting symbols using this in the comments of the tellraw.py file

{C for color
{U for underline, {u to exit underline, same for {D bold, {S strikethrough and {I italic
{- to clear formatting
...

So with the latest cbscript, the following should print an italicized gray "Hello", and a non-italics blue "World!"

function test_tell()
    tell @a "{I{wHello{i {BWorld!"
end

I tried to keep my addition consistent with this while still allowing more freedom with the colors.

ike709 commented 2 months ago

Fair enough for consistency, but now I think that all of them should be changed to have a closing bracket. because {ufoo is similarly difficult for readability.

Out of scope for this PR, but there can just be a helper method in the parser somewhere to get all tokens within a pair of curly braces that all of the tell format tags can share (with sanity checks for if it hits a newline or EOF token). This would standardize the parsing for all of them going forwards, so each format tag isn't rolling its own parser.