Module:SkillTable: Difference between revisions
From Little Tail Wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
function p.main(frame) | function p.main(frame) | ||
local args = frame.args | local args = frame:getParent().args | ||
local skills = {} | local skills = {} | ||
local i = 1 | local i = 1 |
Latest revision as of 15:58, 13 March 2025
Documentation for this module may be created at Module:SkillTable/doc
local p = {}
function p.main(frame)
local args = frame:getParent().args
local skills = {}
local i = 1
-- Get colors via template
local bg = frame:expandTemplate{title = "Color", args = {args.color or "#b06767"}}
local bg2 = frame:expandTemplate{title = "Color", args = {args.color2 or "#9199a6"}}
-- Extract skills
while args["skill"..i] do
skills[i] = {
name = args["skill"..i],
sp = args["sp"..i],
levels = {}
}
local j = 1
while args["skill"..i.."_level"..j] do
skills[i].levels[j] = {
level = args["skill"..i.."_level"..j],
effect = args["skill"..i.."_effect"..j],
acquire = args["skill"..i.."_acquire"..j]
}
j = j + 1
end
i = i + 1
end
-- Build table
local rows = {
'{| class="wikitable" style="border-collapse: collapse;"',
string.format('! style="background: %s; border: 1px solid black; padding: 5px;" | Name', bg),
string.format('! style="background: %s; border: 1px solid black; padding: 5px;" | SP Cost', bg),
string.format('! style="background: %s; border: 1px solid black; padding: 5px;" | Level', bg),
string.format('! style="background: %s; border: 1px solid black; padding: 5px;" | Effect', bg),
string.format('! style="background: %s; border: 1px solid black; padding: 5px;" | Acquire', bg)
}
for _, skill in ipairs(skills) do
table.insert(rows, string.format(
'|-\n| rowspan="%d" style="background: %s; border: 1px solid black; padding: 5px;" | %s\n| rowspan="%d" style="background: %s; border: 1px solid black; padding: 5px;" | %s',
#skill.levels, bg2, skill.name,
#skill.levels, bg2, skill.sp
))
for idx, lvl in ipairs(skill.levels) do
if idx > 1 then table.insert(rows, "|-") end
table.insert(rows, string.format(
'| style="background: %s; border: 1px solid black; padding: 5px;" | %s\n| style="background: %s; border: 1px solid black; padding: 5px;" | %s\n| style="background: %s; border: 1px solid black; padding: 5px;" | %s',
bg2, lvl.level,
bg2, lvl.effect,
bg2, lvl.acquire
))
end
end
table.insert(rows, "|}")
return table.concat(rows, "\n")
end
return p