Module:SkillNav: Difference between revisions

From Elwiki
m (Protected "Module:SkillNav": Easily broken pages ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
No edit summary
Line 15: Line 15:


     -- Prepare a table of skill types to display in the navigation.
     -- Prepare a table of skill types to display in the navigation.
     local skill_types = {
     local skill_types;
        [1] = {
    if (args.forcenav == nil) then
            ['name'] = 'Hyper Active',
        skill_types = {
            ['abbr'] = 'HA'
            [1] = {
        },
                ['name'] = args.l_hyper, -- 'Hyper Active',
        [2] = {
                ['abbr'] = 'HA'
            ['name'] = 'Secret Art',
            },
            ['abbr'] = 'SeA'
            [2] = {
        },
                ['name'] = args.l_secret, -- 'Secret Art',
        [3] = {
                ['abbr'] = 'SeA'
            ['name'] = 'Special Active',
            },
            ['abbr'] = 'SA'
            [3] = {
        },
                ['name'] = args.l_special, -- 'Special Active',
        [4] = {
                ['abbr'] = 'SA'
            ['name'] = 'Active',
            },
            ['abbr'] = 'A'
            [4] = {
        },
                ['name'] = args.l_active, -- 'Active',
        [5] = {
                ['abbr'] = 'A'
            ['name'] = 'Force Mod',
            },
            ['abbr'] = 'FC'
            [5] = {
        },
                ['name'] = args.l_mod, -- 'Force Mod',
        [6] = {
                ['abbr'] = 'FC'
            ['name'] = 'Buff',
            },
            ['abbr'] = 'B'
            [6] = {
        },
                ['name'] = args.l_buff, -- 'Buff',
        [7] = {
                ['abbr'] = 'B'
            ['name'] = 'Passive',
            },
            ['abbr'] = 'P'
            [7] = {
        },
                ['name'] = args.l_passive, -- 'Passive',
        [8] = {
                ['abbr'] = 'P'
            ['name'] = 'Manic Demon',
            },
            ['abbr'] = 'MD'
            [8] = {
        },
                ['name'] = args.l_demon, -- 'Manic Demon',
        [9] = {
                ['abbr'] = 'MD'
            ['name'] = '[[File:ForceIcon.png|16px]] Manic Demon',
            },
            ['abbr'] = 'MDF'
            [9] = {
        },
                ['name'] = '[[File:ForceIcon.png|16px]] ' .. args.l_demon, -- 'Manic Demon',
        [10] = {
                ['abbr'] = 'MDF'
            ['name'] = 'Master Skill',
            },
            ['abbr'] = 'MS'
            [10] = {
        },
                ['name'] = args.l_master, -- 'Master Skill',
        [11] = {
                ['abbr'] = 'MS'
            ['name'] = 'Couple Skill',
            },
            ['abbr'] = 'Wed'
            [11] = {
         },
                ['name'] = args.l_couple, -- 'Couple Skill',
         -- Force Skill Nav
                ['abbr'] = 'Wed'
         [12] = {
            }
            ['name'] = 'Force Active',
         }
            ['abbr'] = 'FA3',
    else
            ['type'] = 'third'
         -- Force Nav called, change skill types
        },
         skill_types = {
        [13] = {
            [1] = {
            ['name'] = 'Force Passive',
                ['name'] = args.l_force_active, -- 'Force Active',
            ['abbr'] = 'FP3',
                ['abbr'] = 'FA3',
            ['type'] = 'third'
                ['type'] = 'third'
        },
            },
        [14] = {
            [2] = {
            ['name'] = 'Force Active',
                ['name'] = args.l_force_passive, -- 'Force Passive',
            ['abbr'] = 'FAM',
                ['abbr'] = 'FP3',
            ['type'] = 'master'
                ['type'] = 'third'
        },
            },
        [15] = {
            [3] = {
            ['name'] = 'Force Passive',
                ['name'] = args.l_force_active, -- 'Force Active',
            ['abbr'] = 'FPM',
                ['abbr'] = 'FAM',
            ['type'] = 'master'
                ['type'] = 'master'
            },
            [4] = {
                ['name'] = args.l_force_passive, -- 'Force Passive',
                ['abbr'] = 'FPM',
                ['type'] = 'master'
            }
         }
         }
     }
     end
   


     -- For backward compatibility. Do not remove until all pages are changed.
     -- For backward compatibility. Do not remove until all pages are changed.
Line 87: Line 94:
         args.name = args.Name;
         args.name = args.Name;
     end
     end
     -- Needed this to make a custom toggle.
     -- Needed this to make a custom toggle.
     local char_name_sanitized = '';
     local char_name_sanitized = '';
     for w in args.name:gmatch("%w+") do
     for w in args.name:gmatch("%w+") do
Line 109: Line 116:
         colors = args.color;
         colors = args.color;
     end
     end
    -- Redirect to language subpages if provided.
    local is_localized = args.lang ~= nil;
    local lang_suffix = '';
    if (is_localized) then
        lang_suffix = '/' .. args.lang;
    end
     header:attr('style', 'background-color:' .. colors)
     header:attr('style', 'background-color:' .. colors)
     if (args.forcenav == nil) then
     if (args.forcenav == nil) then
Line 116: Line 131:
                 args.char,
                 args.char,
                 args.pic,
                 args.pic,
                 link = args.name,
                 link = args.name .. lang_suffix,
                 scale = '0.75'
                 scale = '0.75'
             }
             }
