local p = {}
local getArgs = require('Module:Arguments').getArgs
-- 輔助函數:檢查參數是否存在
local function isNotEmpty(s)
return s and s:match('^%s*$') == nil
end
-- 主函數
function p.main(frame)
local args = getArgs(frame)
local output = ""
local index = 1
-- 循環處理所有角色
while isNotEmpty(args['Name' .. index]) do
local name = args['Name' .. index]
local bgColor = args['bg-color' .. index] or args['bg-color'] or '#f3f3f3'
local width = args['width'] or ''
local style = args['style'] or ''
local thColor = args['th-color' .. index] or args['th-color'] or '#aea'
local thRowStyle = args['th-row-style'] or ''
local tdRowStyle = args['td-row-style'] or ''
local tdImageStyle = args['td-image-style'] or ''
local imageSize = args['image-size'] or '200px'
local tdColor = args['td-color' .. index] or args['td-color'] or '#f3f3f3'
local tdInfoStyle = args['td-info-style'] or ''
local cvColor = args['cv-color' .. index] or args['cv-color'] or '#f3f3f3'
local cvRowStyle = args['cv-row-style'] or ''
local cvStyle = args['cv-style'] or ''
-- 獲取角色特定參數
local customImage = args['custom' .. index] or args['custom-all'] or ''
local image = args['image' .. index] or ''
local imageInfo = args['image info' .. index] or ''
local info = args['info' .. index] or ''
local infoA = args['infoA' .. index] or '' -- 新增:上欄信息
local infoB = args['infoB' .. index] or '' -- 新增:下欄信息
local cv = args['CV' .. index] or ''
-- 開始構建角色HTML
output = output .. '<div class="role-list-item" style="background-color: ' .. bgColor .. ';'
if isNotEmpty(width) then
output = output .. ' width: ' .. width .. ';'
end
output = output .. ' ' .. style .. '">'
-- 角色名稱
output = output .. '<div class="role-name" style="background-color: ' .. thColor .. '; ' .. thRowStyle .. '">' .. name .. '</div>'
-- 角色詳情
output = output .. '<div class="role-details" style="' .. tdRowStyle .. '">'
-- 角色圖片
output = output .. '<div class="role-image" style="' .. tdImageStyle .. '">'
output = output .. '<div class="role-image-inner">'
-- 修復自定義圖片處理邏輯
if isNotEmpty(customImage) and (customImage:lower() == 'true' or customImage:lower() == 'yes' or customImage == '1') then
-- 使用自定義圖片代碼
output = output .. (image or '')
else
-- 使用默認圖片處理
if isNotEmpty(image) then
output = output .. '<div>[[File:' .. image .. '|' .. imageSize .. ']]</div>'
if isNotEmpty(imageInfo) then
output = output .. '<div>' .. imageInfo .. '</div>'
end
end
end
output = output .. '</div></div>'
-- 角色信息
if isNotEmpty(infoA) or isNotEmpty(infoB) then
-- 如果有infoA或infoB參數,則使用分欄佈局
output = output .. '<div class="role-info role-info-columns" style="background-color: ' .. tdColor .. '; ' .. tdInfoStyle .. '">'
output = output .. '<div>' .. infoA .. '</div>'
output = output .. '<div class="role-info-divider" style="border-bottom: 1px solid ' .. thColor .. ';width: 100%;"></div>'
output = output .. '<div>' .. infoB .. '</div>'
else
-- 如果沒有infoA和infoB,則使用原來的info參數
output = output .. '<div class="role-info" style="background-color: ' .. tdColor .. '; ' .. tdInfoStyle .. '">'
output = output .. '<div class="role-info-inner">' .. info .. '</div>'
end
output = output .. '</div></div>'
-- CV信息
if isNotEmpty(cv) then
output = output .. '<div class="role-cv" style="background-color: ' .. cvColor .. '; ' .. cvRowStyle .. '; ' .. cvStyle .. '">CV:' .. cv .. '</div>'
end
output = output .. '</div>'
index = index + 1
end
return output
end
return p