全站通知:

模块:Overlayimg

来自站务
跳到导航 跳到搜索
[ 创建 | 刷新 ]文档页面
当前模块文档缺失,需要扩充。
local getArgs = require('Module:Arguments').getArgs
local p = {}

local QUALITY_MAP = {
    ["4"]       = "Iridium Quality Icon.png",
    ["iridium"] = "Iridium Quality Icon.png",
    ["2"]       = "Gold Quality Icon.png",
    ["gold"]    = "Gold Quality Icon.png",
    ["1"]       = "Silver Quality Icon.png",
    ["silver"]  = "Silver Quality Icon.png"
}

function p.main(frame)
    local args = getArgs(frame)
    
    local imgName = (args[1] or "Blank icon"):gsub("%.png$", "")
    local width   = tonumber(args.width) or 24
    local type    = (args.type or ""):lower()
    local quality = (args.quality or "0"):lower()
    local isCenter = args.center == "true"
    
    local containerStyle = string.format("width:%dpx; height:auto;", width)
    if isCenter then
        containerStyle = containerStyle .. "margin: 0 auto;"
    end
    
    local bgClass = (type == "star") and "backimage" or "backimagetransparent"
    
    local foreContent = ""
    
    if type == "recipe" then
        local recipeWidth = (width == 48) and 48 or (width + 8)
        foreContent = string.format("[[File:Recipe Overlay.png|%dpx|link=]]", recipeWidth)
        
    elseif type == "star" then
        local starFile = QUALITY_MAP[quality]
        if starFile then
            foreContent = string.format("[[File:%s|%dpx|link=]]", starFile, width)
        end
        
    elseif type ~= "" then
        local ns = mw.title.getCurrentTitle().namespace
        if ns ~= 10 then 
            foreContent = string.format("[[File:%s Overlay.png|%dpx|link=]]", args.type, width)
        end
    end

    local root = mw.html.create('div')
        :addClass('parent')
        :cssText(containerStyle)

    root:tag('div')
        :addClass(bgClass)
        :wikitext(string.format("[[File:%s.png|%dpx|link=]]", imgName, width))

    root:tag('div')
        :addClass('foreimage')
        :wikitext(foreContent)

    return tostring(root)
end

return p