Module:Traits: Difference between revisions
From Elwiki
No edit summary Tag: Reverted |
Tag: Undo |
||
Line 29: | Line 29: | ||
end | end | ||
local desc = {} | local desc = { | ||
[1] = {}, | |||
[2] = {} | |||
} | |||
-- Extra effects | -- Extra effects | ||
local counts = {} | local counts = {} | ||
local desc_arg = nil; | local desc_arg = nil; | ||
local header_data = {} | local header_data = { | ||
[1] = {}, | |||
[2] = {} | |||
} | |||
for i = 1, 2, 1 do | for i = 1, 2, 1 do | ||
if (i == 1) then | if (i == 1) then | ||
Line 47: | Line 53: | ||
if desc_arg ~= nil then | if desc_arg ~= nil then | ||
local headers = split(desc_arg, ';')[1]; | |||
local | local data = split(desc_arg, ';')[2]; | ||
headers = split(headers); | |||
for k, v in spairs(headers) do | for k, v in spairs(headers) do | ||
table.insert(header_data[i], v) | table.insert(header_data[i], v) | ||
end | end | ||
Line 83: | Line 66: | ||
local index = 1 | local index = 1 | ||
while index <= #headers do | while index <= #headers do | ||
desc[i | desc[i][headers[index]] = data[index] | ||
index = index + 1 | index = index + 1 | ||
end | end | ||
Line 118: | Line 99: | ||
thead:tag('th'):attr('colspan', counts[1]):wikitext(traits[1] .. ' ' .. skill) | thead:tag('th'):attr('colspan', counts[1]):wikitext(traits[1] .. ' ' .. skill) | ||
thead:tag('th'):attr('colspan', counts[2]):wikitext(traits[2] .. ' ' .. skill) | thead:tag('th'):attr('colspan', counts[2]):wikitext(traits[2] .. ' ' .. skill) | ||
local tr_2 = newtr(); | local tr_2 = newtr(); | ||
for i = 1, 2, 1 do | for i = 1, 2, 1 do | ||
tr_2:tag('th'):wikitext('Attribute Effect') | tr_2:tag('th'):wikitext('Attribute Effect') | ||
if | if (args['effects' .. i] ~= nil) then | ||
for k, v in | for k, v in spairs(header_data[i]) do | ||
v = frame:preprocess(v); | v = frame:preprocess(v); | ||
tr_2:tag('th'):wikitext(v) | tr_2:tag('th'):wikitext(v) | ||
Line 136: | Line 114: | ||
local tr = trait_table:tag('tr') | local tr = trait_table:tag('tr') | ||
for i = 1, 2, 1 do | for i = 1, 2, 1 do | ||
tr:tag('td'):wikitext(frame:expandTemplate{ | tr:tag('td'):wikitext(frame:expandTemplate{ | ||
title = 'SkillText', | title = 'SkillText', | ||
args = {traits[i], effects[i][1], effects[i][2]} | args = {traits[i], effects[i][1], effects[i][2]} | ||
}) | }) | ||
for k, v in pairs(desc[i]) do | |||
tr:tag('td'):wikitext(frame:preprocess(v)) | |||
end | end | ||
end | end |
Revision as of 14:38, 24 August 2022
Documentation for this module may be created at Module:Traits/doc
require('Module:CommonFunctions')
local getArgs = require('Module:Arguments').getArgs
local p = {}
-- Main process
function p.main(frame)
local args = getArgs(frame);
-- Argument init
local traits = args[3]
if (traits == nil) then
traits = '-, -'
end
traits = split(traits);
local skill = args[2]
-- Attribute effect
local effects = {
[1] = {},
[2] = {}
}
args.effects1 = args.effects1 or args[4]
args.effects2 = args.effects2 or args[5]
if args.effects1 ~= nil then
effects[1] = split(args.effects1)
end
if args.effects2 ~= nil then
effects[2] = split(args.effects2)
end
local desc = {
[1] = {},
[2] = {}
}
-- Extra effects
local counts = {}
local desc_arg = nil;
local header_data = {
[1] = {},
[2] = {}
}
for i = 1, 2, 1 do
if (i == 1) then
desc_arg = args[6]
else
desc_arg = args[7]
end
if desc_arg == nil then
desc_arg = args['desc' .. i]
end
if desc_arg ~= nil then
local headers = split(desc_arg, ';')[1];
local data = split(desc_arg, ';')[2];
headers = split(headers);
for k, v in spairs(headers) do
table.insert(header_data[i], v)
end
data = split(data);
counts[i] = 1 + #headers;
local index = 1
while index <= #headers do
desc[i][headers[index]] = data[index]
index = index + 1
end
end
end
-- Main block
local trait_table = mw.html.create('table'):attr({
['cellpadding'] = '5',
['border'] = '1'
}):css({
['border-collapse'] = 'collapse',
['text-align'] = 'center'
})
-- Get table head color
local function color(char)
char = char or args[1]
return frame:expandTemplate{
title = 'ColorSel',
args = {'CharLight', char}
}:gsub("#", "#")
end
function newtr()
return trait_table:tag('tr'):css('background-color', color())
end
-- Spawn headers
local thead = newtr()
thead:tag('th'):attr('colspan', counts[1]):wikitext(traits[1] .. ' ' .. skill)
thead:tag('th'):attr('colspan', counts[2]):wikitext(traits[2] .. ' ' .. skill)
local tr_2 = newtr();
for i = 1, 2, 1 do
tr_2:tag('th'):wikitext('Attribute Effect')
if (args['effects' .. i] ~= nil) then
for k, v in spairs(header_data[i]) do
v = frame:preprocess(v);
tr_2:tag('th'):wikitext(v)
end
end
end
-- Spawn information
local tr = trait_table:tag('tr')
for i = 1, 2, 1 do
tr:tag('td'):wikitext(frame:expandTemplate{
title = 'SkillText',
args = {traits[i], effects[i][1], effects[i][2]}
})
for k, v in pairs(desc[i]) do
tr:tag('td'):wikitext(frame:preprocess(v))
end
end
-- Output point
return tostring(trait_table);
end
return p