-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add colors utilities Local function get_base_color(), conversions hex <=> rgb, rgb color mixer, and global function get_color() * Round numbers to avoid eventual float in string.format * Simplify inbox/outbox mixing of color Use a single if statement for each property and concatenate to displayed_color then execute mail.get_color(displayed_color) instead of making many combined if statements * Convert 3-chars hex colors to 6-chars hex colors Could break the code, the hex convert to rgb always run on 6-chars * Rework color utility using tables Instead of one-letter symbols, it now supports tables of identifiers or single strings
- Loading branch information
Showing
15 changed files
with
86 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
local generic_colors = { | ||
header = "#999999", | ||
selected = "#72FF63", | ||
important = "#FFD700", | ||
additional = "#CCCCDD", | ||
highlighted = "#608631", | ||
new = "#00F529", | ||
} | ||
|
||
local function get_base_color(c) | ||
return generic_colors[c] or "" | ||
end | ||
|
||
local function hex2rgb(hex) | ||
hex = hex:gsub("#","") | ||
return { | ||
r = tonumber("0x" .. hex:sub(1,2)), | ||
g = tonumber("0x" .. hex:sub(3,4)), | ||
b = tonumber("0x" .. hex:sub(5,6)) | ||
} | ||
end | ||
|
||
local function rgb2hex(rgb) | ||
return "#" .. string.format("%x", rgb.r) .. string.format("%x", rgb.g) .. string.format("%x", rgb.b) | ||
end | ||
|
||
local function rgbColorsMix(colors) | ||
local R = 0 | ||
local G = 0 | ||
local B = 0 | ||
for _, c in ipairs(colors) do | ||
R = R + c.r | ||
G = G + c.g | ||
B = B + c.b | ||
end | ||
R = math.floor(R / #colors + 0.5) | ||
G = math.floor(G / #colors + 0.5) | ||
B = math.floor(B / #colors + 0.5) | ||
return {r=R,g=G,b=B} | ||
end | ||
|
||
function mail.get_color(mix) | ||
if type(mix) == "string" then | ||
return get_base_color(mix) | ||
elseif #mix == 1 then | ||
return get_base_color(mix[1]) | ||
else | ||
local colors2mix = {} | ||
for _, c in ipairs(mix) do | ||
colors2mix[#colors2mix+1] = hex2rgb(get_base_color(c)) | ||
end | ||
local mixed_color = rgbColorsMix(colors2mix) | ||
return rgb2hex(mixed_color) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
-- sub files | ||
local MP = minetest.get_modpath(minetest.get_current_modname()) | ||
dofile(MP .. "/util/normalize.lua") | ||
dofile(MP .. "/util/colors.lua") | ||
dofile(MP .. "/util/contact.lua") | ||
dofile(MP .. "/util/uuid.lua") | ||
dofile(MP .. "/util/time_ago.lua") |