Module:SkillNav/zh-hant: Difference between revisions

From Elwiki
No edit summary
No edit summary
Line 3: Line 3:
local p = {}
local p = {}


-- Main process
function p.main(frame)
function p.main(frame)
     local args = getArgs(frame);
     local args = getArgs(frame)
    local isForceNav = args.forcenav ~= nil


     -- Making life easier.
     -- 準備技能類別
    function inArgs(name)
     local skill_types
        if (inArray(name, args)) then
     if not isForceNav then
            return true
        end
    end
 
    local isForceNav = args.forcenav ~= nil;
 
    -- Prepare a table of skill types to display in the navigation.
     local skill_types;
     if (not isForceNav) then
         skill_types = {{
         skill_types = {{
             name = args.l_hyper, -- 'Hyper Active',
             name = args.l_hyper,
             abbr = 'HA'
             abbr = 'HA'
         }, {
         }, {
             name = args.l_secret, -- 'Secret Art',
             name = args.l_secret,
             abbr = 'SeA'
             abbr = 'SeA'
         }, {
         }, {
             name = args.l_special, -- 'Special Active',
             name = args.l_special,
             abbr = 'SA'
             abbr = 'SA'
         }, {
         }, {
             name = args.l_active, -- 'Active',
             name = args.l_active,
             abbr = 'A'
             abbr = 'A'
         }, {
         }, {
             name = args.l_mod, -- 'Force Mod',
             name = args.l_mod,
             abbr = 'FC',
             abbr = 'FC',
             mod = true,
             mod = true,
             link_suffix = '/Mod'
             link_suffix = '/Mod'
         }, {
         }, {
             name = args.l_mod2, -- 'Base Mod',
             name = args.l_mod2,
             abbr = 'FC2',
             abbr = 'FC2',
             mod = true,
             mod = true,
             force_class = 'base'
             force_class = 'base'
         }, {
         }, {
             name = args.l_buff, -- 'Buff',
             name = args.l_buff,
             abbr = 'B'
             abbr = 'B'
         }, {
         }, {
             name = args.l_passive, -- 'Passive',
             name = args.l_passive,
             abbr = 'P'
             abbr = 'P'
         }, {
         }, {
             name = args.l_demon, -- 'Manic Demon',
             name = args.l_demon,
             abbr = 'MD'
             abbr = 'MD'
         }, {
         }, {
             name = '[[File:ForceIcon.png|16px]] ' .. args.l_demon, -- 'Manic Demon (Force)',
             name = '[[File:ForceIcon.png|16px]] ' .. args.l_demon,
             abbr = 'MDF',
             abbr = 'MDF',
             mod = true,
             mod = true,
             link_suffix = '/Mod'
             link_suffix = '/Mod'
         }, {
         }, {
             name = args.l_master, -- 'Master Skill',
             name = args.l_master,
             abbr = 'MS'
             abbr = 'MS'
         }, {
         }, {
             name = args.l_couple, -- 'Couple Skill',
             name = args.l_couple,
             abbr = 'Wed'
             abbr = 'Wed'
        }, {
            name = args.l_row1, -- 'Row 1',
            abbr = 'row1'
        }, {
            name = args.l_row2, -- 'Row 2',
            abbr = 'row2'
        }, {
            name = args.l_row3, -- 'Row 3',
            abbr = 'row3'
        }, {
            name = args.l_row4, -- 'Row 4',
            abbr = 'row4'
        }}
    else
        -- Force Nav called, change skill types
        skill_types = {{
            name = args.l_force_active, -- 'Force Active',
            abbr = 'FA3',
            type = 'third'
        }, {
            name = args.l_force_passive, -- 'Force Passive',
            abbr = 'FP3',
            type = 'third'
        }, {
            name = args.l_force_active, -- 'Force Active',
            abbr = 'FAM',
            type = 'master'
        }, {
            name = args.l_force_passive, -- 'Force Passive',
            abbr = 'FPM',
            type = 'master'
         }}
         }}
     end
     end


     -- For backward compatibility. Do not remove until all pages are changed.
     -- 設定角色名稱
     if (args.name == nil) then
     if args.name == nil then
         args.name = args.Name;
         args.name = args.Name
    end
 
    -- Needed this to make a custom toggle.
    local char_name_sanitized = '';
    local char_name = args.name;
    if (isForceNav and args.parent_name ~= nil) then
        char_name = args.parent_name;
    end
    for w in char_name:gmatch("%w+") do
        char_name_sanitized = char_name_sanitized .. w;
    end
    if (isForceNav and args.parent_name ~= nil) then
        char_name_sanitized = 'ForceSkills-' .. char_name_sanitized;
     end
     end


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


     -- Header
     -- 設定標題
     local header = skill_nav:tag('div'):addClass('skill-nav-header');
     local header = skill_nav:tag('div'):addClass('skill-nav-header')
     local colors;
     local colors = args.color or frame:expandTemplate{
    if (args.color ~= nil) then
        title = 'ColorSel',
        colors = args.color;
        args = {'Character', args.char}
    else
    }
        colors = frame:expandTemplate{
    colors = colors:gsub('#', '#')
            title = 'ColorSel',
     header:css('background-color', colors)
            args = {'Character', args.char}
        };
     end


     -- Redirect to language subpages if provided.
     -- 設定標題文字
     local is_localized = args.lang ~= nil;
     if args.l_name == nil then
    local lang_suffix = '';
         args.l_name = args.name
    if (is_localized) then
         lang_suffix = '/' .. args.lang;
     end
     end
 
     local headerText = header:tag('span'):addClass('skill-nav-title')
    colors = colors:gsub('#', '#')
     if not isForceNav then
   
         headerText:wikitext('[[' .. args.name .. '|' .. args.l_name .. ']] - ' .. args.l_skills)
    header:css('background-color', colors);
 
    if (args.is_guild ~= nil) then
        header:css({
            ['justify-content'] = 'center',
            ['background-color'] = colors
        });
    end
   
    if (not isForceNav and not args.is_guild) then
        header:wikitext(frame:expandTemplate{
            title = 'Face',
            args = {
                args.char,
                args.pic,
                link = args.name,
                lang = lang_suffix,
                scale = '0.85'
            }
        })
    end
    -- Header text with a link
    if (args.l_name == nil) then
        args.l_name = args.name;
    end
     local headerText = header:tag('span'):addClass('skill-nav-title');
     if (not isForceNav) then
         headerText:wikitext('[[' .. args.name .. lang_suffix .. '|' .. args.l_name .. ']] - ' .. args.l_skills);
     else
     else
         headerText:wikitext(args.name);
         headerText:wikitext(args.name)
     end
     end


     -- 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')
    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) or args.collapsible ~= nil) then
        skill_nav_wrap:attr('id', 'mw-customcollapsible-' .. char_name_sanitized);
        header:tag('div'):addClass('mw-customtoggle-' .. char_name_sanitized);
    end
    if (args.collapsible ~= nil) then
        skill_nav_wrap:addClass('mw-collapsible');
    end
    if (args.collapsed ~= nil) then
        skill_nav_wrap:addClass('mw-collapsed');
    end


     -- Generate the navigation's body content.
     -- 產生技能導航內容
     for k2, v2 in spairs(skill_types) do
     for _, v2 in pairs(skill_types) do
         local name = v2['name'];
         local name = v2.name
         local abbr = v2['abbr'];
         local abbr = v2.abbr
        local type = v2['type'];
         local mod = v2.mod
         local mod = v2['mod'];
         local link_suffix = v2.link_suffix or ''
         local link_suffix = v2['link_suffix'] or '';
        local force_class = v2['force_class'];
        if (inArgs(abbr)) then
            -- Syntax: [image.png, link_name, display_name]; [image.png, link_name, display_name]; (...)
            local skills = split(args[abbr], ';');
            if (abbr == 'Wed') then
                skills = {
                    'RelationSkill1.png, Extreme Heavenly Love' .. lang_suffix .. ', ' .. args.l_couple_skill_name,
                    'RelationSkill2.png, Extreme Heavenly Bond' .. lang_suffix .. ', ' .. args.l_soulmate_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];
                mc_skill_name = mc_skill_name:gsub('ä', 'a');
                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 .. ', ' .. mc_skill_name .. '/Stage 4' .. lang_suffix .. ', ' .. args.l_stage .. ' 4';
                skills[6] = mc_skill_name .. '/Stage 3' .. lang_suffix .. ', ' .. mc_skill_name .. '/Stage 3' .. lang_suffix .. ', ' .. args.l_stage .. ' 3';
                skills[4] = mc_skill_name .. '/Stage 2' .. lang_suffix .. ', ' .. mc_skill_name .. '/Stage 2' .. lang_suffix .. ', ' .. args.l_stage .. ' 2';
                skills[2] = mc_skill_name .. '/Stage 1' .. lang_suffix .. ', ' .. mc_skill_name .. '/Stage 1' .. lang_suffix .. ', ' .. args.l_stage .. ' 1';
            end


            -- If Force Nav, append an extra header before "Force Active" if needed.
        if args[abbr] then
            if (abbr == 'FA3' or abbr == 'FAM') then
            local skills = split(args[abbr], ';') -- 技能列表
                local extra_head = skill_nav_wrap:tag('div'):addClass(
             local i = 1
                    '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)
             skill_nav_wrap:tag('div'):addClass('skill-nav-sub-head border-color tone-4'):wikitext(name ..
            local content = skill_nav_wrap:tag('div'):addClass('skill-nav-skill-content border-color tone-6')
                                                                                                      mc_skill_name_head);


             -- Get localized names (not used in new format)
             for _, skill_data in pairs(skills) do
            local l_display_names = nil;
                if skill_data then
            if (abbr ~= 'MS' and args['l_' .. abbr] ~= nil) then
                    local skill_parts = split(skill_data, ',')
                l_display_names = split(args['l_' .. abbr], ";");
                    local skill_icon = trim(skill_parts[1]) -- 圖片檔案
            end
                    local skill_link = trim(skill_parts[2]) -- 跳轉連結
                    local skill_display_name = trim(skill_parts[3]) -- 顯示名稱


            -- Append skill fields on the right.
                    local skill_entry = content:tag('div')
            local content = skill_nav_wrap:tag('div'):addClass('skill-nav-skill-content border-color tone-6');
                        :addClass('skill-nav-skill tone-7-hover color-normal-force-link tone-8-active')
            for k, v in pairs(skills) do
                     skill_entry:wikitext('[[' .. skill_link .. '|' .. skill_display_name .. ']]')
                if v == nil then
                     return
                end
                -- Split each skill entry into image, link_name, display_name
                local skill_parts = split(trim(v), ',');
                local image = skill_parts[1] and trim(skill_parts[1]) or '';
                local link_name = skill_parts[2] and trim(skill_parts[2]) or '';
                local display_name = skill_parts[3] and trim(skill_parts[3]) or link_name; -- Fallback to link_name if display_name is missing


                -- Append the actual skills.
                     local skill_icon_div = skill_entry:tag('div'):addClass('skill-nav-image')
                local skill_entry = content:tag('div'):addClass(
                    if mod then
                     'skill-nav-skill tone-7-hover color-normal-force-link tone-8-active');
                        skill_icon_div:wikitext(frame:expandTemplate{
                local skill_icon = skill_entry:tag('div'):addClass('skill-nav-image');
                            title = 'Force',
                if (mod) then
                            args = {
                    -- [Mod] case
                                skill_icon,
                    skill_entry:wikitext('[[' .. link_name .. link_suffix .. lang_suffix .. '|' .. display_name .. ']]');
                                link = skill_link,
                    skill_icon:wikitext(frame:expandTemplate{
                                size = '3'
                        title = 'Force',
                             }
                        args = {
                         })
                            image,
                            link = link_name,
                            language = args.lang,
                            size = '3',
                             class = force_class
                         }
                    });
                else
                    -- Normal skill case
                    if (abbr == 'MS' or abbr == 'Wed') then
                        -- Master Skill/Wedding Skill case
                        skill_entry:wikitext('[[' .. link_name .. '|' .. display_name .. ']]');
                     else
                     else
                         skill_entry:wikitext('[[' .. link_name .. lang_suffix .. '|' .. display_name .. ']]');
                         skill_icon_div:wikitext('[[File:' .. skill_icon .. '|30px|link=' .. skill_link .. ']]')
                     end
                     end
                    skill_icon:wikitext('[[File:' .. image .. '|30px|link=' .. link_name .. lang_suffix .. ']]');
                 end
                 end
                i = i + 1
             end
             end
         end
         end
     end
     end


    -- Append the Force Skill Navigation if needed.
     return tostring(skill_nav)
    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,
                parent_name = args.name
            }
        }
    end
 
    -- Output point
     return tostring(skill_nav) .. force_nav;
 
