-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGenerationsData.lua
More file actions
127 lines (95 loc) · 3.24 KB
/
GenerationsData.lua
File metadata and controls
127 lines (95 loc) · 3.24 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
--[[
Module used as a frontend to wikicode for Gens-data module.
Each interface function is documented in its own comment, with examples.
--]]
local b = {}
-- stylua: ignore start
local tab = require('Wikilib-tables')
local txt = require('Wikilib-strings')
local css = require('Css')
local gens = require("Gens-data")
local c = require("Colore-data")
-- stylua: ignore end
--[[
Return the number of the last (current) generation
Ex:
{{#invoke: GenerationsData | getLastGen }} --> 8
--]]
b.getLastGen = function(frame)
return gens.latest
end
b.GetLastGen = b.getLastGen
-- Internal function to convert a roman number to arabic. The number should
-- corespond to a generation.
local function roman2arabic(roman)
return tab.find(gens, function(gentab)
return gentab.roman == roman
end, ipairs)
end
-- Internal function to get the gens-data
local function genTable(gen)
gen = roman2arabic(gen) or tonumber(gen)
return gens[gen]
end
--[[
Return the ordinal number of the given generation (either an arabic or roman
number). The result is all lowercase.
Ex: {{#invoke: GenerationsData | getOrdinal | 4 }} --> quarta
Ex: {{#invoke: GenerationsData | getOrdinal | III }} --> terza
--]]
b.getOrdinal = function(frame)
local gen = txt.trim(frame.args[1])
return genTable(gen).ext
end
b.GetOrdinal = b.getOrdinal
--[[
Return the roman number of the given generation (either an arabic or roman
number).
Ex: {{#invoke: GenerationsData | getRoman | 7 }} --> VII
Ex: {{#invoke: GenerationsData | getRoman | IX }} --> IX
--]]
b.getRoman = function(frame)
local gen = txt.trim(frame.args[1])
return genTable(gen).roman
end
b.GetRoman = b.getRoman
--[[
Return the region of the given generation (either an arabic or roman number).
The result is all lowercase.
Ex: {{#invoke: GenerationsData | getRegion | 4 }} --> sinnoh
Ex: {{#invoke: GenerationsData | getRegion | III }} --> hoenn
--]]
b.getRegion = function(frame)
local gen = txt.trim(frame.args[1])
return genTable(gen).region
end
b.GetRegion = b.getRegion
--[[
Return the color of the region of the given generation (either an arabic or
roman number). This function behaves like a color module call: the first
argument is the generation, and the second is an (optional) shade.
Ex: {{#invoke: GenerationsData | getRegionColor | 4 }} --> 9ECF17
Ex: {{#invoke: GenerationsData | getRegionColor | II | light }} --> FFB287
--]]
b.getRegionColor = function(frame)
local gen = txt.trim(frame.args[1])
local region = genTable(gen).region
local shade = txt.trim(frame.args[2] or "normale")
return c[region][shade]
end
b.GetRegionColor = b.getRegionColor
--[[
Return the gradient of the region of the given generation (either an arabic or
roman number). The first argument is the generation, the second is a function
in module Css to invoke (such as horizGrad).
Ex: {{#invoke: GenerationsData | getRegionGradient | 8 | horizGrad }}
Ex: {{#invoke: GenerationsData | getRegionGradient | V | radialGrad }}
--]]
b.getRegionGradient = function(frame)
local gen = txt.trim(frame.args[1])
local region = genTable(gen).region
local func = txt.trim(frame.args[2]) .. "Lua"
return css[func]({ type = region })
end
b.GetRegionGradient = b.getRegionGradient
return b