-
Notifications
You must be signed in to change notification settings - Fork 1
/
text_formatter.lua
58 lines (51 loc) · 1.38 KB
/
text_formatter.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
---@class text_formatter
local M = {}
local colour_char = string.char(27)
M.colour_codes =
{ RESET = "0", GREY = "30", RED = "31", GREEN = "32", YELLOW = "33", BLUE = "34", PINK = "35", CYAN = "36" }
for k, v in pairs(M.colour_codes) do
M.colour_codes[k] = colour_char .. "[" .. v .. "m"
end
M.ty_map = {}
local col_map = {
[ACTION_TYPE_PROJECTILE] = M.colour_codes.RED,
[ACTION_TYPE_STATIC_PROJECTILE] = M.colour_codes.RED,
[ACTION_TYPE_MODIFIER] = M.colour_codes.BLUE,
[ACTION_TYPE_UTILITY] = M.colour_codes.PINK,
[ACTION_TYPE_MATERIAL] = M.colour_codes.GREEN,
[ACTION_TYPE_OTHER] = M.colour_codes.YELLOW,
[ACTION_TYPE_DRAW_MANY] = M.colour_codes.CYAN,
[ACTION_TYPE_PASSIVE] = M.colour_codes.CYAN,
}
local colours = true
local function colour_of(id)
return col_map[M.ty_map[id] or ACTION_TYPE_DRAW_MANY]
end
---@param id string
---@param translations table<string, string>
---@return string
function M.id_text(id, translations)
local name = translations[id] or id
if colours then
name = colour_of(id) .. name
end
return name
end
---@param a node
---@param b node
---@return boolean?
function M.colour_compare(a, b)
if colour_of(a.name) ~= colour_of(b.name) then
return colour_of(a.name) > colour_of(b.name)
end
return nil
end
function M.set_colours(cols)
colours = cols
if not cols then
for k, v in pairs(M.colour_codes) do
M.colour_codes[k] = ""
end
end
end
return M