Module:SkillTable

local p = {}

function p.skill_table(frame) -- Adds anchors for linking local skill_name = " " .. frame.args["skill_name"] -- 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 additional notes to skill description if frame.args["desc_notes"] ~= "" then skill_desc = skill_desc .. "\n" .. frame.args["desc_notes"] .. "\n" end -- Add body parts/stats used to skill description if frame.args["body_parts"] ~= "" then skill_desc = skill_desc .. "\n* Body part used: " .. frame.args["body_parts"] .. "\n" end if frame.args["skill_stats"] ~= "" then skill_desc = skill_desc .. "\n* Stat(s) used: " .. frame.args["skill_stats"] .. "\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 .. "\nPrerequisite skill(s):" .. prereq_data end -- Split up skill parameter input and convert to a table for easier usage params = {} for i = 1, 8 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") -- If the skill doesn't have 10 levels, make the table narrower, it looks better this way :addClass("wikitable"):css("width", math.min(math.max(100 / (10 / max_lv), 75), 100) .. "%") :tag("tr") :tag("th"):attr("colspan", max_lv + 1):wikitext(skill_name):done :done :tag("td"):attr("colspan", max_lv + 1):wikitext(skill_desc):done :done:tag("tr") :tag("th"):css("width", "20%"):wikitext("Level"):done

-- Add level headings for i = 1, max_lv do       out_table:tag("th"):css("width", (80 / max_lv) .."%"):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] for i = 1, max_lv 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[max_lv]):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] .. params[i][2] for j = 1, max_lv 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][max_lv] .. params[i][2]):done tr:done end

return out_table:done end

return p