跳转到内容
打开/关闭菜单
  • 397 文件
  • 1979 用户
  • 1.2万 编辑
Gal中文百科
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

Module:角色立绘:修订间差异

来自Gal中文百科
更多语言
Yexiaoyu​(留言 | 贡献)
创建页面,内容为“--Module:角色立绘 功能: 解析角色立绘参数 支持格式: 单张: Aya.png 多张: Aya.png:常服; Aya_school.png:校服 规则: ; 分隔多个立绘 : 分隔图片和说明 local p = {} -------------------------------------------------- -- 去除首尾空格 -------------------------------------------------- local function trim(str) if not str then return "" end ret…”
 
Yexiaoyu​(留言 | 贡献)
无编辑摘要
 
(未显示同一用户的1个中间版本)
第1行: 第1行:
--[[
    Module:角色立绘
    功能:
    解析角色立绘参数
    支持格式:
    单张:
    Aya.png
    多张:
    Aya.png:常服;
    Aya_school.png:校服
    规则:
    ;  分隔多个立绘
    :  分隔图片和说明
]]
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
--------------------------------------------------
 
-- 主函数
 
--
-- 解析立绘:Aya.png:常服; Aya_school.png:校服
-- 调用:
local function parse( value )
--
local list = {}
-- {{#invoke:角色立绘|main
 
-- |图片=xxx
value = trim( value )
-- |角色名=Aya
if value == "" then
-- }}
return list
--
end
--------------------------------------------------
 
function p.main(frame)
for item in string.gmatch( value, "([^;]+)" ) do
    local args = frame.args
item = trim( item )
    local images =
 
        trim(args["图片"])
local file, label = item:match( "^([^:]+):?(.*)$" )
    local name =
 
        trim(args["角色名"])
table.insert(
    if images == "" then
list,
        return ""
{
    end
file = trim( file ),
    local html = {}
label = trim( label )
    -- 外层
}
    table.insert(
)
        html,
end
        '<div class="character-card__portrait">'
 
    )
return list
    -- 按 ; 分割立绘
end
    for item in string.gmatch(images, "([^;]+)") do
 
        item = trim(item)
 
        -- 图片:说明
-- 立绘轮播,供卡片主体使用
        local file, label =
function p.main( frame )
            item:match("^([^:]+):?(.*)$")
local args = frame.args
        file =
 
            trim(file)
local images = args["图片"] or ""
        label =
local name = args["角色名"] or ""
            trim(label)
 
        table.insert(
local list = parse( images )
            html,
 
            '<div class="portrait-slide">'
if #list == 0 then
        )
return ""
        -- 图片
end
        table.insert(
 
            html,
local html = {}
            '[[File:' ..
 
            file ..
html[#html + 1] = '<div class="portrait-slides">'
            '|link=|' ..
 
            name ..
for i, v in ipairs( list ) do
            ']]'
 
        )
local active = ""
        -- 说明
if i == 1 then
        if label ~= "" then
active = " active"
            table.insert(
end
                html,
 
                '<span class="portrait-label">'
html[#html + 1] = '<div class="portrait-slide' .. active .. '">'
                ..
 
                label
html[#html + 1] = '[[File:' .. v.file .. '|link=|alt=' .. name .. ']]'
                ..
 
                '</span>'
if v.label ~= "" then
            )
html[#html + 1] = '<span class="portrait-label">' .. v.label .. '</span>'
        end
end
        table.insert(
 
            html,
html[#html + 1] = '</div>'
            '</div>'
end
        )
 
    end
html[#html + 1] = '</div>'
    table.insert(
 
        html,
-- 多图才显示按钮
        '</div>'
if #list > 1 then
    )
html[#html + 1] = '<div class="character-card__switch" title="切换立绘">' .. '⇄' .. '</div>'
    return table.concat(html)
end
 
return table.concat( html )
end
 
-- 取第一张立绘的文件名,供画廊缩略项使用
-- {{#invoke:角色立绘|first|图片={{{角色立绘|}}}}}
function p.first( frame )
local list = parse( frame.args["图片"] or "" )
if #list == 0 then
return ""
end
return list[1].file
end
end
return p
return p

2026年8月28日 (五) 11:36的最新版本

此模块的文档可以在Module:角色立绘/doc创建

local p = {}


-- 去除空格
local function trim( str )
	if not str then
		return ""
	end
	return mw.text.trim( str )
end


-- 解析立绘:Aya.png:常服; Aya_school.png:校服
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=|alt=' .. 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

-- 取第一张立绘的文件名,供画廊缩略项使用
-- {{#invoke:角色立绘|first|图片={{{角色立绘|}}}}}
function p.first( frame )
	local list = parse( frame.args["图片"] or "" )
	if #list == 0 then
		return ""
	end
	return list[1].file
end
return p