No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function p. | function p.listDomain(frame) | ||
local json = frame.args[1] | local json = frame.args[1] | ||
json = firstToUpper(json) | json = firstToUpper(json) | ||
Line 20: | Line 20: | ||
table.insert(out, "\n| '''" .. getLevelString(k) .. "'''\n|-") | table.insert(out, "\n| '''" .. getLevelString(k) .. "'''\n|-") | ||
for _, is in ipairs(spells[v]) do | for _, is in ipairs(spells[v]) do | ||
table.insert(out, "|| " .. spells[v][is]) | table.insert(out, "|| [[" .. spells[v][is] .. "]]") | ||
end | end | ||
end | end |
Revision as of 12:45, 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 spells = mw.loadJsonData(json) local out = {} table.insert(out, '{| class="wikitable"\n! Level !! Spells\n|-') local ordered_keys = {} for k in pairs(spells) do table.insert(ordered_keys, k) end table.sort(ordered_keys) for i = 1, #ordered_keys do local k, v = ordered_keys[i], spells[ordered_keys[i]] table.insert(out, "\n| '''" .. getLevelString(k) .. "'''\n|-") for _, is in ipairs(spells[v]) do table.insert(out, "|| [[" .. spells[v][is] .. "]]") end end table.insert(out, '\n|}') return out end function firstToUpper(str) return (str:gsub("^%l", string.upper)) end function getLevelString(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