全站通知:

模块:Map

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

function p.main(frame)
    local args = getArgs(frame)
    local island = args.island or ""
    local main = args.main or "true"
    local width = tonumber(args[3]) or 400
    local height = math.floor(width / 400 * 244 + 0.5)
    
    local bgImage, prefix
    if island == "true" then
        bgImage = "Ginger Island Map.png"
        prefix = "islandloc"
    elseif island == "small" then
        bgImage = "Map with Island.png"
        prefix = "loc"
    elseif main ~= "false" then
        bgImage = "Map.png"
        prefix = "loc"
    else
        return ""
    end

    local container = mw.html.create('div')
        :addClass('mapcontainer')
        :css({
            ['width'] = width .. 'px',
            ['height'] = height .. 'px',
            ['position'] = 'relative'
        })

    local function addPoint(x, y)
        if x and y then
            container:tag('div')
                :addClass('maplocation')
                :css({
                    ['left'] = x .. 'px',
                    ['top'] = y .. 'px',
                    ['position'] = 'absolute'
                })
                :wikitext('[[File:Maplocation.png|20px|link=]]')
        end
    end

    if island == "true" then
        addPoint(args[prefix .. '1x'], args[prefix .. '1y'])
    else
        addPoint(args[1], args[2])
    end

    for i = 2, 4 do
        addPoint(args[prefix .. i .. 'x'], args[prefix .. i .. 'y'])
    end

    container:wikitext(string.format('[[File:%s|%dpx|link=]]', bgImage, width))

    return tostring(mw.html.create('div'):addClass('maplayout'):node(container))
end

return p