Please join this new Discord server!
Difference between revisions of "Module:SkillTable"
From Etrian Odyssey Wiki
(Merge adjacent identical cells) |
m (Moydow moved page Module:SkillTable EO5 to Module:SkillTable without leaving a redirect: Can probably be reused for most other games) |
(No difference)
|
Revision as of 23:29, 10 December 2018
Documentation for this module may be created at Module:SkillTable/doc
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
-- 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")
-- If the skill doesn't have 10 levels, make the table narrower, it looks better this way
:addClass("wikitable"):css("width", math.max(80 / (10 / max_lv), 40) .. "%")
:tag("tr")
:tag("th"):attr("colspan", max_lv + 1):wikitext(frame.args["skill_name"]):done()
:done()
:tag("td"):attr("colspan", max_lv + 1):wikitext(frame.args["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