FANDOM


m
m
(2 intermediate revisions by one user not shown)
Line 3: Line 3:
   
 
local p = {}
 
local p = {}
local getArgs = require('Module:Arguments').getArgs
+
local getArgs = require('Module:Arguments').getArgs
 
local getColor = require('Module:Color').colorByGame
 
local getColor = require('Module:Color').colorByGame
local common = require('Module:Common')
+
local common = require('Module:Common')
local stats = require('Module:CharStat/data').stats
+
local stats = require('Module:CharStat/data').stats
+
local exts = {
  +
['Holy Blood'] = '[[Holy Blood]]',
  +
['Aff'] = '[[Affinity]]',
  +
['Group'] = 'Group',
  +
['Wardrobe'] = 'Wardrobe Stats'
  +
}
 
local others = {
 
local others = {
 
{'Magic', '[[Magic]]'},
 
{'Magic', '[[Magic]]'},
Line 15: Line 15:
 
{'Item', 'Starting Items'},
 
{'Item', 'Starting Items'},
 
}
 
}
 
 
local resistances = {
 
local resistances = {
'sword', 'lance', 'axe', 'bow',
+
'sword', 'lance', 'axe' , 'bow' ,
'fire', 'ice', 'thunder', 'wind', 'light', 'dark'
+
'fire' , 'ice' , 'thunder', 'wind',
  +
'light', 'dark'
 
}
 
}
   
Line 26: Line 25:
 
return p._main(args)
 
return p._main(args)
 
else
 
else
return '[[Category:Pages with script errors]]<span style="color: red">Missing \'game\' parameter. See [[Template:CharStat]] for more info.</span>'
+
return '[[Category:Pages with script errors]]'..
  +
'<span style="color: red">Missing \'game\' parameter.'..
  +
'See [[Template:CharStat]] for more info.</span>'
 
end
 
end
 
end
 
end
   
 
function p._main(args)
 
function p._main(args)
local game = string.lower(mw.text.trim(args.game))
+
local game = string.lower(mw.text.trim(args.game))
 
local class = common.colorLinks(game)
 
local class = common.colorLinks(game)
local out, colspan, colspan1
 
local columns, col = '', ''
 
local nCols, oCols = 0, 0
 
 
local color = getColor[game]
 
local color = getColor[game]
+
local count = 0 -- section 2 column count
----------------- Char stats columns iteration -----------------
+
local cnt = 0 -- section 3 column count
-- Headers
+
local tbl = mw.html.create('table'):addClass('statbox'):css('max-width', 'initial')
  +
local th1 = mw.html.create('tr'):addClass(class):css('background', color)
  +
local td1 = mw.html.create('tr')
  +
local th2 = mw.html.create('tr'):addClass(class):css('background', color)
  +
local td2 = mw.html.create('tr'):addClass('s-cells')
  +
local th3 = mw.html.create('tr'):addClass(class):css('background', color)
  +
local td3 = mw.html.create('tr')
  +
local ext
  +
local th1_1, td1_1 -- FEH integration
  +
local th2_1, td2_1, th3_1 -- TMS integration
  +
  +
-- Section 2
 
for i = 1, #stats do
 
for i = 1, #stats do
if(common.isnotNil(args[stats[i][1]])) then
+
if common.isnotNil(args[stats[i][1]]) then
columns = columns..stats[i][3]
+
th2:tag('th'):wikitext(stats[i][3])
nCols = nCols + 1
+
td2:tag('td'):wikitext(args[stats[i][1]])
  +
count = count + 1
 
end
 
end
 
end
 
end
-- Datas
+
columns = columns..'\n|-class="s-cells"'
+
-- Section 1
for i = 1, #stats do
+
for k, v in pairs(exts) do
if(common.isnotNil(args[stats[i][1]])) then
+
if common.isnotNil(args[k]) then ext = k end
columns = columns..'\n| '..args[stats[i][1]] end
 
 
end
 
end
-- Assign colspan
+
th1 :tag('th')
colspan = nCols
+
:wikitext('Starting Class')
col = col..'\n!colspan="4" bgcolor='..color..' class='..class..'|'
+
:attr('colspan', ext and count - 4 or count)
if(common.isnotNil(args['Holy Blood'])) then
+
td1 :tag('td')
col = col..'[[Holy Blood]]'
+
:wikitext(common.setDefault(args.image))
colspan = nCols - 4
+
:attr('colspan', ext and count - 4 or count)
elseif(common.isnotNil(args['Aff'])) then
+
if ext then
col = col..'[[Affinity]]'
+
th1:tag('th'):attr('colspan', 4):wikitext(exts[ext])
colspan = nCols - 4
+
td1:tag('td'):attr('colspan', 4):wikitext(args[ext])
elseif(common.isnotNil(args['Group'])) then
 
