-- Palette auto-detected from current Omarchy system theme local Palette = {} local theme = {} local function hexToRGB(hex) -- Accept only well-formed #rrggbb; anything else falls back to white rather -- than returning {nil, nil, nil} which would crash love.graphics.setColor. if type(hex) ~= "string" then return {1, 1, 1} end local rr, gg, bb = hex:match("^#?(%x%x)(%x%x)(%x%x)$") if not rr then return {1, 1, 1} end return { tonumber(rr, 16) / 255, tonumber(gg, 16) / 255, tonumber(bb, 16) / 255 } end function Palette.loadFromSystem() local path = os.getenv("HOME") .. "/.config/omarchy/current/theme/ghostty.conf" local f = io.open(path, "r") if not f then theme.bg = {0, 0, 0} theme.fg = {1, 1, 1} theme.accent = {1, 1, 1} for i = 0, 15 do theme["color" .. i] = {i/15, i/15, i/15} end theme.dim = theme.color8 return end for line in f:lines() do -- Require exactly 6 hex digits so partial/truncated entries don't slip through local key, val = line:match("^(%S+)%s*=%s*(#%x%x%x%x%x%x)%s*$") if key and val then if key == "background" then theme.bg = hexToRGB(val) elseif key == "foreground" then theme.fg = hexToRGB(val) elseif key == "cursor-color" then theme.accent = hexToRGB(val) end end local idx, hex = line:match("^palette%s*=%s*(%d+)=(#%x%x%x%x%x%x)%s*$") if idx and hex then theme["color" .. idx] = hexToRGB(hex) end end f:close() theme.dim = theme.color8 or theme.color0 or {0.2, 0.2, 0.2} for i = 0, 15 do if not theme["color" .. i] then theme["color" .. i] = theme.fg or {1, 1, 1} end end if not theme.bg then theme.bg = {0, 0, 0} end if not theme.fg then theme.fg = {1, 1, 1} end if not theme.accent then theme.accent = theme.color12 or theme.fg end end function Palette.get() return { bg = theme.bg, fg = theme.fg, tank = theme.fg, enemy = theme.color4, obstacle = theme.color2 or theme.color3, projectile = theme.accent, ground = theme.color0, mountain = theme.color8 or theme.dim, radar_bg = theme.color0, radar_fg = theme.fg, hud = theme.fg, bright = theme.accent, dim = theme.dim, explosion = theme.accent, } end return Palette