Module:Dynmap: Difference between revisions

From Colonia Wiki
Created page with "local p = {} --p stands for package function p.hello( frame ) return "Hello, world!" end return p"
 
No edit summary
Line 1: Line 1:
local p = {} --p stands for package
local p = {} -- package
 
-- worldtomap
local wtms = {}
 
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 = {}
 
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[3] * coords.x + wtm[4] * coords.y + wtm[5] * coords.z;
    local lng = wtm[0] * coords.x + wtm[1] * coords.y + wtm[2] * coords.z;
 
    local results = {};
    -- results.x = -((128 - lat) / (1 << mapzoomout));
    results.x = -((128 - lat) / (bit.lshift(1, mapzoomout)));
    -- results.z = lng / (1 << mapzoomout);
    results.z = lng / (bit.lshift(1, mapzoomout));
    results.y = coords.y;
 
    return results;
end


function p.hello( frame )
function p.hello( frame )

Revision as of 16:54, 18 October 2021

TODO documentation

Lua error at line 6: attempt to index field 'world' (a nil value).


local p = {} -- package

-- worldtomap
local wtms = {}

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 = {}

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[3] * coords.x + wtm[4] * coords.y + wtm[5] * coords.z;
    local lng = wtm[0] * coords.x + wtm[1] * coords.y + wtm[2] * coords.z;

    local results = {};
    -- results.x = -((128 - lat) / (1 << mapzoomout));
    results.x = -((128 - lat) / (bit.lshift(1, mapzoomout)));
    -- results.z = lng / (1 << mapzoomout);
    results.z = lng / (bit.lshift(1, mapzoomout));
    results.y = coords.y;

    return results;
end

function p.hello( frame )
    return "Hello, world!"
end

return p