置顶公告:【置顶】关于临时开启评论区所有功能的公告(2022.10.22) | 【置顶】关于本站Widget恢复使用的公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

Module:Llsifitem

贴贴♀百科,万娘皆可贴的百科全书!转载请标注来源页面的网页链接,并声明引自贴贴百科。内容不可商用。
跳到导航 跳到搜索
Template-info.svg 模块文档  [查看] [编辑] [历史] [刷新]

该模块实现{{Llsifitem}}的功能。

请不要直接调用此模块。

-- Module:Llsifitem
-- Made with ♥ by User:Leranjun

-- This module implements {{tl|Llsifitem}}.
-- Please refrain from invoking this module directly.

local p = {}

local getArgs = require("Module:Arguments").getArgs

local DATA = mw.loadData("Module:Llsifitem/data")
local FILES = DATA.FILES
local BORDER_KW = DATA.BORDER_KW
local COLORS = DATA.COLORS
local LEVELS = DATA.LEVELS
local TABLEATTRS = DATA.TABLEATTRS

local function notempty(s)
    return (s and s ~= "")
end

function p.main(frame)
    return p._main(getArgs(frame, {removeBlanks = false}), frame)
end

function p._main(args, frame)
    local arg1, arg2, arg3 = mw.ustring.lower(args[1] or ""), args[2], mw.ustring.lower(args[3] or "")
    local r = ""

    if (FILES[arg1]) then
        local data = FILES[arg1]
        if (data.aka) then
            data = FILES[data.aka]
        end
        local src = ""
        if (data.switch) then
            src = (data[data.switch[arg3]] or data[1])
        else
            if (BORDER_KW[arg3] and data[2]) then
                src = data[2]
            else
                src = data[1]
            end
        end
        src = frame:callParserFunction("filepath", src .. ".png")
        r = r .. tostring(mw.html.create("img"):attr("src", src):css("width", "24px")) .. " " .. data.before

        local after = {}
        if (data.after[1]) then
            after = data.after
        else
            after[1] = data.after
        end

        if (arg2 ~= "0") then
            if (data.force2 or notempty(arg2)) then
                r = r .. arg2 .. after[1]
            else
                r = r .. (data.default or "1") .. after[1]
            end
        else
            if (data.force2) then
                r = r .. "{{{2}}}"
            end
            r = r .. (after[2] or "")
        end
    elseif (COLORS[arg1]) then
        local data = COLORS[arg1]
        if (data.aka) then
            data = COLORS[data.aka]
        end
        r = r .. frame:preprocess("[[File:sif" .. data[1] .. ".png|20px|link=]] ")
        r = r .. frame:expandTemplate {title = "color", args = {data[2], (arg2 or data[1])}}
    elseif (TABLEATTRS[arg1]) then
        r = TABLEATTRS[arg1]
    else
        local src = LEVELS[arg1]
        src = frame:callParserFunction("filepath", src .. ".png")
        r = r .. tostring(mw.html.create("img"):attr("src", src):css("width", "24px")) .. " "

        if (notempty(arg2) or notempty(arg3)) then
            local color = ""
            if (COLORS[mw.ustring.lower(arg2)]) then
                if (COLORS[mw.ustring.lower(arg2)].aka) then
                    color = COLORS[COLORS[mw.ustring.lower(arg2)].aka][2]
                else
                    color = COLORS[mw.ustring.lower(arg2)][2]
                end
            elseif (COLORS[arg3]) then
                if (COLORS[arg3].aka) then
                    color = COLORS[COLORS[arg3].aka][2]
                else
                    color = COLORS[arg3][2]
                end
            else
                color = "black"
            end

            local content = ""
            if (COLORS[arg3]) then
                content = frame:preprocess("'''" .. arg2 .. "'''")
            else
                content = frame:preprocess("'''" .. arg3 .. "'''")
            end

            r = r .. frame:expandTemplate {title = "color", args = {color, content}}
        end
    end
    return r
end

return p