-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtext_formatter.lua
72 lines (62 loc) · 1.61 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---@class text_formatter
local M = {}
local col_map = {}
---@param colour_codes {[string]: string}
---@param do_cols boolean
function M.init_cols(colour_codes, do_cols)
local colour_char = string.char(27)
M.colour_codes = {}
for k, v in pairs(colour_codes) do
M.colour_codes[k] = v
end
if do_cols then
for k, v in pairs(M.colour_codes) do
M.colour_codes[k] = colour_char .. "[" .. v .. "m"
end
else
for k, _ in pairs(M.colour_codes) do
M.colour_codes[k] = ""
end
end
-- we may not always be called in a context where the engine exists (i.e. help menu)
if ACTION_TYPE_PROJECTILE then
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,
}
end
end
M.ty_map = {}
---@param id string
---@return string
local function colour_of(id)
local key = M.ty_map[id] or ACTION_TYPE_DRAW_MANY
if key then
return col_map[key]
end
return ""
end
---@param id string
---@param translations table<string, string>
---@return string
function M.id_text(id, translations)
local name = translations[id] or id
name = colour_of(id) .. name
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
return M