LLWiki正在建设中,欢迎加入我们

“模块:Sifitem”的版本间差异

来自LLWiki
跳转到导航 跳转到搜索
(debug遗留)
(在判断颜色时转换arg2为小写)
第112行: 第112行:
if (notempty(arg2) or notempty(arg3)) then
if (notempty(arg2) or notempty(arg3)) then
local color = ""
local color = ""
if (COLORS[arg2]) then
if (COLORS[mw.ustring.lower(arg2)]) then
color = COLORS[arg2][2]
color = COLORS[mw.ustring.lower(arg2)][2]
elseif (COLORS[arg3]) then
elseif (COLORS[arg3]) then
color = COLORS[arg3][2]
color = COLORS[arg3][2]

2021年1月2日 (六) 22:58的版本

Template-info.png 模块文档
这个文档嵌入模块:Sifitem/doc

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

请不要直接调用此模块。

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

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

local p = {}

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

local FILES = mw.loadData("Module:Sifitem/data")
local BORDER_KW = {["有底"] = true, ["有框"] = true, ["粉底"] = true, ["底"] = true, ["框"] = true}
local COLORS = {
    ["smile"] = {
        "Smile",
        "#d1016a"
    },
    ["red"] = {
        ["aka"] = "smile"
    },
    ["pure"] = {
        "Pure",
        "#2da55a"
    },
    ["green"] = {
        ["aka"] = "pure"
    },
    ["cool"] = {
        "Cool",
        "#0f98e3"
    },
    ["blue"] = {
        ["aka"] = "cool"
    },
    ["all"] = {
        "",
        "#9a55cc"
    },
    ["purple"] = {
        ["aka"] = "all"
    }
}
local LEVELS = {
    ["ur"] = "Item icon 13",
    ["ssr"] = "Item icon 25",
    ["sr"] = "Item icon 14",
    ["r"] = "Item icon 15",
    ["n"] = "Item icon 85"
}

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])}}
    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
                color = COLORS[mw.ustring.lower(arg2)][2]
            elseif (COLORS[arg3]) then
                color = COLORS[arg3][2]
            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