-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module:RankColor.lua
67 lines (59 loc) · 1.69 KB
/
Module:RankColor.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
local data = mw.loadData('Module:RankColor/data')
local p = {}
--[ Thecow275's RankColor Module V3]--
local RankColor_Template = [[
* Rank: %s
* RankColor: %d
* BracketColor: %d
* RankPlusColor: %d
]]
-- Trim whitespace from args, and treat blank args as nil
local function preprocessArg(s)
if not s then
return nil
end
s = s:match('^%s*(.-)%s*$') -- trim whitespace
if s == '' then
return nil
else
return s
end
end
function p.main(frame)
local args = frame.args
local rank = preprocessArg(args[1])
local rankcolor = preprocessArg(args[2])
local bracketcolor = preprocessArg(args[3]) --[ Bracket Color stuff ]–-
local rankpluscolor = preprocessArg(args[4]) --[ The rank color stuff for the + on rank+ ranks. ]--
-- Check for blank rank arguments
if not rank then
return ''
end
-- Get the data for the specified rank
local rankData = data[rank]
if not rankData then
return ''
end
if rankcolor then
-- User specified a rankcolor, so return it
return rankData[rankcolor] or ''
end
if rankpluscolor then
-- User specified a rankpluscolor, so return it
return rankData[rankpluscolor] or ''
end
if bracketcolor then --[ Bracket Color stuff ]--
-- User specified a bracketcolor, so return it
return rankData[bracketcolor] or ''
else
-- Return the rankcolor template with all the ranks in it
return string(
RankColor_Template,
rankData.rank,
rankData.rankcolor,
rankData.bracketcolor,
rankData.rankpluscolor
)
end
end
return p