More actions
No edit summary |
No edit summary |
||
Line 11: | Line 11: | ||
table.insert(out, '{| class="wikitable"\n! Level !! Spells\n|-') | table.insert(out, '{| class="wikitable"\n! Level !! Spells\n|-') | ||
local out2 = {} | |||
local ordered_spells = {} | local ordered_spells = {} | ||
for k in pairs(all_spells | for k in pairs(all_spells) do | ||
table.insert(ordered_spells, k) | table.insert(ordered_spells, k) | ||
table.insert(out2, k) | |||
end | end | ||
return table.concat(out2) | |||
end | |||
--[[ | |||
table.sort(ordered_spells) | table.sort(ordered_spells) | ||
for i = 1,#ordered_spells do | for i = 1,#ordered_spells do | ||
Line 25: | Line 28: | ||
if #spells > 0 then | if #spells > 0 then | ||
for _, spell in ipairs(spells) do | for _, spell in ipairs(spells) do | ||
table.insert(out, "[[" .. spell .. "]] <br>") | table.insert(out, "\[\[" .. spell .. "\]\] <br>") | ||
end | end | ||
end | end | ||
Line 34: | Line 37: | ||
return #ordered_spells | return #ordered_spells | ||
end | end | ||
]]-- | |||
function firstToUpper(str) | function firstToUpper(str) | ||
return (str:gsub("^%l", string.upper)) | return (str:gsub("^%l", string.upper)) |
Revision as of 13:21, 1 March 2023
Usage
{{#invoke:spell|list|domain=}}
{{#invoke:spell|list|category=}}
local p = {}
function p.listDomain(frame)
local json = frame.args[1]
json = firstToUpper(json)
json = 'Module:Spell/Domain/' .. json .. '.json'
local all_spells = mw.loadJsonData(json)
local out = {}
table.insert(out, '{| class="wikitable"\n! Level !! Spells\n|-')
local out2 = {}
local ordered_spells = {}
for k in pairs(all_spells) do
table.insert(ordered_spells, k)
table.insert(out2, k)
end
return table.concat(out2)
end
--[[
table.sort(ordered_spells)
for i = 1,#ordered_spells do
local spell_lv = ordered_spells[i]
local spells = all_spells[spell_lv]
table.insert(out, "\n| '''" .. formatLevel(spell_lv) .. "''' ||")
if #spells > 0 then
for _, spell in ipairs(spells) do
table.insert(out, "\[\[" .. spell .. "\]\] <br>")
end
end
table.insert(out, '\n')
end
table.insert(out, '\n|}')
return #ordered_spells
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