Module:InfoboxCharacter

From Elwiki
Revision as of 21:00, 28 April 2022 by Ritsu (talk | contribs) (Created page with "require('Module:CommonFunctions') local getArgs = require('Module:Arguments').getArgs local p = {} -- Main process function p.main(frame) local args = getArgs(frame);...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:InfoboxCharacter/doc

require('Module:CommonFunctions')
local getArgs = require('Module:Arguments').getArgs
local p = {}

-- Main process
function p.main(frame)
    local args = getArgs(frame);

    if args.textcolor == nil then
        args.textcolor = 'white';
    else
        args.textcolor = 'black';
    end

    if args.fullname == nil then
        args.fullname = args.name;
    end

    local infobox = mw.html.create('div'):addClass('infobox-character');
    infobox:tag('div'):addClass('infobox-character-header'):css('background-color', args.color:gsub("%#", "#")):css(
        'color', args.textcolor):wikitext(args.name);
    infobox:tag('div'):addClass('infobox-character-image'):wikitext(args.image);

    function addField(param, field_name)
        if args[param] ~= nil then
            local row = infobox:tag('div'):addClass('infobox-row');
            if field_name == nil then
                field_name = titleCase(param);
            end
            row:tag('div'):addClass('infobox-row-title'):wikitext(field_name);
            if (param == 'video' or param == 'tree' or param == 'stats') then
                row:tag('div'):addClass('infobox-row-content'):wikitext(args[param]);
            else
                row:tag('div'):addClass('infobox-row-content'):tag('span'):wikitext(args[param]);
            end
        end
    end

    function addField2(param, field_name)
        if args[param .. '1'] ~= nil and args[param .. '2'] ~= nil then
            local row = infobox:tag('div'):addClass('infobox-row'):addClass('infobox-double-row');
            if field_name == nil then
                field_name = titleCase(param):gsub("%d+", '');
            end
            row:tag('div'):addClass('infobox-row-title'):wikitext(field_name);
            row:tag('div'):addClass('infobox-row-content'):tag('span'):wikitext(args[param .. '1']);
            row:tag('div'):addClass('infobox-row-content'):tag('span'):wikitext(args[param .. '2']);
        end
    end

    if args.classes1 == nil and args.classes2 == nil then
        addField('fullname', 'Full Name');
    end
    addField2('fullname', 'Full Name');
    addField('class');
    addField2('classes', 'Classes');
    addField('weapon');
    addField2('weapon');
    addField('age');
    addField2('age');
    addField('race');
    addField2('race');
    addField('Birth');
    addField2('Birth');
    addField('Height');
    addField2('Height');
    addField('Weight');
    addField2('Weight');
    addField('Blood', 'Blood Type');
    addField2('Blood', 'Blood Type');
    addField('ESP', '[[El Search Party Collection|ESP Collection]]');
    addField('tree', 'Class Tree');
    addField('VA', 'Voice Actors');
    addField2('VA', 'Voice Actors');
    addField('RD', 'Release Date');
    addField('TRD', 'Transcendence Release Date');
    addField('MRD', 'Master Class Release Date');
    addField('theme');
    addField('video', 'Job Path Story Movie');
    addField('stat', 'Statistics');
    
    return frame:preprocess(tostring(infobox));

end

return p