Line 122: Line 137:
     end
     end
     -- Header text with a link
     -- Header text with a link
    if (args.l_name == nil) then
        args.l_name = args.name;
    end
     if (args.forcenav == nil) then
     if (args.forcenav == nil) then
         header:tag('span'):wikitext('[[' .. args.name .. ']] - Skills');
         header:tag('span'):wikitext('[[' .. args.name .. lang_suffix .. '|' .. args.l_name .. ']] - ' .. args.l_skills);
     else
     else
         header:tag('span'):wikitext(args.name);
         header:tag('span'):wikitext(args.name);
     end
     end
   
 
     -- Generate the navigation's body
     -- Generate the navigation's body
     local skill_nav_wrap = skill_nav:tag('div'):addClass('skill-nav-inner-wrap border-color')
     local skill_nav_wrap = skill_nav:tag('div'):addClass('skill-nav-inner-wrap border-color')
Line 145: Line 163:
         local type = v2['type'];
         local type = v2['type'];
         if (inArgs(abbr)) then
         if (inArgs(abbr)) then
            -- Syntax: [image.extension]; [name]; [image.extension]; [name]; (...)
             local skills = split(args[abbr], ';');
             local skills = split(args[abbr], ';');
             if (abbr == 'Wed') then
             if (abbr == 'Wed') then
                 skills = {'CSZE.png', 'Extreme Heavenly Love'}
                 skills = {'CSZE.png', args.l_couple_skill_name}
             end
             end
             -- Separate syntax for Master Skills: [Stage 1 image]; [Stage 2 image]; [Stage 3 image]; [Stage 4 image]; [skill name];
             -- Separate syntax for Master Skills: [Stage 1 image]; [Stage 2 image]; [Stage 3 image]; [Stage 4 image]; [skill name];
Line 154: Line 173:
             if (abbr == 'MS') then
             if (abbr == 'MS') then
                 mc_skill_name = skills[5];
                 mc_skill_name = skills[5];
                 mc_skill_name_head = '<br/>- ' .. mc_skill_name;
                local l_mc_skill_name = skills[5];
                if (args.l_mc_skill_name ~= nil and is_localized) then
                    l_mc_skill_name = args.l_mc_skill_name;
                end
                 mc_skill_name_head = '<br/>- ' .. l_mc_skill_name;
                 skills[7] = skills[4];
                 skills[7] = skills[4];
                 skills[5] = skills[3];
                 skills[5] = skills[3];
                 skills[3] = skills[2];
                 skills[3] = skills[2];
                 skills[8] = mc_skill_name .. '/Stage 4|Stage 4';
                 skills[8] = mc_skill_name .. '/Stage 4' .. lang_suffix .. '|' .. args.l_stage .. ' 4';
                 skills[6] = mc_skill_name .. '/Stage 3|Stage 3';
                 skills[6] = mc_skill_name .. '/Stage 3' .. lang_suffix .. '|' .. args.l_stage .. ' 3';
                 skills[4] = mc_skill_name .. '/Stage 2|Stage 2';
                 skills[4] = mc_skill_name .. '/Stage 2' .. lang_suffix .. '|' .. args.l_stage .. ' 2';
                 skills[2] = mc_skill_name .. '/Stage 1|Stage 1';
                 skills[2] = mc_skill_name .. '/Stage 1' .. lang_suffix .. '|' .. args.l_stage .. ' 1';
             end
             end
             local i = 1;
             local i = 1;
