Module:Enemy

local p = {}

function p.key(frame) local t = mw.title.getCurrentTitle local key = t.text if t:inNamespace("Module") then key = frame.pagename end key, _ = key:gsub(" %(Enemy%)$", "") return key end

function p.skills_table(frame) local pf = mw.getCurrentFrame:getParent if mw.title.getCurrentTitle:inNamespace("Module") then pf = frame end local s = {} table.insert(s, "{| class=\"wikitable\"\n") table.insert(s, "! Skill !! Description\n") for i=1,16 do       local skill = pf.args[string.format("skill %d", i)] local desc = pf.args[string.format("desc %d", i)] local icon = pf.args[string.format("icon %d", i)] local iconimg = "" if icon ~= nil then iconimg = string.format("", icon) end if skill ~= nil then table.insert(s, "|-\n") table.insert(s, string.format("| %s %s || %s\n", iconimg, skill, desc or "")) end end table.insert(s, "|}\n") return table.concat(s, "") end

-- Run this before saving function p._test local testcases = { ["Leviathan (Enemy)"] = "Leviathan", ["Scaled Wolf"] = "Scaled Wolf", }   for pname, key in pairs(testcases) do        local x = p.key{pagename=pname, args={}} if x ~= key then mw.log(string.format("%s key is %s; expected %s", pname, x, key)) end end

local x = p.skills_table{args={ ["icon 1"]=8, ["skill 1"]="Fire", ["desc 1"]="burn", ["skill 2"] = "ice"} }   if string.len(x) < 10 then mw.log("skills table too short") end end

return p