col = col..'Group'
 
colspan = nCols - 4
 
end
 
 
 
---------------------- TOKYO MIRAGE SESSIONS ♯FE ----------------------
 
if(game == 'tms') then
 
colspan = 10
 
-------------------- Resistances -------------------
 
-- Headers
 
columns = columns..'\n|-bgcolor='..color..' class='..class
 
for i = 1, #resistances do
 
columns = columns..'\n!'..
 
mw.getCurrentFrame():expandTemplate{
 
title = 'Weapon',
 
args = { 'tms', resistances[i] }
 
}
 
end
 
 
columns = columns..'\n|-class="s-cells"'
 
-- Datas
 
for i = 1, #resistances do
 
columns = columns..'\n| '..common.setDefault(args[resistances[i]], '--')
 
end
 
 
-------------------- Skills & Items -------------------
 
columns =
 
columns..'\n|-bgcolor='..
 
color..' class='..class..
 
'\n!colspan=7| Skills'..
 
'\n!colspan=3| Items'..
 
'\n|-'..
 
'\n!colspan=3|Command'..
 
'\n!colspan=2|Session'..
 
'\n!colspan=2|Passive'..
 
'\n|colspan=3 rowspan=2|\n'..common.setDefault(args['items'], '--')..
 
'\n|-'..
 
'\n|colspan=3|\n'..common.setDefault(args['command'], '--')..
 
'\n|colspan=2|\n'..common.setDefault(args['session'], '--')..
 
'\n|colspan=2|\n'..common.setDefault(args['passive'], '--')
 
 
end
 
end
 
 
+
-- Section 3
------------------- Other columns iteration ----------------------
 
-- Assign colspan
 
local n = 0-- colspan identifier for the last column
 
 
for i = 1, #others do
 
for i = 1, #others do
if(common.isnotNil(args[others[i][1]])) then oCols = oCols + 1 end
+
if common.isnotNil(args[others[i][1]]) then cnt = cnt + 1 end
 
end
 
end
if(nCols % oCols ~= 0) then n = 1 end
 
colspan1 = nCols / oCols
 
-- Headers
 
columns = columns..'\n|-bgcolor='..color..' class='..class
 
 
for i = 1, #others do
 
