No edit summary |
No edit summary |
||
Line 6: | Line 6: | ||
json = 'Module:Spell/Domain/' .. json .. '.json' | json = 'Module:Spell/Domain/' .. json .. '.json' | ||
local all_spells = mw.loadJsonData(json) | local all_spells = mw.loadJsonData(json) | ||
all_spells = all_spells.spells | |||
local out = {} | local out = {} | ||
Line 12: | Line 13: | ||
local ordered_spells = {} | local ordered_spells = {} | ||
for | for spell_level,spells in ipairs(all_spells) do | ||
table.insert(ordered_spells, spell_level) | table.insert(ordered_spells, spell_level) | ||
end | end | ||
Line 31: | Line 32: | ||
table.insert(out, '|}') | table.insert(out, '|}') | ||
return | return #ordered_spells | ||
end | end | ||
Revision as of 17:35, 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) all_spells = all_spells.spells local out = {} table.insert(out, '{| class="wikitable"\n! Level !! Spells\n|-\n') local ordered_spells = {} for spell_level,spells in ipairs(all_spells) do table.insert(ordered_spells, spell_level) end table.sort(ordered_spells) for spell_level, spells in ipairs(ordered_spells) do table.insert(out, "| '''" .. spell_level .. "''' \n|") if #spells > 0 then for index, spell in ipairs(spells) do if index > 1 then table.insert(out, "<br>") end table.insert(out, "" .. spell .. " ") end end table.insert(out, '\n|-') end table.insert(out, '|}') 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