end
end


return p
return p

Revision as of 11:12, 28 March 2025

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

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

function p.main(frame)
    local args = getArgs(frame)
    local isForceNav = args.forcenav ~= nil

    -- 準備技能類別
    local skill_types
    if not isForceNav then
        skill_types = {{
            name = args.l_hyper,
            abbr = 'HA'
        }, {
            name = args.l_secret,
            abbr = 'SeA'
        }, {
            name = args.l_special,
            abbr = 'SA'
        }, {
            name = args.l_active,
            abbr = 'A'
        }, {
            name = args.l_mod,
            abbr = 'FC',
            mod = true,
            link_suffix = '/Mod'
        }, {
            name = args.l_mod2,
            abbr = 'FC2',
            mod = true,
            force_class = 'base'
        }, {
            name = args.l_buff,
            abbr = 'B'
        }, {
            name = args.l_passive,
            abbr = 'P'
        }, {
            name = args.l_demon,
            abbr = 'MD'
        }, {
            name = '[[File:ForceIcon.png|16px]] ' .. args.l_demon,
            abbr = 'MDF',
            mod = true,
            link_suffix = '/Mod'
        }, {
            name = args.l_master,
            abbr = 'MS'
        }, {
            name = args.l_couple,
            abbr = 'Wed'
        }}
    end

    -- 設定角色名稱
    if args.name == nil then
        args.name = args.Name
    end

    local skill_nav = mw.html.create('div'):addClass('skill-nav')
    if isForceNav then
        skill_nav:addClass('force-nav')
    end

    -- 設定標題
    local header = skill_nav:tag('div'):addClass('skill-nav-header')
    local colors = args.color or frame:expandTemplate{
        title = 'ColorSel',
        args = {'Character', args.char}
    }
    colors = colors:gsub('&#35;', '#')
    header:css('background-color', colors)

    -- 設定標題文字
    if args.l_name == nil then
        args.l_name = args.name
    end
    local headerText = header:tag('span'):addClass('skill-nav-title')
    if not isForceNav then
        headerText:wikitext('[[' .. args.name .. '|' .. args.l_name .. ']] - ' .. args.l_skills)
    else
        headerText:wikitext(args.name)
    end

    -- 技能欄位內容
    local skill_nav_wrap = skill_nav:tag('div'):addClass('skill-nav-inner-wrap border-color')

    -- 產生技能導航內容
    for _, v2 in pairs(skill_types) do
        local name = v2.name
        local abbr = v2.abbr
        local mod = v2.mod
        local link_suffix = v2.link_suffix or ''

        if args[abbr] then
            local skills = split(args[abbr], ';') -- 技能列表
            local i = 1

            skill_nav_wrap:tag('div'):addClass('skill-nav-sub-head border-color tone-4'):wikitext(name)
            local content = skill_nav_wrap:tag('div'):addClass('skill-nav-skill-content border-color tone-6')

            for _, skill_data in pairs(skills) do
                if skill_data then
                    local skill_parts = split(skill_data, ',')
                    local skill_icon = trim(skill_parts[1]) -- 圖片檔案
                    local skill_link = trim(skill_parts[2]) -- 跳轉連結
                    local skill_display_name = trim(skill_parts[3]) -- 顯示名稱

                    local skill_entry = content:tag('div')
                        :addClass('skill-nav-skill tone-7-hover color-normal-force-link tone-8-active')
                    skill_entry:wikitext('[[' .. skill_link .. '|' .. skill_display_name .. ']]')

                    local skill_icon_div = skill_entry:tag('div'):addClass('skill-nav-image')
                    if mod then
                        skill_icon_div:wikitext(frame:expandTemplate{
                            title = 'Force',
                            args = {
                                skill_icon,
                                link = skill_link,
                                size = '3'
                            }
                        })
                    else
                        skill_icon_div:wikitext('[[File:' .. skill_icon .. '|30px|link=' .. skill_link .. ']]')
                    end
                end
                i = i + 1
            end
        end
    end

    return tostring(skill_nav)
end

return p