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

模块:Sif2item

来自LLWiki
跳转到导航 跳转到搜索

可在模块:Sif2item/doc创建此模块的帮助文档

-- @Author: [[User:Leranjun]]

local p = {}

local getArgs = require("Module:Arguments").getArgs
local DATA = mw.loadData("Module:Sif2item/data")

function p.main(frame)
    local args = getArgs(frame, {parentOnly = true, removeBlanks = false})
    local arg1, arg2, arg3 = mw.ustring.lower(args[1] or ""), args[2], args[3]
    local item = DATA.AKA[arg1] or arg1
    local data = DATA.ITEMS[item]

    if data == nil then
        return "<span class=\"error\">错误的道具名!</span>"
    elseif data.force2 and arg2 == nil then
        return "<span class=\"error\">模板Sif2item缺失必要参数!</span>"
    end

    local file = data.file or mw.ustring.upper(item)
    local r = tostring( mw.html.create('span'):addClass("game-item")
        :wikitext(
            "[[file:SIF2 "..file..
            ".png|40px|link=]]"
        )
    ).." "..(data.before or file.." ")
    if arg2 == "" or arg2 == "0" or not (arg2 or data.default) then
        return r
    end
    return r..(arg2 or data.default)..(data.after or "")
end

return p