Module:Dynmap: Difference between revisions
From Colonia Wiki
No edit summary |
No edit summary |
||
Line 31: | Line 31: | ||
local results = {}; | local results = {}; | ||
-- results.x = -((128 - lat) / (1 << mapzoomout)); | -- results.x = -((128 - lat) / (1 << mapzoomout)); | ||
results.x = -((128 - lat) / ( | results.x = -((128 - lat) / (bit32.lshift(1, mapzoomout))); | ||
-- results.z = lng / (1 << mapzoomout); | -- results.z = lng / (1 << mapzoomout); | ||
results.z = lng / ( | results.z = lng / (bit32.lshift(1, mapzoomout)); | ||
results.y = coords.y; | results.y = coords.y; | ||
Line 49: | Line 49: | ||
function p.tileToPath(tile, zoom, world, map) | function p.tileToPath(tile, zoom, world, map) | ||
local scale = | local scale = bit32.lshift(1, zoom) | ||
local x = scale * tile.x; | local x = scale * tile.x; | ||
local z = scale * tile.z; | local z = scale * tile.z; | ||
local scaledx = | print("x:" .. x .. " z:" .. z) | ||
local scaledz = | local scaledx = bit32.rshift(math.floor(x), zoom); | ||
local scaledz = bit32.rshift(math.floor(z), zoom); | |||
print("scaledx:" .. scaledx .. " scaledz:" .. scaledz) | |||
-- /map/tiles/<world>/<map>/<scaledx>_<scaledz>/<zoom prefix>_<x>_<z>.png | -- /map/tiles/<world>/<map>/<scaledx>_<scaledz>/<zoom prefix>_<x>_<z>.png | ||
Line 61: | Line 63: | ||
function p.dynmapImageForCoords(world, map, x, z, zoom) | function p.dynmapImageForCoords(world, map, x, z, zoom) | ||
local tile = p.gameCoordsToTile({x = x, z = z}, world, map); | local tile = p.gameCoordsToTile({x = x, y = 64, z = z}, world, map); | ||
local path = p.tileToPath(tile, zoom, world, map); | local path = p.tileToPath(tile, zoom, world, map); | ||
return path; | return path; | ||
Line 69: | Line 71: | ||
return "Hello, world!" | return "Hello, world!" | ||
end | end | ||
Revision as of 17:36, 18 October 2021
TODO documentation
Script error: The module returned a nil value. It is supposed to return an export table.
local p = {} -- package
-- worldtomap
local wtms = { world = {}, world_nether = {}, world_the_end = {}};
wtms.world.flat = {4, 0, -2.4492935982947064e-16, -2.4492935982947064e-16, 0, -4, 0, 1, 0}
wtms.world.t = {1.31370849898476, 0, -11.313708498984761, -5.6568542494923815, 13.856406460551018, -5.656854249492381, 5.551115123125782e-17, 0.9999999999999997, 5.551115123125782e-17 };
-- mapzoomout
local mapzoomouts = { world = {}, world_nether = {}, world_the_end = {}};
mapzoomouts.world.flat = 5;
mapzoomouts.world.t = 5;
function p.getWorldToMap(world, map)
return wtms[world][map]
end
function p.getMapZoomOut(world, map)
return mapzoomouts[world][map]
end
function p.gameCoordsToTile(coords, world, map)
local wtm = p.getWorldToMap(world, map)
local mapzoomout = p.getMapZoomOut(world, map)
local lat = wtm[4] * coords.x + wtm[5] * coords.y + wtm[6] * coords.z;
local lng = wtm[1] * coords.x + wtm[2] * coords.y + wtm[3] * coords.z;
local results = {};
-- results.x = -((128 - lat) / (1 << mapzoomout));
results.x = -((128 - lat) / (bit32.lshift(1, mapzoomout)));
-- results.z = lng / (1 << mapzoomout);
results.z = lng / (bit32.lshift(1, mapzoomout));
results.y = coords.y;
return results;
end
function p.zoomPrefix(level)
-- repeat "z" for each zoom level
local prefix = "";
for i = 1, level do
prefix = prefix .. "z";
end
return prefix;
end
function p.tileToPath(tile, zoom, world, map)
local scale = bit32.lshift(1, zoom)
local x = scale * tile.x;
local z = scale * tile.z;
print("x:" .. x .. " z:" .. z)
local scaledx = bit32.rshift(math.floor(x), zoom);
local scaledz = bit32.rshift(math.floor(z), zoom);
print("scaledx:" .. scaledx .. " scaledz:" .. scaledz)
-- /map/tiles/<world>/<map>/<scaledx>_<scaledz>/<zoom prefix>_<x>_<z>.png
local path = "/map/tiles/" .. world .. "/" .. map .. "/" .. scaledx .. "_" .. scaledz .. "/" .. p.zoomPrefix(zoom) .. "_" .. x .. "_" .. z .. ".png";
return path;
end
function p.dynmapImageForCoords(world, map, x, z, zoom)
local tile = p.gameCoordsToTile({x = x, y = 64, z = z}, world, map);
local path = p.tileToPath(tile, zoom, world, map);
return path;
end
function p.hello( frame )
return "Hello, world!"
end