Module:InfoboxProto: Difference between revisions

From Elwiki
No edit summary
Tag: Reverted
(Undo revision 898865 by Ritsu (talk))
Tag: Undo
Line 1: Line 1:
require('Module:CommonFunctions')
require('Module:CommonFunctions')
require('Module:InfoboxProto');
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local p = {}
local p = {}


-- Main process
-- Main process
function p.main(frame)
function p.main(frame, title)
     local args = getArgs(frame);
     local args = getArgs(frame);
    local infobox = require('Module:InfoboxProto').main(frame, args.class);
    infobox:addClass('infobox-character');


     if (args.name1 == nil and args.name2 == nil) then
     if args.color == nil then
         addField('name', args.l_name);
        if args['Color'] ~= nil then
            args.color = args['Color'];
        else
            args.color = '{{ColorSel|Misc}}';
        end
    end
 
    if title == nil then
        title = args.name
    end
    if title == nil then
         title = args['Name']
    end
 
    local infobox = mw.html.create('div'):addClass('infobox-new');
    infobox:tag('div'):addClass('infobox-new-header'):css('background-color', args.color:gsub("%#", "#")):wikitext(title);
    local img = args.image;
    if args.image == nil then
        img = args['Image'];
     end
     end
    infobox:tag('div'):addClass('infobox-new-image'):wikitext(img);


     local fields = {
     -- Adds a normal row
        {
    function addField(param, field_name, double, collapsed)
            id = 'name',
         field_value = args[param];
            localize = args.l_name,
         if field_value ~= nil then
            dual = true
             local row = infobox:tag('div'):addClass('infobox-row');
        },
             if field_name == nil then
         {
                field_name = titleCase(param);
            id = 'class',
             end
            localize = args.l_class
             row:tag('div'):addClass('infobox-row-title'):tag('span'):wikitext(field_name);
         },
             local content = row:tag('div'):addClass('infobox-row-content');
        {
             if (param == 'video' or param == 'tree' or param == 'stat') then
             id = 'classes',
                content:wikitext(field_value);
            localize = args.l_classes,
                if param == 'video' then
            dual = true,
                    special_row:addClass('infobox-video-row')
            special = true
                end
        },
             else
        {
                content:tag('span'):addClass('mw-collapsible mw-collapsed'):wikitext(field_value);
            id = 'weapon',
             end
             localize = args.l_weapon,
         end
            dual = true
         if double == true then
        },
             addField2(param, field_name)
        {
         end
            id = 'age',
     end
            localize = args.l_age,
             dual = true
        },
        {
             id = 'race',
            localize = args.l_race,
            dual = true
        },
        {
            id = 'Birth',
            localize = args.l_birth,
            dual = true
        },
        {
            id = 'Height',
             localize = args.l_height,
            dual = true
        },
        {
            id = 'Weight',
            localize = args.l_weight,
            dual = true
        },
        {
            id = 'Blood',
             localize = args.l_blood,
            dual = true
        },
        {
            id = 'ESP',
            localize = args.l_esp
        },
        {
            id = 'tree',
            localize = args.l_tree
        },
        {
            id = 'VA',
            localize = args.l_va,
            dual = true,
            collapsed = true
        },
        {
            id = 'RD',
            localize = args.l_rd,
            collapsed = true
        },
        {
            id = 'TRD',
            localize = args.l_trd,
             collapsed = true
        },
        {
            id = 'MRD',
            localize = args.l_mrd,
            collapsed = true
        },
        {
            id = 'theme',
             localize = args.l_theme,
            collapsed = true
         },
         {
            id = 'video',
            localize = args.l_video
        },
        {
             id = 'stat',
            localize = args.l_stat
         }
     }


     for k, v in ipairs(fields) do
     -- Adds a row with 2 columns
         if v.special then
    function addField2(param, field_name)
             addField2(v.id, v.localize)
         if args[param .. '1'] ~= nil and args[param .. '2'] ~= nil then
        else
             local row = infobox:tag('div'):addClass('infobox-row'):addClass('infobox-double-row');
             addField(v.id, v.localize, v.dual or false, v.collapsed)
            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
     end
     end
   
 
     return tostring(infobox);
     return infobox;


end
end


return p
return p

Revision as of 12:34, 8 September 2023

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

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

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

    if args.color == nil then
        if args['Color'] ~= nil then
            args.color = args['Color'];
        else
            args.color = '{{ColorSel|Misc}}';
        end
    end

    if title == nil then
        title = args.name
    end
    if title == nil then
        title = args['Name']
    end

    local infobox = mw.html.create('div'):addClass('infobox-new');
    infobox:tag('div'):addClass('infobox-new-header'):css('background-color', args.color:gsub("%#", "#")):wikitext(title);
    local img = args.image;
    if args.image == nil then
        img = args['Image'];
    end
    infobox:tag('div'):addClass('infobox-new-image'):wikitext(img);

    -- Adds a normal row
    function addField(param, field_name, double, collapsed)
        field_value = args[param];
        if field_value ~= 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'):tag('span'):wikitext(field_name);
            local content = row:tag('div'):addClass('infobox-row-content');
            if (param == 'video' or param == 'tree' or param == 'stat') then
                content:wikitext(field_value);
                if param == 'video' then
                    special_row:addClass('infobox-video-row')
                end
            else
                content:tag('span'):addClass('mw-collapsible mw-collapsed'):wikitext(field_value);
            end
        end
        if double == true then
            addField2(param, field_name)
        end
    end

    -- Adds a row with 2 columns
    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

    return infobox;

end

return p