mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
Add loading palette to color module
This commit is contained in:
parent
488e78c9d7
commit
d939d017cb
@ -11,6 +11,10 @@ local M = {}
|
|||||||
---@param color_id string Color id from palette or hex color
|
---@param color_id string Color id from palette or hex color
|
||||||
---@return vector4
|
---@return vector4
|
||||||
function M.get_color(color_id)
|
function M.get_color(color_id)
|
||||||
|
if PALETTE_DATA[color_id] then
|
||||||
|
return PALETTE_DATA[color_id]
|
||||||
|
end
|
||||||
|
|
||||||
-- Check is it hex: starts with "#" or contains only 3 or 6 hex symbols
|
-- Check is it hex: starts with "#" or contains only 3 or 6 hex symbols
|
||||||
if type(color_id) == "string" then
|
if type(color_id) == "string" then
|
||||||
if string.sub(color_id, 1, 1) == "#" or string.match(color_id, "^[0-9a-fA-F]+$") then
|
if string.sub(color_id, 1, 1) == "#" or string.match(color_id, "^[0-9a-fA-F]+$") then
|
||||||
@ -18,7 +22,7 @@ function M.get_color(color_id)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return PALETTE_DATA[color_id] or COLOR_WHITE
|
return COLOR_WHITE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -171,4 +175,22 @@ function M.rgb2hex(red, green, blue)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local load_palette_from_json = function(path)
|
||||||
|
local data = sys.load_resource(path)
|
||||||
|
if not data then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
return json.decode(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
local DEFAULT_PALETTE_PATH = sys.get_config_string("druid.palette_path")
|
||||||
|
if DEFAULT_PALETTE_PATH then
|
||||||
|
local loaded_palette = load_palette_from_json(DEFAULT_PALETTE_PATH)
|
||||||
|
if loaded_palette and loaded_palette["default"] then
|
||||||
|
M.add_palette(loaded_palette["default"])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
Loading…
x
Reference in New Issue
Block a user