Module:角色立绘
来自Gal中文百科
更多语言
更多操作
此模块的文档可以在Module:角色立绘/doc创建
--[[
Module:角色立绘
功能:
解析角色立绘参数
支持格式:
单张:
Aya.png
多张:
Aya.png:常服;
Aya_school.png:校服
规则:
; 分隔多个立绘
: 分隔图片和说明
]]
local p = {}
--------------------------------------------------
-- 去除首尾空格
--------------------------------------------------
local function trim(str)
if not str then
return ""
end
return mw.text.trim(str)
end
--------------------------------------------------
-- 主函数
--
-- 调用:
--
-- {{#invoke:角色立绘|main
-- |图片=xxx
-- |角色名=Aya
-- }}
--
--------------------------------------------------
function p.main(frame)
local args = frame.args
local images =
trim(args["图片"])
local name =
trim(args["角色名"])
if images == "" then
return ""
end
local html = {}
-- 外层
table.insert(
html,
'<div class="character-card__portrait">'
)
-- 按 ; 分割立绘
for item in string.gmatch(images, "([^;]+)") do
item = trim(item)
-- 图片:说明
local file, label =
item:match("^([^:]+):?(.*)$")
file =
trim(file)
label =
trim(label)
table.insert(
html,
'<div class="portrait-slide">'
)
-- 图片
table.insert(
html,
'[[File:' ..
file ..
'|link=|' ..
name ..
']]'
)
-- 说明
if label ~= "" then
table.insert(
html,
'<span class="portrait-label">'
..
label
..
'</span>'
)
end
table.insert(
html,
'</div>'
)
end
table.insert(
html,
'</div>'
)
return table.concat(html)
end
return p