Module:CharTree/zh-hant: Difference between revisions

From Elwiki
No edit summary
Tag: Manual revert
No edit summary
Line 51: Line 51:
         end
         end
          
          
        for job_iter, job_name in ipairs(jobs) do
for job_iter, job_name in ipairs(jobs) do
            for path_iter, path_name in ipairs(job_name) do
    for path_iter, path_name in ipairs(job_name) do
                -- Foreign languages
        -- 分離顯示名稱和圖標名稱
                local icon_link_char_name = path_name;
        local icon_link_char_name = path_name
                local normal_link_char_name = path_name;
        local normal_link_char_name = path_name
                if str_localized(path_name) then
        local display_name = path_name
                    local name_split = split_lang(path_name)
                    icon_link_char_name = name_split[1]:gsub(':', '')
                    path_name = name_split[2]
                    normal_link_char_name = name_split[1] .. lang
                end
                icon_link_char_name = icon_link_char_name:gsub(':', '')
                local icon_str = 'Icon - '
                local link = '|link=' .. normal_link_char_name
                local unreleased = indexOf(normal_link_char_name, not_exist)


                if unreleased then
        -- 如果有本地化名稱,提取英文名稱和顯示名稱
                    icon_str = ''
        if str_localized(path_name) then
                    icon_link_char_name = 'Dunno'
            local name_split = split_lang(path_name)
                    link = '|link=#!'
            icon_link_char_name = name_split[1]:gsub(':', '') -- 始終使用英文名稱作為圖標文件名
                end
            display_name = name_split[2] -- 使用本地化名稱(zh-hant)作為顯示名稱
            normal_link_char_name = name_split[1] .. lang -- 鏈接使用本地化格式
        else
            icon_link_char_name = path_name:gsub(':', '') -- 無本地化時直接使用 path_name
            display_name = path_name
            normal_link_char_name = path_name
        end
 
        -- 檢查未發布狀態
        local icon_str = 'Icon - '
        local link = '|link=' .. normal_link_char_name
        local unreleased = indexOf(normal_link_char_name, not_exist)
 
        if unreleased then
            icon_str = ''
            icon_link_char_name = 'Dunno'
            link = '|link=#!'
        end


                local icon_with_link = '[[File:' .. icon_str .. icon_link_char_name .. '.png' .. link .. ']]'
        -- 生成圖標 Wiki 語法
                local img = tree:tag('div'):addClass('char-banner-tree-image'):attr('data-class-name', path_name):wikitext(icon_with_link)
        local icon_with_link = '[[File:' .. icon_str .. icon_link_char_name .. '.png' .. link .. ']]'
        local img = tree:tag('div')
            :addClass('char-banner-tree-image')
            :attr('data-class-name', display_name) -- 使用本地化名稱作為顯示名稱
            :wikitext(icon_with_link)


                if unreleased then
        if unreleased then
                    img:attr('data-unreleased', 'true')
            img:attr('data-unreleased', 'true')
                end
            end
         end
         end
    end
end


         char_banner:node(tree)
         char_banner:node(tree)

Revision as of 03:48, 22 April 2025

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

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

-- Main process
function p.main(frame)
    local args = getArgs(frame);
    local char_outer = mw.html.create('div'):addClass('character-banner-outer'):attr('data-lang', args.lang)
    local char_banner = mw.html.create('div'):addClass('character-banner-wrap border-color tone-2')
    local char_list = get_char_list(frame, args.lang)
    local lang = '';
    if args.lang then lang = '/' .. args.lang end
    local is_localized = lang and lang ~= ''
    local char_order = char_list[1]
    local not_exist = char_list[3]
    local char_list = char_list[2]

    function split_lang(str)
        local lang_l = is_localized and lang or ''
        return is_localized and split(str, lang_l .. '|') or str
    end

    function str_localized(str)
        return string.find(str, (lang or '') .. '|')
    end

    local base_arg = args[1] or 'Elsword'
    local base_name = str_localized(base_arg) and split_lang(base_arg)[1] or base_arg
    local char_tree = mw.html.create('div'):addClass('char-banner-tree')
    local out = ''
    local char, file_name, link, nopath, nopathnojob, entry, image_arg, icon_str;
    for char_iter=1, #char_order, 1 do
        local base, jobs = char_order[char_iter], {{}, {}, {}}
        local base_name = split_lang(base)[1] or base
        local tree = mw.html.create('div'):addClass('char-banner-tree'):attr('data-base', base_name:gsub('/', '')):attr('data-display-base', split_lang(base)[2] or base)

        for path_iter=1, 4, 1 do
            local path = char_list[base][path_iter]
            for job_iter=1, 3, 1 do
                local job = path[job_iter]
                local out_table = jobs[job_iter]
                if job == nil and jobs[1][path_iter] ~= nil then
                    job = jobs[1][path_iter]
                end
                if job ~= nil then
                    table.insert(out_table, job)
                end
            end
            
        end
        
for job_iter, job_name in ipairs(jobs) do
    for path_iter, path_name in ipairs(job_name) do
        -- 分離顯示名稱和圖標名稱
        local icon_link_char_name = path_name
        local normal_link_char_name = path_name
        local display_name = path_name

        -- 如果有本地化名稱,提取英文名稱和顯示名稱
        if str_localized(path_name) then
            local name_split = split_lang(path_name)
            icon_link_char_name = name_split[1]:gsub(':', '') -- 始終使用英文名稱作為圖標文件名
            display_name = name_split[2] -- 使用本地化名稱(zh-hant)作為顯示名稱
            normal_link_char_name = name_split[1] .. lang -- 鏈接使用本地化格式
        else
            icon_link_char_name = path_name:gsub(':', '') -- 無本地化時直接使用 path_name
            display_name = path_name
            normal_link_char_name = path_name
        end

        -- 檢查未發布狀態
        local icon_str = 'Icon - '
        local link = '|link=' .. normal_link_char_name
        local unreleased = indexOf(normal_link_char_name, not_exist)

        if unreleased then
            icon_str = ''
            icon_link_char_name = 'Dunno'
            link = '|link=#!'
        end

        -- 生成圖標 Wiki 語法
        local icon_with_link = '[[File:' .. icon_str .. icon_link_char_name .. '.png' .. link .. ']]'
        local img = tree:tag('div')
            :addClass('char-banner-tree-image')
            :attr('data-class-name', display_name) -- 使用本地化名稱作為顯示名稱
            :wikitext(icon_with_link)

        if unreleased then
            img:attr('data-unreleased', 'true')
        end
    end
end

        char_banner:node(tree)
        out = not_exist
    end

    local styles = frame:preprocess('{{#css:MediaWiki:Character-Banner.css}}')
    local header = frame:expandTemplate{
        title = 'CharHeader',
        args = {
            'Elsword',
            'Elsword' .. lang,
            'tone-8',
            force_title = split_lang(char_order[1])[2]
        }
    }

    local select_banner = mw.html.create('div'):addClass('character-banner-select tone-8 border-color')
    for k, v in ipairs(char_order) do
        local display_name = v;
        local actual_name = v;
        if str_localized(v) then actual_name = split_lang(v)[1]; display_name = split_lang(v)[2] end
        if actual_name == 'Lu/Ciel' then actual_name = 'LuCiel (Lu)' end
        local base_icon = mw.html.create('div'):attr('data-base', actual_name):attr('data-display-base', display_name or actual_name):wikitext('[[File: Icon - ' .. actual_name .. '.png]]')
        select_banner:node(base_icon)
    end

    char_outer:wikitext(header):node(char_banner:node(select_banner))
    
    return styles .. tostring(char_outer)

end

return p