More actions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function p. | function p.list(frame) | ||
local json = 'Module:Spell/Domain/' .. firstToUpper(frame.args[1]) .. '.json' | if frame.args.domain ~= nil then | ||
local json = 'Module:Spell/Domain/' .. firstToUpper(frame.args[1]) .. '.json' | |||
local spells = mw.loadJsonData(json) | |||
local out = {} | |||
table.insert(out, '{| class="wikitable"\n! style="text-align:center" | Level !! style="text-align:center" | Spells\n|-\n') | |||
for spell_level,_ in ipairs(spells) do | |||
table.insert(out, "| '''" .. formatLevel(spell_level-1) .. "''' \n|") | |||
for spell_index, spell in ipairs(spells[spell_level]) do | |||
if spell_index > 1 then | |||
table.insert(out, "<br>") | |||
end | |||
table.insert(out, "[[" .. spell .. "]]") | |||
end | end | ||
table.insert(out, | table.insert(out, '\n|-\n') | ||
end | end | ||
table.insert(out, '|}') | |||
return table.concat(out) | |||
end | |||
end | end | ||
Revision as of 15:46, 2 March 2023
Usage
{{#invoke:spell|list|domain=}}
{{#invoke:spell|list|category=}}
local p = {}
function p.list(frame)
if frame.args.domain ~= nil then
local json = 'Module:Spell/Domain/' .. firstToUpper(frame.args[1]) .. '.json'
local spells = mw.loadJsonData(json)
local out = {}
table.insert(out, '{| class="wikitable"\n! style="text-align:center" | Level !! style="text-align:center" | Spells\n|-\n')
for spell_level,_ in ipairs(spells) do
table.insert(out, "| '''" .. formatLevel(spell_level-1) .. "''' \n|")
for spell_index, spell in ipairs(spells[spell_level]) do
if spell_index > 1 then
table.insert(out, "<br>")
end
table.insert(out, "[[" .. spell .. "]]")
end
table.insert(out, '\n|-\n')
end
table.insert(out, '|}')
return table.concat(out)
end
end
function firstToUpper(str)
return (str:gsub("^%l", string.upper))
end
function formatLevel(lv)
local str
if lv == 0 then str = 'Cantrip'
elseif lv == 1 then str = '1st'
elseif lv == 2 then str = '2nd'
elseif lv == 3 then str = '3rd'
else str = lv .. 'th'
end
return str
end
return p