Module:CharStat

--This module is invoked by Template:CharStat local p = {} local getArgs = require('Module:Arguments').getArgs local getColor = require('Module:Color').colorByGame local stats = { -- character stats {'Level',  '\n!Level'}, {'HP',     '\n!HP'}, {'Str',    '\n!Str'}, {'Mag',    '\n!Mag'}, {'Mnd', '\n!Mnd'}, {'Skl',    '\n!Skl'}, {'Spd',    '\n!Spd'}, {'Agl', '\n!Agl'}, {'Lck',    '\n!Lck'}, {'Def',    '\n!Def'}, {'Res',    '\n!Res'}, {'Con',    '\n!Con'}, {'Bld', '\n!Bld'}, {'Wt',     '\n!Wt'}, {'Wlv',    '\n!Wlv'}, {'Move',   '\n!Mov'}, {'Lead',   '\n!Lead'}, {'LS', '\n!LS'}, {'MS',     '\n!MS'}, {'PC',     '\n!PC'}, {'Gold',   '\n!Gold'} }

local others = { {'Magic',  'Magic'}, {'Weapon', 'Weapon'}, {'Skills', 'Skills'}, {'Skill',  'Skills'}, {'Item',   'Starting Items'}, }

-- Helper functions function setDefault(arg) if(arg == nil) then return '' else return arg end end

function check(arg) if(arg == nil) then return false else return true end end

function p.main(frame) args = getArgs(frame) if(pcall(p._main, args)) then return p._main(args) else return ' Missing \'game\' parameter. See Template:CharStat for more info. '   end end

function p._main(args) local game = string.lower(args.game) local out, colspan, colspan1, colspan2, colspan3 local class, columns, col = , , '' local nCols, oCols = 0, 0 local color = getColor[game]

if (game=='fe6' or game=='fe8' or game=='fe9' or game=='fe12' or game=='fe13' or game=='fe14') then class = 'light' end -- Char stats columns iteration -- Headers for i = 1, #stats do       if(check(args[stats[i][1]])) then columns = columns..stats[i][2] nCols = nCols + 1 end end -- Datas columns = columns..'\n|-' for i = 1, #stats do       if(check(args[stats[i][1]])) then columns = columns..'\n| '..args[stats[i][1]] end end -- Assign colspan colspan = nCols if(check(args['Holy Blood'])) then col = col..'\n!colspan="4"|Holy Blood' colspan = nCols - 4 elseif(check(args['Aff'])) then col = col..'\n!colspan="4"|Affinity' colspan = nCols - 4 end

--- Other columns iteration -- Headers columns = columns..'\n|-bgcolor='..color..' class='..class for i = 1, #others do       if(check(args[others[i][1]])) then oCols = oCols + 1 colspan1 = nCols / oCols end end for i = 1, #others do       if(check(args[others[i][1]])) then columns = columns.. '\n!colspan='..colspan1.. '|'..others[i][2] end end -- Datas columns = columns..'\n|-' for i = 1, #others do       if(check(args[others[i][1]])) then columns = columns.. '\n|colspan='..colspan1.. '| '..args[others[i][1]] end end

--- Final output out = '{| border=1 style="text-align: center; min-width: 40%"'.. '\n|-bgcolor='..color..' class='..class.. '\n!colspan='..colspan..'|Starting Class' if(check(args['Holy Blood']) or check(args['Aff'])) then out = out..col end out = out..'\n|-\n|colspan='..colspan..'| '..setDefault(args['image']) if(check(args['Holy Blood'])) then out = out..'\n|colspan="4"| '..args['Holy Blood'] elseif(check(args['Aff'])) then out = out..'\n|colspan="4"| '..args['Aff'] end out = out.. '\n|-bgcolor='..color..' class='..class.. columns.. '\n|}' return out end

return p --