summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/color.lua30
1 files changed, 16 insertions, 14 deletions
diff --git a/script/core/color.lua b/script/core/color.lua
index f5c792a3..2cbcce11 100644
--- a/script/core/color.lua
+++ b/script/core/color.lua
@@ -19,9 +19,9 @@ end
local function textToColor(colorText)
return {
alpha = tonumber(colorText:sub(1, 2), 16) / 255,
- red = tonumber(colorText:sub(3, 4), 16) / 255,
+ red = tonumber(colorText:sub(3, 4), 16) / 255,
green = tonumber(colorText:sub(5, 6), 16) / 255,
- blue = tonumber(colorText:sub(7, 8), 16) / 255,
+ blue = tonumber(colorText:sub(7, 8), 16) / 255,
}
end
@@ -29,11 +29,12 @@ end
---@param color Color
---@return string
local function colorToText(color)
- return (''
- .. string.format('%02x', math.tointeger(color.alpha * 255))
- .. string.format('%02x', math.tointeger(color.red * 255))
- .. string.format('%02x', math.tointeger(color.green * 255))
- .. string.format('%02x', math.tointeger(color.blue * 255))):upper()
+ return string.format('%02X%02X%02X%02X'
+ , math.floor(color.alpha * 255)
+ , math.floor(color.red * 255)
+ , math.floor(color.green * 255)
+ , math.floor(color.blue * 255)
+ )
end
---@class Color
@@ -48,29 +49,30 @@ end
---@field finish integer
---@async
-function colors(uri)
+local function colors(uri)
local state = files.getState(uri)
local text = files.getText(uri)
if not state or not text then
return nil
end
---@type ColorValue[]
- local colors = {}
+ local colorValues = {}
guide.eachSource(state.ast, function (source) ---@async
if source.type == 'string' and isColor(source) then
---@type string
local colorText = source[1]
-
- colors[#colors+1] = {
- start = source.start + 1,
+
+ colorValues[#colorValues+1] = {
+ start = source.start + 1,
finish = source.finish - 1,
- color = textToColor(colorText)
+ color = textToColor(colorText)
}
end
end)
- return colors
+ return colorValues
end
+
return {
colors = colors,
colorToText = colorToText