for i = 1, #others do
if(common.isnotNil(args[others[i][1]])) then
+
colspan = math.floor(count / cnt)
columns = columns..'\n!colspan='..(i == #others and colspan1+n or colspan1)
+
colspan = i == #others and colspan + count % cnt or colspan
columns = columns..'|'..others[i][2]
+
if common.isnotNil(args[others[i][1]]) then
  +
th3 :tag('th')
  +
:attr('colspan', colspan)
  +
:wikitext(others[i][2])
  +
td3 :tag('td')
  +
:attr('colspan', colspan)
  +
:wikitext(args[others[i][1]])
 
end
 
end
 
end
 
end
-- Datas
+
columns = columns..'\n|-'
+
-- Spin-off integrations
for i = 1, #others do
+
if game == 'tms' then
if(common.isnotNil(args[others[i][1]])) then
+
th2_1 = mw.html.create('tr'):addClass(class):css('background', color)
columns = columns..'\n|colspan='..(i == #others and colspan1+n or colspan1)
+
td2_1 = mw.html.create('tr'):addClass('s-cells')
columns = columns..'|\n'..args[others[i][1]]
+
th3 = mw.html.create('tr'):addClass(class):css('background', color)
  +
td3 = mw.html.create('tr')
  +
th3_1 = mw.html.create('tr')
  +
for i = 1, #resistances do
  +
td2_1:tag('td'):wikitext(common.setDefault(args[resistances[i]], '--'))
  +
th2_1:tag('th'):wikitext(mw.getCurrentFrame():expandTemplate{
  +
title = 'Weapon',
  +
args = { 'tms', resistances[i] }
  +
})
 
end
 
end
  +
th3 :tag('th'):attr('colspan', 7):wikitext('Skills')
  +
th3 :tag('th'):attr('colspan', 3):wikitext('Items')
  +
th3_1:tag('th'):attr('colspan', 3):wikitext('Command')
  +
th3_1:tag('th'):attr('colspan', 2):wikitext('Session')
  +
th3_1:tag('th'):attr('colspan', 2):wikitext('Passive')
  +
td3 :tag('td'):attr('colspan', 3):wikitext(common.setDefault(args.command, '--'))
  +
td3 :tag('td'):attr('colspan', 2):wikitext(common.setDefault(args.session, '--'))
  +
td3 :tag('td'):attr('colspan', 2):wikitext(common.setDefault(args.passive, '--'))
  +
th3_1:tag('td'):attr({
  +
colspan = 3,
  +
rowspan = 2
  +
}):wikitext(common.setDefault(args.items, '--'))
  +
end
  +
if game == 'feh' then
  +
imgcol = 2
  +
image = string.gsub(common.setDefault(args.image), '<br%s*%/*>', '<br>')
  +
image = mw.text.split(image, '<br>')
  +
th1 = mw.html.create('tr')
  +
td1 = mw.html.create('tr')
  +
th1_1 = mw.html.create('tr')
  +
td1_1 = mw.html.create('tr')
  +
th1:tag('td'):attr({ colspan = imgcol, rowspan = 4 }):wikitext(image[1])
  +
th1 :tag('th')
  +
:attr('colspan', count - imgcol)
  +
:wikitext('Title')
  +
:css('background', color)
  +
:addClass(class)
  +
th1_1:tag('th')
  +
:attr('colspan', count - imgcol)
  +
:wikitext('Group')
  +
:css('background', color)
  +
:addClass(class)
  +
td1 :tag('td'):attr('colspan', count - imgcol):wikitext(image[2])
  +
td1_1:tag('td'):attr('colspan', count - imgcol):wikitext(args['Group'])
 
end
 
end
   
+
return tbl
----------------------- Final output --------------------------
+
:node(th1)
local image = common.setDefault(args['image'])
+
:node(td1)
out =
+
:node(th1_1)
'{| class="statbox" style="max-width: initial"\n|-'
+
:node(td1_1)
if (game == 'feh') then
+
:node(th2)
image = string.gsub(image, '<br/>', '<br>')
+
:node(td2)
image = string.gsub(image, '<br />', '<br>')
+
:node(th2_1)
out = out..'\n|colspan='..colspan..' rowspan=4|'..mw.text.split(image, '<br>')[1]
+
:node(td2_1)
out = out..'\n!colspan=4 bgcolor='..color..' class='..class..'|Title\n|-'
+
:node(th3)
out = out..'\n|colspan=4|'..mw.text.split(image, '<br>')[2]
+
:node(th3_1)
out = out..'\n|-'
+
:node(td3)
else
 
out = out..'\n!colspan='..colspan
 
out = out..' bgcolor='..color..' class='..class..'|Starting Class'
 
end
 
 
if (common.isnotNil(args['Holy Blood']) or
 
common.isnotNil(args['Aff']) or
 
common.isnotNil(args['Group'])) then
 
out = out..col end
 
 
if (game == 'feh') then
 
out = out..'\n|-'
 
else
 
out = out..'\n|-\n|colspan='..colspan..'| '..image
 
end
 
 
if(common.isnotNil(args['Holy Blood'])) then
 
out = out..'\n|colspan=4| '..args['Holy Blood']
 
elseif(common.isnotNil(args['Aff'])) then
 
out = out..'\n|colspan=4| '..args['Aff']
 
elseif(common.isnotNil(args['Group'])) then
 
out = out..'\n|colspan=4| '..args['Group']
 
end
 
 
out = out..
 
'\n|-bgcolor='..color..' class='..class..
 
columns..
 
'\n|}'
 
 
return out
 
 
end
 
end
   

Revision as of 08:33, June 27, 2019

--This module is invoked by Template:CharStat
--<nowiki>
 
local p = {}
local getArgs  = require('Module:Arguments').getArgs
local getColor = require('Module:Color').colorByGame
local common   = require('Module:Common')
local stats    = require('Module:CharStat/data').stats
local exts = {
    ['Holy Blood'] = '[[Holy Blood]]',
    ['Aff'] = '[[Affinity]]',
    ['Group'] = 'Group',
    ['Wardrobe'] = 'Wardrobe Stats'
}
local others = {
    {'Magic',   '[[Magic]]'},
    {'Skills',  '[[Skills]]'},
    {'Skill',   '[[Skills]]'},
    {'Weapon',  '[[Weapon Level|Weapon]]'},
    {'Item',    'Starting Items'},
}
local resistances = {
    'sword', 'lance', 'axe'    , 'bow' ,
    'fire' , 'ice'  , 'thunder', 'wind',
    'light', 'dark'
}
 
function p.main(frame)
    args = getArgs(frame)
    if(pcall(p._main, args)) then
        return p._main(args)
    else
        return '[[Category:Pages with script errors]]'..
            '<span style="color: red">Missing \'game\' parameter.'..
            'See [[Template:CharStat]] for more info.</span>'
    end
end
 
function p._main(args)
    local game  = string.lower(mw.text.trim(args.game))
    local class = common.colorLinks(game)
    local color = getColor[game]
    local count = 0 -- section 2 column count
    local cnt   = 0 -- section 3 column count
    local tbl   = mw.html.create('table'):addClass('statbox'):css('max-width', 'initial')
    local th1   = mw.html.create('tr'):addClass(class):css('background', color)
    local td1   = mw.html.create('tr')
    local th2   = mw.html.create('tr'):addClass(class):css('background', color)
    local td2   = mw.html.create('tr'):addClass('s-cells')
    local th3   = mw.html.create('tr'):addClass(class):css('background', color)
    local td3   = mw.html.create('tr')
    local ext
    local th1_1, td1_1          -- FEH integration
    local th2_1, td2_1, th3_1   -- TMS integration
 
    -- Section 2
    for i = 1, #stats do
        if common.isnotNil(args[stats[i][1]]) then
            th2:tag('th'):wikitext(stats[i][3])
            td2:tag('td'):wikitext(args[stats[i][1]])
            count = count + 1
        end
    end
 
    -- Section 1
    for k, v in pairs(exts) do
        if common.isnotNil(args[k]) then ext = k end
    end
    th1 :tag('th')
        :wikitext('Starting Class')
        :attr('colspan', ext and count - 4 or count)
    td1 :tag('td')
        :wikitext(common.setDefault(args.image))
        :attr('colspan', ext and count - 4 or count)
    if ext then
        th1:tag('th'):attr('colspan', 4):wikitext(exts[ext])
        td1:tag('td'):attr('colspan', 4):wikitext(args[ext])
    end
 
    -- Section 3
    for i = 1, #others do
        if common.isnotNil(args[others[i][1]]) then cnt = cnt + 1 end
    end
    for i = 1, #others do
        colspan = math.floor(count / cnt)
        colspan = i == #others and colspan + count % cnt or colspan
        if common.isnotNil(args[others[i][1]]) then
            th3 :tag('th')
                :attr('colspan', colspan)
                :wikitext(others[i][2])
            td3 :tag('td')
                :attr('colspan', colspan)
                :wikitext(args[others[i][1]])
        end
    end
 
    -- Spin-off integrations
    if game == 'tms' then
        th2_1 = mw.html.create('tr'):addClass(class):css('background', color)
        td2_1 = mw.html.create('tr'):addClass('s-cells')
        th3   = mw.html.create('tr'):addClass(class):css('background', color)
        td3   = mw.html.create('tr')
        th3_1 = mw.html.create('tr')
        for i = 1, #resistances do
            td2_1:tag('td'):wikitext(common.setDefault(args[resistances[i]], '--'))
            th2_1:tag('th'):wikitext(mw.getCurrentFrame():expandTemplate{
                title = 'Weapon',
                args = { 'tms', resistances[i] }
            })
        end
        th3  :tag('th'):attr('colspan', 7):wikitext('Skills')
        th3  :tag('th'):attr('colspan', 3):wikitext('Items')
        th3_1:tag('th'):attr('colspan', 3):wikitext('Command')
        th3_1:tag('th'):attr('colspan', 2):wikitext('Session')
        th3_1:tag('th'):attr('colspan', 2):wikitext('Passive')
        td3  :tag('td'):attr('colspan', 3):wikitext(common.setDefault(args.command, '--'))
        td3  :tag('td'):attr('colspan', 2):wikitext(common.setDefault(args.session, '--'))
        td3  :tag('td'):attr('colspan', 2):wikitext(common.setDefault(args.passive, '--'))
        th3_1:tag('td'):attr({
            colspan = 3,
            rowspan = 2
        }):wikitext(common.setDefault(args.items, '--'))
    end
    if game == 'feh' then
        imgcol = 2
        image = string.gsub(common.setDefault(args.image), '<br%s*%/*>', '<br>')
        image = mw.text.split(image, '<br>')
        th1   = mw.html.create('tr')
        td1   = mw.html.create('tr')
        th1_1 = mw.html.create('tr')
        td1_1 = mw.html.create('tr')
        th1:tag('td'):attr({ colspan = imgcol, rowspan = 4 }):wikitext(image[1])
        th1  :tag('th')
             :attr('colspan', count - imgcol)
             :wikitext('Title')
             :css('background', color)
             :addClass(class)
        th1_1:tag('th')
             :attr('colspan', count - imgcol)
             :wikitext('Group')
             :css('background', color)
             :addClass(class)
        td1  :tag('td'):attr('colspan', count - imgcol):wikitext(image[2])
        td1_1:tag('td'):attr('colspan', count - imgcol):wikitext(args['Group'])
    end
 
    return tbl
        :node(th1)
        :node(td1)
        :node(th1_1)
        :node(td1_1)
        :node(th2)
        :node(td2)
        :node(th2_1)
        :node(td2_1)
        :node(th3)
        :node(th3_1)
        :node(td3)
end
 
return p
--</nowiki>
--[[Category:Modules]]
Community content is available under CC-BY-SA unless otherwise noted.