2023年政策修订增补工作正在进行中,欢迎参与!
  • Moegirl.ICU:萌娘百科流亡社群 581077156(QQ),欢迎对萌娘百科运营感到失望的编辑者加入
  • Moegirl.ICU:账号认领正在试运行,有意者请参照账号认领流程

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