Module:Dynmap Test: Difference between revisions

From Colonia Wiki
No edit summary
No edit summary
Line 10: Line 10:


     if (tonumber(x0) or 0) <= (tonumber(x1) or 0) then
     if (tonumber(x0) or 0) <= (tonumber(x1) or 0) then
         local numXStart = tonumber(x0) or 0
         numXStart = tonumber(x0) or 0
         local numYStart = tonumber(y0) or 0
         numYStart = tonumber(y0) or 0
         local numXEnd  = tonumber(x1) or 0
         numXEnd  = tonumber(x1) or 0
         local numYEnd  = tonumber(y1) or 0
         numYEnd  = tonumber(y1) or 0
     else
     else
         local numXStart = tonumber(x1) or 0
         numXStart = tonumber(x1) or 0
         local numYStart = tonumber(y1) or 0
         numYStart = tonumber(y1) or 0
         local numXEnd  = tonumber(x0) or 0
         numXEnd  = tonumber(x0) or 0
         local numYEnd  = tonumber(y0) or 0
         numYEnd  = tonumber(y0) or 0
     end
     end


     local blockRes          = zoomBlockRes[numZoom]
     local blockRes          = zoomBlockRes[numZoom]
     local blocksPerTileAxis = 128 / blockRes
     local blocksPerTileAxis = 128 / blockRes
     local XAxisTileCount    = ceil((numXStart - numXEnd) / blocksPerTileAxis)
     local XAxisTileCount    = math.ceil((numXStart - numXEnd) / blocksPerTileAxis)
     local YAxisTileCount    = ceil((numYStart - numYEnd) / blocksPerTileAxis)
     local YAxisTileCount    = math.ceil((numYStart - numYEnd) / blocksPerTileAxis)


     local tilePaths = {}
     local tilePaths = {}

Revision as of 03:16, 7 March 2024

Documentation for this module may be created at Module:Dynmap Test/doc

local p = {}

-- How many pixels does a block take up at different zoom levels?
local zoomBlockRes = {}
zoomBlockRes[6]    = 4
zoomBlockRes[5]    = 1

function p.getMapTilePaths(zoom, x0, y0, x1, y1)
    local numZoom = tonumber(zoom) or 0

    if (tonumber(x0) or 0) <= (tonumber(x1) or 0) then
        numXStart = tonumber(x0) or 0
        numYStart = tonumber(y0) or 0
        numXEnd   = tonumber(x1) or 0
        numYEnd   = tonumber(y1) or 0
    else
        numXStart = tonumber(x1) or 0
        numYStart = tonumber(y1) or 0
        numXEnd   = tonumber(x0) or 0
        numYEnd   = tonumber(y0) or 0
    end

    local blockRes          = zoomBlockRes[numZoom]
    local blocksPerTileAxis = 128 / blockRes
    local XAxisTileCount    = math.ceil((numXStart - numXEnd) / blocksPerTileAxis)
    local YAxisTileCount    = math.ceil((numYStart - numYEnd) / blocksPerTileAxis)

    local tilePaths = {}
    
    for y = 0, YAxisTileCount do
        for x = 0, XAxisTileCount do
            -- TODO: honor zoom level
            tilePaths[y] = "https://colonia.lightni.ng/map/tiles/world/flat/0_0/z_" .. x .. "_" .. y .. ".jpg"
        end
    end

    return tilePaths
end

function p.generateTable(tilePaths)
    data = "{|cellpadding=0 cellspacing=0\n|-"

    for y = 0, table.getn(tilePaths) do
        data = data .. "\n|-\n| " .. tilePaths[y][0] .. " ||"
        for x = 1, table.getn(tilePaths[y]) do
            data = data .. " " .. tilePaths[y][x]
        end
    end

    data = data .. "\n|}"
    return data
end

function p.map(zoom, x0, y0, x1, y1)
    local tilePaths = p.getMapTilePaths(zoom, x0, y0, x1, y1)
    local data = p.generateTable(tilePaths)
    return data
end

return p