打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:少女前线立绘

来自OGAS数据中枢
弃权者留言 | 贡献2026年5月16日 (六) 21:30的版本 (弃权者移动页面Module:少女前线信息Module:少女前线立绘,不留重定向)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

此模块的文档可以在Module:少女前线立绘/doc创建

local p = {}

local PIC_NAMES = { '普通', '重创', '和谐', '重创和谐' }

local STYLES_PAGE = 'User:弃权者/Template:少女前线信息/styles.css'
local WIDGET_NAME = 'GF立绘切换'

local function escape(s)
    if not s then return '' end
    return s:gsub('&','&amp;'):gsub('<','&lt;'):gsub('>','&gt;'):gsub('"','&quot;')
end

local function parseGroups(args)
    local groups = {}
    for i = 1, 30 do
        local tag = args['tag' .. i]
        if not tag or tag == '' then
            if i > 3 then
                local allEmpty = true
                for k = i, math.min(i + 2, 30) do
                    if args['tag' .. k] and args['tag' .. k] ~= '' then
                        allEmpty = false
                        break
                    end
                end
                if allEmpty then break end
            end
        else
            local groupType = args['type' .. i] or 'pic'
            local pics = {}
            for j = 1, 20 do
                local picFile = args['tag' .. i .. 'pic' .. j]
                if picFile and picFile ~= '' then
                    local label
                    if groupType == 'pic' then
                        label = PIC_NAMES[j] or ('差分' .. j)
                    else
                        label = args['tag' .. i .. 'name' .. j]
                        if not label or label == '' then
                            label = '差分' .. j
                        end
                    end
                    table.insert(pics, { file = picFile, label = label })
                end
            end
            table.insert(groups, {
                label = tag,
                groupType = groupType,
                pics = pics,
            })
        end
    end
    return groups
end

local function renderSwitcher(groups)
    local html = {}
    table.insert(html, '<div class="gf-switcher-overlay">')
    table.insert(html, '<div class="gf-switcher-toggle" title="展开/隐藏菜单"></div>')
    table.insert(html, '<div class="gf-switcher-list">')

    for gi, group in ipairs(groups) do
        local isFirst = gi == 1
        table.insert(html, string.format(
            '<div class="gf-group-btn%s" data-group="%d">%s</div>',
            isFirst and ' active' or '',
            gi,
            escape(group.label)
        ))
        table.insert(html, string.format(
            '<div class="gf-variant-list%s" data-group="%d">',
            isFirst and '' or ' collapsed',
            gi
        ))
        for vi, pic in ipairs(group.pics) do
            table.insert(html, string.format(
                '<div class="gf-switch-btn%s" data-group="%d" data-variant="%d" data-filename="%s">%s</div>',
                (isFirst and vi == 1) and ' active' or '',
                gi,
                vi,
                escape(pic.file),
                escape(pic.label)
            ))
        end
        table.insert(html, '</div>')
    end

    table.insert(html, '</div>')
    table.insert(html, '</div>')
    return table.concat(html, '\n')
end

local function renderImageContainer(groups)
    local html = {}
    table.insert(html, '<div class="gf-image-container">')

    local defaultFile = ''
    if groups[1] and groups[1].pics[1] then
        defaultFile = groups[1].pics[1].file
    end

    if defaultFile ~= '' then
        table.insert(html, string.format(
            '<div class="gf-main-img">[[File:%s|link=]]</div>',
            defaultFile
        ))
    end

    table.insert(html, '<div class="gf-view-original" title="查看原图"></div>')
    table.insert(html, '</div>')
    return table.concat(html, '\n')
end

function p.main(frame)
    local args = frame:getParent().args
    local pageName = mw.title.getCurrentTitle().subpageText
    local groups = parseGroups(args)

    local boxId = 'gf-box-' .. mw.uri.encode(pageName, 'PATH')

    local html = {}
    table.insert(html, frame:extensionTag('templatestyles', '', { src = STYLES_PAGE }))
    table.insert(html, frame:preprocess('{{#widget:' .. WIDGET_NAME .. '}}'))
    table.insert(html, string.format('<div class="gf-infobox-new" id="%s">', escape(boxId)))
    table.insert(html, '<div class="gf-left-panel">')
    if #groups > 0 then
        table.insert(html, renderSwitcher(groups))
        table.insert(html, renderImageContainer(groups))
    end
    table.insert(html, '</div>')

    return table.concat(html, '\n')
end

return p