Line 170: Line 193:
                     'skill-nav-sub-head skill-nav-extra-head border-color tone-7 color-normal-force-link');
                     'skill-nav-sub-head skill-nav-extra-head border-color tone-7 color-normal-force-link');
                 if (type == 'third') then
                 if (type == 'third') then
                     extra_head:wikitext('[[3rd Jobs|3rd Job]]');
                     extra_head:wikitext('[[3rd Jobs' .. lang_suffix .. '|' .. args.l_third_job .. ']]');
                 elseif (type == 'master') then
                 elseif (type == 'master') then
                     extra_head:wikitext('[[Master Class]]');
                     extra_head:wikitext('[[Master Class' .. lang_suffix .. '|' .. args.l_master_class .. ']]');
                 end
                 end
             end
             end
Line 178: Line 201:
             -- Append header fields on the left.
             -- Append header fields on the left.
             skill_nav_wrap:tag('div'):addClass('skill-nav-sub-head border-color tone-4'):wikitext(name .. mc_skill_name_head);
             skill_nav_wrap:tag('div'):addClass('skill-nav-sub-head border-color tone-4'):wikitext(name .. mc_skill_name_head);
            -- Get localized names
            local l_display_names = nil;
            if (abbr ~= 'MS' and args['l_' .. abbr] ~= nil) then
                l_display_names = split(args['l_' .. abbr], ";");
            end


             -- Append skill fields on the right.
             -- Append skill fields on the right.
