Module:Dynmap Test: Difference between revisions
From Colonia Wiki
Test thing |
No edit summary |
||
(23 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
-- How many pixels does a block take up at different zoom levels? | -- How many pixels does a block take up at different zoom levels? | ||
Line 10: | Line 10: | ||
if (tonumber(x0) or 0) <= (tonumber(x1) or 0) then | 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 | else | ||
numXStart = tonumber(x1) or 0 | |||
numYStart = tonumber(y1) or 0 | |||
numXEnd = tonumber(x0) or 0 | |||
numYEnd = tonumber(y0) or 0 | |||
end | end | ||
local blockRes = zoomBlockRes[numZoom] | --local blockRes = zoomBlockRes[numZoom] | ||
local blockRes = 1 | |||
local blocksPerTileAxis = 128 / blockRes | local blocksPerTileAxis = 128 / blockRes | ||
local XAxisTileCount = ceil((numXStart | local XAxisTileCount = math.ceil((numXEnd - numXStart) / blocksPerTileAxis) | ||
local YAxisTileCount = ceil((numYStart | local YAxisTileCount = math.ceil((numYEnd - numYStart) / blocksPerTileAxis) | ||
local tilePaths = {} | local tilePaths = {} | ||
for y = | for y = YAxisTileCount, 1, -1 do | ||
for x = | tilePaths[y] = {} | ||
for x = XAxisTileCount, 1, -1 do | |||
-- TODO: honor zoom level | -- TODO: honor zoom level | ||
tilePaths[y] = "https://colonia.lightni.ng/map/tiles/world/flat/0_0/ | tilePaths[y][x] = "https://colonia.lightni.ng/map/tiles/world/flat/0_0/" .. x .. "_" .. y .. ".png" | ||
end | end | ||
end | end | ||
Line 39: | Line 41: | ||
function p.generateTable(tilePaths) | function p.generateTable(tilePaths) | ||
data = "{|cellpadding=0 cellspacing=0 | data = "{| cellpadding=0 cellspacing=0" | ||
for y = | for y = #tilePaths, 1, -1 do | ||
data = data .. "\n|-\n| " .. tilePaths[y][ | data = data .. "\n|-\n| " .. tilePaths[y][1] | ||
for x = | for x = 2, #tilePaths[y], 1 do | ||
data = data .. " " .. tilePaths[y][x] | data = data .. " ||" .. tilePaths[y][x] | ||
end | end | ||
end | end | ||
Line 52: | Line 54: | ||
end | end | ||
function p.map(zoom | function p.map(frame) | ||
local tilePaths = getMapTilePaths(zoom, x0, y0, x1, y1) | local zoom = frame.args[1] | ||
local data = generateTable(tilePaths) | local x0 = frame.args[2] | ||
return data | local y0 = frame.args[3] | ||
local x1 = frame.args[4] | |||
local y1 = frame.args[5] | |||
local tilePaths = p.getMapTilePaths(zoom, x0, y0, x1, y1) | |||
local data = p.generateTable(tilePaths) | |||
return tostring(data) | |||
end | end | ||
return p | return p |
Latest revision as of 04:25, 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 blockRes = 1
local blocksPerTileAxis = 128 / blockRes
local XAxisTileCount = math.ceil((numXEnd - numXStart) / blocksPerTileAxis)
local YAxisTileCount = math.ceil((numYEnd - numYStart) / blocksPerTileAxis)
local tilePaths = {}
for y = YAxisTileCount, 1, -1 do
tilePaths[y] = {}
for x = XAxisTileCount, 1, -1 do
-- TODO: honor zoom level
tilePaths[y][x] = "https://colonia.lightni.ng/map/tiles/world/flat/0_0/" .. x .. "_" .. y .. ".png"
end
end
return tilePaths
end
function p.generateTable(tilePaths)
data = "{| cellpadding=0 cellspacing=0"
for y = #tilePaths, 1, -1 do
data = data .. "\n|-\n| " .. tilePaths[y][1]
for x = 2, #tilePaths[y], 1 do
data = data .. " ||" .. tilePaths[y][x]
end
end
data = data .. "\n|}"
return data
end
function p.map(frame)
local zoom = frame.args[1]
local x0 = frame.args[2]
local y0 = frame.args[3]
local x1 = frame.args[4]
local y1 = frame.args[5]
local tilePaths = p.getMapTilePaths(zoom, x0, y0, x1, y1)
local data = p.generateTable(tilePaths)
return tostring(data)
end
return p