Module:SkillTable EO2U

local p = {}

function p.skill_table(frame) -- Frame arguments are strings, but we need this one as a number local max_lv = tonumber(frame.args["max_level"]) -- Split up TP cost input if frame.args["tp_cost"] ~= "" then tp_costs = mw.text.split(frame.args["tp_cost"], ";%s") end local skill_desc = frame.args["skill_desc"] .. "\n" -- Add body parts/stats used to skill description if frame.args["body_parts"] ~= "" then skill_desc = skill_desc .. "\nBody part(s) used: " .. frame.args["body_parts"] .. "\n" end -- Split up prerequisite input, and add to skill description if frame.args["prereq"] ~= "" then prereq = mw.text.split(frame.args["prereq"], ";%s") prereq_lv = mw.text.split(frame.args["prereq_level"], ";%s") local prereq_data = "" for i = 1, #prereq do prereq_data = prereq_data .. "\n* " .. prereq[i] .. ", lv. " .. prereq_lv[i] end skill_desc = skill_desc .. "\nRequires:" .. prereq_data end -- Split up skill parameter input and convert to a table for easier usage params = {} for i = 1, 6 do       if frame.args["param"..i] ~= "" then params[i] = { frame.args["param"..i], frame.args["param"..i.."_type"], mw.text.split(frame.args["param"..i.."_value"], ";%s") }       end end

-- Start building the output table out_table = mw.html.create("table") :addClass("wikitable"):css("width", "100%") :tag("tr") :tag("th"):attr("colspan", "11"):wikitext(frame.args["skill_name"]):done :done :tag("td"):attr("colspan", "11"):wikitext(skill_desc):done :done

-- Needs to run twice for skills that go up to level 20 via Grimoires, -- using max_lv lets it only run once for skills that only go to level 10 for g = 0, max_lv - 10, 10 do		local tr = out_table:tag("tr") :tag("th"):css("width", "20%"):wikitext("Level"):done -- Add level headings for i = 1 + g, 10 + g do	       tr:tag("th"):css("width", "8%"):wikitext(i):done end -- If skill has a TP cost, add it to the table if tp_costs ~= nil then local tr = out_table:tag("tr") :tag("th"):wikitext("TP cost"):done -- Loop through each item and merge identical adjacent values into a single cell local colspan = 0 local prev_value = tp_costs[1 + g]	       for i = 1 + g, 10 + g do	        	if prev_value == tp_costs[i] then colspan = colspan + 1 else tr:tag("td"):css("text-align", "center"):attr("colspan", colspan):wikitext(tp_costs[i-1]):done prev_value = tp_costs[i] colspan = 1 end end tr:tag("td"):css("text-align", "center"):attr("colspan", colspan):wikitext(tp_costs[10 + g]):done tr:done end -- For each parameter input, add to the table for i = 1, #params do	       local tr = out_table:tag("tr") :tag("th"):wikitext(params[i][1]):done -- Loop through each item and merge identical adjacent values into a single cell local colspan = 0 local prev_value = params[i][3][1 + g] .. params[i][2] for j = 1 + g, 10 + g do if prev_value == params[i][3][j] .. params[i][2] then colspan = colspan + 1 else tr:tag("td"):css("text-align", "center"):attr("colspan", colspan):wikitext(params[i][3][j-1] .. params[i][2]):done prev_value = params[i][3][j] .. params[i][2] colspan = 1 end end tr:tag("td"):css("text-align", "center"):attr("colspan", colspan):wikitext(params[i][3][10 + g] .. params[i][2]):done tr:done end tr:done end

return out_table:done end

return p