Line 185: Line 214:
                     return
                     return
                 end
                 end
                -- Remove stuff like (Elesis) or (Elsword) in skill display name
                local v_display_name = v:gsub("%s%(%w+%)", "");
                 -- Fetch skills every 2 table elements, since we don't want doubles.
                 -- Fetch skills every 2 table elements, since we don't want doubles.
                 if (i % 2 == 0) then
                 if (i % 2 == 0) then
                    -- The display name of skills
                    local v_display_name = v;
                    if (is_localized and abbr ~= 'MS' and l_display_names ~= nil) then
                        v_display_name = l_display_names[i / 2];
                    end
                    -- Remove stuff like (Elesis) or (Elsword) in skill display name
                    v_display_name = v_display_name:gsub("%s%(%w+%)", "");
                     -- Append the actual skills.
                     -- Append the actual skills.
                     local skill_entry = content:tag('div'):addClass(
                     local skill_entry = content:tag('div'):addClass(
Line 195: Line 230:
                     if (abbr == 'FC' or abbr == 'MDF') then
                     if (abbr == 'FC' or abbr == 'MDF') then
                         -- [Mod] case
                         -- [Mod] case
                         skill_entry:wikitext('[[' .. v .. '/ModA|' .. v_display_name .. ']]');
                         skill_entry:wikitext('[[' .. v .. '/ModA' .. lang_suffix .. '|' .. v_display_name .. ']]');
                         skill_icon:wikitext(frame:expandTemplate{
                         skill_icon:wikitext(frame:expandTemplate{
                             title = 'Force',
                             title = 'Force',
Line 201: Line 236:
                                 trim(skills[i - 1]), -- closest smaller odd element will be the icon
                                 trim(skills[i - 1]), -- closest smaller odd element will be the icon
                                 link = v,
                                 link = v,
                                language = args.lang,
                                 size = '3'
                                 size = '3'
                             }
                             }
Line 210: Line 246:
                             skill_entry:wikitext('[[' .. v_display_name .. ']]');
                             skill_entry:wikitext('[[' .. v_display_name .. ']]');
                         else
                         else
                             skill_entry:wikitext('[[' .. v .. '|' .. v_display_name .. ']]');
                             skill_entry:wikitext('[[' .. v .. lang_suffix .. '|' .. v_display_name .. ']]');
                         end
                         end


                         skill_icon:wikitext('[[File:' .. trim(skills[i - 1]) .. '|30px|link= ' .. v .. ']]');
                         skill_icon:wikitext('[[File:' .. trim(skills[i - 1]) .. '|30px|link= ' .. v .. lang_suffix ..
                                                ']]');
                     end
                     end
                 end
                 end
Line 225: Line 262:
     if (args.FS == 'true') then
     if (args.FS == 'true') then
         force_nav = frame:expandTemplate{
         force_nav = frame:expandTemplate{
             title = 'ForceSkillNav',
             title = 'ForceSkillNav' .. lang_suffix,
             args = {
             args = {
                 type = 'mw-collapsible mw-collapsed',
                 type = 'mw-collapsible mw-collapsed',

Revision as of 19:06, 17 June 2022

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

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

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

    -- Making life easier.
    function inArgs(name)
        if (inArray(name, args)) then
            return true
        end
    end

    -- Prepare a table of skill types to display in the navigation.
    local skill_types;
    if (args.forcenav == nil) then
        skill_types = {
            [1] = {
                ['name'] = args.l_hyper, -- 'Hyper Active',
                ['abbr'] = 'HA'
            },
            [2] = {
                ['name'] = args.l_secret, -- 'Secret Art',
                ['abbr'] = 'SeA'
            },
            [3] = {
                ['name'] = args.l_special, -- 'Special Active',
                ['abbr'] = 'SA'
            },
            [4] = {
                ['name'] = args.l_active, -- 'Active',
                ['abbr'] = 'A'
            },
            [5] = {
                ['name'] = args.l_mod, -- 'Force Mod',
                ['abbr'] = 'FC'
            },
            [6] = {
                ['name'] = args.l_buff, -- 'Buff',
                ['abbr'] = 'B'
            },
            [7] = {
                ['name'] = args.l_passive, -- 'Passive',
                ['abbr'] = 'P'
            },
            [8] = {
                ['name'] = args.l_demon, -- 'Manic Demon',
                ['abbr'] = 'MD'
            },
            [9] = {
                ['name'] = '[[File:ForceIcon.png|16px]] ' .. args.l_demon, -- 'Manic Demon',
                ['abbr'] = 'MDF'
            },
            [10] = {
                ['name'] = args.l_master, -- 'Master Skill',
                ['abbr'] = 'MS'
            },
            [11] = {
                ['name'] = args.l_couple, -- 'Couple Skill',
                ['abbr'] = 'Wed'
            }
        }
    else
        -- Force Nav called, change skill types
        skill_types = {
            [1] = {
                ['name'] = args.l_force_active, -- 'Force Active',
                ['abbr'] = 'FA3',
                ['type'] = 'third'
            },
            [2] = {
                ['name'] = args.l_force_passive, -- 'Force Passive',
                ['abbr'] = 'FP3',
                ['type'] = 'third'
            },
            [3] = {
                ['name'] = args.l_force_active, -- 'Force Active',
                ['abbr'] = 'FAM',
                ['type'] = 'master'
            },
            [4] = {
                ['name'] = args.l_force_passive, -- 'Force Passive',
                ['abbr'] = 'FPM',
                ['type'] = 'master'
            }
        }
    end
    

    -- For backward compatibility. Do not remove until all pages are changed.
    if (args.name == nil) then
        args.name = args.Name;
    end

    -- Needed this to make a custom toggle.
    local char_name_sanitized = '';
    for w in args.name:gmatch("%w+") do
        char_name_sanitized = char_name_sanitized .. w;
    end

    -- Main block
    local skill_nav = mw.html.create('div'):addClass('skill-nav');
    if (args.forcenav ~= nil) then
        skill_nav:addClass('force-nav');
    end

    -- Header
    local header = skill_nav:tag('div'):addClass('skill-nav-header');
    local colors = frame:expandTemplate{
        title = 'ColorSel',
        args = {'Character', args.char}
    };
    if (args.color ~= nil) then
        colors = args.color;
    end

    -- Redirect to language subpages if provided.
    local is_localized = args.lang ~= nil;
    local lang_suffix = '';
    if (is_localized) then
        lang_suffix = '/' .. args.lang;
    end

    header:attr('style', 'background-color:' .. colors)
    if (args.forcenav == nil) then
        header:wikitext(frame:expandTemplate{
            title = 'Face',
            args = {
                args.char,
                args.pic,
                link = args.name .. lang_suffix,
                scale = '0.75'
            }
        })
    end
    -- Header text with a link
    if (args.l_name == nil) then
        args.l_name = args.name;
    end
    if (args.forcenav == nil) then
        header:tag('span'):wikitext('[[' .. args.name .. lang_suffix .. '|' .. args.l_name .. ']] - ' .. args.l_skills);
    else
        header:tag('span'):wikitext(args.name);
    end

    -- Generate the navigation's body
    local skill_nav_wrap = skill_nav:tag('div'):addClass('skill-nav-inner-wrap border-color')
    if (args.type ~= nil) then
        skill_nav_wrap:addClass(args.type);
    end
    -- Make it collapsible if needed.
    if (args.type ~= nil and string.find(args.type, 'mw%-collapsible') ~= nil) then
        skill_nav_wrap:attr('id', 'mw-customcollapsible-' .. char_name_sanitized);
        header:tag('div'):addClass('mw-customtoggle-' .. char_name_sanitized);
    end

    -- Generate the navigation's body content.
    for k2, v2 in spairs(skill_types) do
        local name = v2['name'];
        local abbr = v2['abbr'];
        local type = v2['type'];
        if (inArgs(abbr)) then
            -- Syntax: [image.extension]; [name]; [image.extension]; [name]; (...)
            local skills = split(args[abbr], ';');
            if (abbr == 'Wed') then
                skills = {'CSZE.png', args.l_couple_skill_name}
            end
            -- Separate syntax for Master Skills: [Stage 1 image]; [Stage 2 image]; [Stage 3 image]; [Stage 4 image]; [skill name];
            local mc_skill_name = ''
            local mc_skill_name_head = ''
            if (abbr == 'MS') then
                mc_skill_name = skills[5];
                local l_mc_skill_name = skills[5];
                if (args.l_mc_skill_name ~= nil and is_localized) then
                    l_mc_skill_name = args.l_mc_skill_name;
                end
                mc_skill_name_head = '<br/>- ' .. l_mc_skill_name;
                skills[7] = skills[4];
                skills[5] = skills[3];
                skills[3] = skills[2];
                skills[8] = mc_skill_name .. '/Stage 4' .. lang_suffix .. '|' .. args.l_stage .. ' 4';
                skills[6] = mc_skill_name .. '/Stage 3' .. lang_suffix .. '|' .. args.l_stage .. ' 3';
                skills[4] = mc_skill_name .. '/Stage 2' .. lang_suffix .. '|' .. args.l_stage .. ' 2';
                skills[2] = mc_skill_name .. '/Stage 1' .. lang_suffix .. '|' .. args.l_stage .. ' 1';
            end
            local i = 1;

            -- If Force Nav, append an extra header before "Force Active" if needed.
            if (abbr == 'FA3' or abbr == 'FAM') then
                local extra_head = skill_nav_wrap:tag('div'):addClass(
                    'skill-nav-sub-head skill-nav-extra-head border-color tone-7 color-normal-force-link');
                if (type == 'third') then
                    extra_head:wikitext('[[3rd Jobs' .. lang_suffix .. '|' .. args.l_third_job .. ']]');
                elseif (type == 'master') then
                    extra_head:wikitext('[[Master Class' .. lang_suffix .. '|' .. args.l_master_class .. ']]');
                end
            end

            -- Append header fields on the left.
            skill_nav_wrap:tag('div'):addClass('skill-nav-sub-head border-color tone-4'):wikitext(name .. mc_skill_name_head);

            -- Get localized names
            local l_display_names = nil;
            if (abbr ~= 'MS' and args['l_' .. abbr] ~= nil) then
                l_display_names = split(args['l_' .. abbr], ";");
            end

            -- Append skill fields on the right.
            local content = skill_nav_wrap:tag('div'):addClass('skill-nav-skill-content border-color tone-6');
            for k, v in pairs(skills) do
                if v == nil then
                    return
                end
                -- Fetch skills every 2 table elements, since we don't want doubles.
                if (i % 2 == 0) then
                    -- The display name of skills
                    local v_display_name = v;
                    if (is_localized and abbr ~= 'MS' and l_display_names ~= nil) then
                        v_display_name = l_display_names[i / 2];
                    end
                    -- Remove stuff like (Elesis) or (Elsword) in skill display name
                    v_display_name = v_display_name:gsub("%s%(%w+%)", "");

                    -- Append the actual skills.
                    local skill_entry = content:tag('div'):addClass(
                        'skill-nav-skill tone-7-hover color-normal-force-link tone-8-active');
                    local skill_icon = skill_entry:tag('div'):addClass('skill-nav-image')
                    if (abbr == 'FC' or abbr == 'MDF') then
                        -- [Mod] case
                        skill_entry:wikitext('[[' .. v .. '/ModA' .. lang_suffix .. '|' .. v_display_name .. ']]');
                        skill_icon:wikitext(frame:expandTemplate{
                            title = 'Force',
                            args = {
                                trim(skills[i - 1]), -- closest smaller odd element will be the icon
                                link = v,
                                language = args.lang,
                                size = '3'
                            }
                        });
                    else
                        -- Normal skill case
                        if (abbr == 'MS') then
                            -- Master Skill case
                            skill_entry:wikitext('[[' .. v_display_name .. ']]');
                        else
                            skill_entry:wikitext('[[' .. v .. lang_suffix .. '|' .. v_display_name .. ']]');
                        end

                        skill_icon:wikitext('[[File:' .. trim(skills[i - 1]) .. '|30px|link= ' .. v .. lang_suffix ..
                                                ']]');
                    end
                end
                i = i + 1;
            end
        end
    end

    -- Append the Force Skill Navigation if needed.
    local force_nav = ''
    if (args.FS == 'true') then
        force_nav = frame:expandTemplate{
            title = 'ForceSkillNav' .. lang_suffix,
            args = {
                type = 'mw-collapsible mw-collapsed',
                char = colors,
                Color = args.color
            }
        }
    end

    -- Output point
    return tostring(skill_nav) .. force_nav;

end

return p