Module:CharTree/zh-hant: Difference between revisions
From Elwiki
(Created page with "require('Module:CommonFunctions') local getArgs = require('Module:Arguments').getArgs local p = {} -- Main process function p.main(frame, lang) local args = getArgs(frame) local named_list = {} local not_exist = {} lang = '/zh-hant' -- 強制使用繁體中文 local chars = frame:preprocess('{{:MediaWiki:NavSidebar' .. lang .. '/Character}}') -- Get rid of link wikitext. chars = chars:gsub('%[%[', ''):gsub('%]%]', '') -- Replace star s...") |
No edit summary |
||
(17 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local p = {} | local p = {} | ||
local get_char_list = require('Module:CharList').main | |||
-- 提取 base 名稱(去掉語系碼) | |||
local function get_icon_base_name(fullname) | |||
return fullname:match('^([^/]+)') or fullname | |||
end | |||
-- 提取 display 名稱(支援多語) | |||
local function get_display_name(str, lang) | |||
if str:find((lang or '') .. '|') then | |||
return split(str, (lang or '') .. '|')[2] or str | |||
end | |||
return str | |||
end | |||
-- Main process | -- Main process | ||
function p.main(frame, lang) | function p.main(frame) | ||
local | local args = getArgs(frame); | ||
local lang = args.lang or '' | |||
local lang_path = lang ~= '' and '/' .. lang or '' | |||
local is_localized = lang_path ~= '' | |||
local char_outer = mw.html.create('div'):addClass('character-banner-outer'):attr('data-lang', lang) | |||
local char_banner = mw.html.create('div'):addClass('character-banner-wrap border-color tone-2') | |||
local char_list_raw = get_char_list(frame, lang) | |||
local char_order = char_list_raw[1] | |||
local not_exist = char_list_raw[3] | |||
local char_list = char_list_raw[2] | |||
function split_lang(str) | |||
local lang_l = is_localized and lang_path or '' | |||
return is_localized and split(str, lang_l .. '|') or str | |||
end | |||
function str_localized(str) | |||
return string.find(str, (lang_path or '') .. '|') | |||
end | |||
for | |||
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 = '' | |||
for char_iter=1, #char_order do | |||
if | local base = char_order[char_iter] | ||
local jobs = {{}, {}, {}} | |||
local base_name = split_lang(base)[1] or base | |||
local tree = mw.html.create('div'):addClass('char-banner-tree') | |||
table.insert( | :attr('data-base', base_name:gsub('/', '')) | ||
:attr('data-display-base', split_lang(base)[2] or base) | |||
for path_iter=1, 4 do | |||
local path = char_list[base][path_iter] | |||
for job_iter=1, 3 do | |||
local job = path[job_iter] | |||
if job == nil and jobs[1][path_iter] ~= nil then | |||
job = jobs[1][path_iter] | |||
end | |||
if job then | |||
table.insert(jobs[job_iter], job) | |||
end | end | ||
end | 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 | |||
if str_localized(path_name) then | |||
local name_split = split_lang(path_name) | |||
icon_link_char_name = get_icon_base_name(name_split[1]):gsub(':', '') | |||
path_name = name_split[2] | |||
normal_link_char_name = name_split[1] .. lang_path | |||
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 = '' | |||
icon_link_char_name = 'Dunno' | |||
link = '|link=#!' | |||
end | |||
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', path_name) | |||
:wikitext(icon_with_link) | |||
local | |||
if unreleased then | |||
if | img:attr('data-unreleased', 'true') | ||
end | end | ||
end | end | ||
end | |||
char_banner:node(tree) | |||
end | end | ||
-- | local styles = frame:preprocess('{{#css:MediaWiki:Character-Banner.css}}') | ||
local | |||
-- ✅ 修正:正確顯示 display 名稱 | |||
local header_display_name = get_display_name(char_order[1], lang_path) | |||
local header = frame:expandTemplate{ | |||
title = 'CharHeader', | |||
args = { | |||
'Elsword', | |||
'Elsword' .. lang_path, | |||
'tone-8', | |||
force_title = header_display_name | |||
} | |||
} | } | ||
if | 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 = get_display_name(v, lang_path) | |||
local actual_name = str_localized(v) and split_lang(v)[1] or v | |||
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 - ' .. get_icon_base_name(actual_name) .. '.png]]') | |||
select_banner:node(base_icon) | |||
end | |||
char_outer:wikitext(header):node(char_banner:node(select_banner)) | |||
return | return styles .. tostring(char_outer) | ||
end | end | ||
return p | return p |
Latest revision as of 20:43, 23 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
-- 提取 base 名稱(去掉語系碼)
local function get_icon_base_name(fullname)
return fullname:match('^([^/]+)') or fullname
end
-- 提取 display 名稱(支援多語)
local function get_display_name(str, lang)
if str:find((lang or '') .. '|') then
return split(str, (lang or '') .. '|')[2] or str
end
return str
end
-- Main process
function p.main(frame)
local args = getArgs(frame);
local lang = args.lang or ''
local lang_path = lang ~= '' and '/' .. lang or ''
local is_localized = lang_path ~= ''
local char_outer = mw.html.create('div'):addClass('character-banner-outer'):attr('data-lang', lang)
local char_banner = mw.html.create('div'):addClass('character-banner-wrap border-color tone-2')
local char_list_raw = get_char_list(frame, lang)
local char_order = char_list_raw[1]
local not_exist = char_list_raw[3]
local char_list = char_list_raw[2]
function split_lang(str)
local lang_l = is_localized and lang_path or ''
return is_localized and split(str, lang_l .. '|') or str
end
function str_localized(str)
return string.find(str, (lang_path 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 = ''
for char_iter=1, #char_order do
local base = char_order[char_iter]
local jobs = {{}, {}, {}}
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 do
local path = char_list[base][path_iter]
for job_iter=1, 3 do
local job = path[job_iter]
if job == nil and jobs[1][path_iter] ~= nil then
job = jobs[1][path_iter]
end
if job then
table.insert(jobs[job_iter], 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
if str_localized(path_name) then
local name_split = split_lang(path_name)
icon_link_char_name = get_icon_base_name(name_split[1]):gsub(':', '')
path_name = name_split[2]
normal_link_char_name = name_split[1] .. lang_path
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 = ''
icon_link_char_name = 'Dunno'
link = '|link=#!'
end
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', path_name)
:wikitext(icon_with_link)
if unreleased then
img:attr('data-unreleased', 'true')
end
end
end
char_banner:node(tree)
end
local styles = frame:preprocess('{{#css:MediaWiki:Character-Banner.css}}')
-- ✅ 修正:正確顯示 display 名稱
local header_display_name = get_display_name(char_order[1], lang_path)
local header = frame:expandTemplate{
title = 'CharHeader',
args = {
'Elsword',
'Elsword' .. lang_path,
'tone-8',
force_title = header_display_name
}
}
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 = get_display_name(v, lang_path)
local actual_name = str_localized(v) and split_lang(v)[1] or v
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 - ' .. get_icon_base_name(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