Module:角色立绘:修订间差异
来自Gal中文百科
更多语言
更多操作
创建页面,内容为“--Module:角色立绘 功能: 解析角色立绘参数 支持格式: 单张: Aya.png 多张: Aya.png:常服; Aya_school.png:校服 规则: ; 分隔多个立绘 : 分隔图片和说明 local p = {} -------------------------------------------------- -- 去除首尾空格 -------------------------------------------------- local function trim(str) if not str then return "" end ret…” |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
local p={} | |||
-- 去除空格 | |||
local p = {} | |||
-- | |||
local function trim(str) | local function trim(str) | ||
if not str then | if not str then | ||
return "" | return "" | ||
end | end | ||
return mw.text.trim(str) | return mw.text.trim(str) | ||
end | end | ||
-- | |||
-- 解析立绘 | |||
local function parse(value) | |||
local list={} | |||
value=trim(value) | |||
if value=="" then | |||
return list | |||
end | |||
for item in string.gmatch(value,"([^;]+)") do | |||
item=trim(item) | |||
local file,label = | |||
item:match("^([^:]+):?(.*)$") | |||
table.insert( | |||
list, | |||
{ | |||
file=trim(file), | |||
label=trim(label) | |||
} | |||
) | |||
end | |||
return list | |||
end | |||
function p.main(frame) | function p.main(frame) | ||
local args = frame.args | |||
local images = | |||
local args=frame.args | |||
local name = | |||
if | local images= | ||
args["图片"] or "" | |||
local name= | |||
args["角色名"] or "" | |||
local list= | |||
parse(images) | |||
if #list==0 then | |||
return "" | return "" | ||
end | end | ||
local html = {} | |||
local html={} | |||
for | html[#html+1]= | ||
'<div class="portrait-slides">' | |||
for i,v in ipairs(list) do | |||
local active="" | |||
if i==1 then | |||
active=" active" | |||
end | |||
html[#html+1]= | |||
'<div class="portrait-slide' | |||
.. | |||
if label ~= "" then | active | ||
.. | |||
'">' | |||
html[#html+1]= | |||
'[[File:' | |||
.. | |||
v.file | |||
.. | |||
'|link=|' | |||
.. | |||
name | |||
.. | |||
']]' | |||
if v.label~="" then | |||
html[#html+1]= | |||
'<span class="portrait-label">' | |||
.. | |||
v.label | |||
.. | |||
'</span>' | |||
end | end | ||
html[#html+1]= | |||
'</div>' | |||
end | end | ||
html[#html+1]= | |||
'</div>' | |||
-- 多图才显示按钮 | |||
if #list>1 then | |||
html[#html+1]= | |||
'<div class="character-card__switch" title="切换立绘">' | |||
.. | |||
'⇄' | |||
.. | |||
'</div>' | '</div>' | ||
end | |||
return table.concat(html) | return table.concat(html) | ||
end | end | ||
return p | return p | ||
2026年8月27日 (四) 04:57的版本
此模块的文档可以在Module:角色立绘/doc创建
local p={}
-- 去除空格
local function trim(str)
if not str then
return ""
end
return mw.text.trim(str)
end
-- 解析立绘
local function parse(value)
local list={}
value=trim(value)
if value=="" then
return list
end
for item in string.gmatch(value,"([^;]+)") do
item=trim(item)
local file,label =
item:match("^([^:]+):?(.*)$")
table.insert(
list,
{
file=trim(file),
label=trim(label)
}
)
end
return list
end
function p.main(frame)
local args=frame.args
local images=
args["图片"] or ""
local name=
args["角色名"] or ""
local list=
parse(images)
if #list==0 then
return ""
end
local html={}
html[#html+1]=
'<div class="portrait-slides">'
for i,v in ipairs(list) do
local active=""
if i==1 then
active=" active"
end
html[#html+1]=
'<div class="portrait-slide'
..
active
..
'">'
html[#html+1]=
'[[File:'
..
v.file
..
'|link=|'
..
name
..
']]'
if v.label~="" then
html[#html+1]=
'<span class="portrait-label">'
..
v.label
..
'</span>'
end
html[#html+1]=
'</div>'
end
html[#html+1]=
'</div>'
-- 多图才显示按钮
if #list>1 then
html[#html+1]=
'<div class="character-card__switch" title="切换立绘">'
..
'⇄'
..
'</div>'
end
return table.concat(html)
end
return p