map_api.lua: Parameterize coordinate covnersion methods
This commit is contained in:
parent
28360f585c
commit
d38a666f5a
2
init.lua
2
init.lua
@ -58,7 +58,7 @@ local chunk = {
|
|||||||
cartographer.skin = loadfile(modpath .. "/skin_api.lua") ();
|
cartographer.skin = loadfile(modpath .. "/skin_api.lua") ();
|
||||||
cartographer.gui = loadfile(modpath .. "/formspec.lua") ();
|
cartographer.gui = loadfile(modpath .. "/formspec.lua") ();
|
||||||
loadfile(modpath .. "/scanner.lua") (map_data, chunk);
|
loadfile(modpath .. "/scanner.lua") (map_data, chunk);
|
||||||
loadfile(modpath .. "/map_api.lua") ();
|
loadfile(modpath .. "/map_api.lua") (chunk);
|
||||||
loadfile(modpath .. "/items.lua") ();
|
loadfile(modpath .. "/items.lua") ();
|
||||||
_cartographer.generate_marker_formspec = loadfile(modpath .. "/marker_formspec.lua") (_cartographer.marker_lookup, cartographer.gui);
|
_cartographer.generate_marker_formspec = loadfile(modpath .. "/marker_formspec.lua") (_cartographer.marker_lookup, cartographer.gui);
|
||||||
loadfile(modpath .. "/map_formspec.lua") (map_data);
|
loadfile(modpath .. "/map_formspec.lua") (map_data);
|
||||||
|
15
map_api.lua
15
map_api.lua
@ -1,3 +1,5 @@
|
|||||||
|
local chunk = ...;
|
||||||
|
|
||||||
function cartographer.create_map(x, z, w, h, filled, detail, scale)
|
function cartographer.create_map(x, z, w, h, filled, detail, scale)
|
||||||
local id = _cartographer.next_map_id;
|
local id = _cartographer.next_map_id;
|
||||||
|
|
||||||
@ -92,10 +94,10 @@ end
|
|||||||
-- Returns The converted x and z coordinates
|
-- Returns The converted x and z coordinates
|
||||||
function cartographer.to_map_coordinates(map, x, z)
|
function cartographer.to_map_coordinates(map, x, z)
|
||||||
if not map or map.scale == 0 then
|
if not map or map.scale == 0 then
|
||||||
return tochunk(x), tochunk(z);
|
return chunk.to(x), chunk.to(z);
|
||||||
end
|
end
|
||||||
|
|
||||||
return math.floor(tochunk(x) / map.scale + 0.5), math.floor(tochunk(z) / map.scale + 0.5);
|
return math.floor(chunk.to(x) / map.scale + 0.5), math.floor(chunk.to(z) / map.scale + 0.5);
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Periodically-called function to fill in maps and queue chunks for manual
|
-- Periodically-called function to fill in maps and queue chunks for manual
|
||||||
@ -116,9 +118,9 @@ local function fill_loop()
|
|||||||
for i = -2,2 do
|
for i = -2,2 do
|
||||||
for j = -2,2 do
|
for j = -2,2 do
|
||||||
local adjusted_pos = {
|
local adjusted_pos = {
|
||||||
x = pos.x + fromchunk(i),
|
x = pos.x + chunk.from(i),
|
||||||
y = pos.y,
|
y = pos.y,
|
||||||
z = pos.z + fromchunk(j),
|
z = pos.z + chunk.from(j),
|
||||||
}
|
}
|
||||||
cartographer.queue_region(adjusted_pos);
|
cartographer.queue_region(adjusted_pos);
|
||||||
end
|
end
|
||||||
@ -208,7 +210,6 @@ function cartographer.is_filled(map, x, z)
|
|||||||
return false;
|
return false;
|
||||||
end
|
end
|
||||||
|
|
||||||
-- minetest.chat_send_all(tostring(x).. ", " .. tostring(z) .. "(" .. tostring(x + (z * map.w)) .."): " .. tostring(map.fill[x + (z * map.w)]));
|
|
||||||
return map.fill[(x - map.x) + ((z - map.z) * map.w)] ~= nil;
|
return map.fill[(x - map.x) + ((z - map.z) * map.w)] ~= nil;
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -228,7 +229,9 @@ end
|
|||||||
-- Returns a string with a texture name, or nil if no matching biome entry was found.
|
-- Returns a string with a texture name, or nil if no matching biome entry was found.
|
||||||
function cartographer.get_biome_texture(name, height, detail)
|
function cartographer.get_biome_texture(name, height, detail)
|
||||||
for _,biome in ipairs(_cartographer.biome_lookup) do
|
for _,biome in ipairs(_cartographer.biome_lookup) do
|
||||||
if biome.name == name and (not biome.min_height or height >= biome.min_height) and (not biome.max_height or height <= biome.max_height) then
|
local matches_height = (not biome.min_height or height >= biome.min_height)
|
||||||
|
and (not biome.max_height or height <= biome.max_height);
|
||||||
|
if biome.name == name and matches_height then
|
||||||
return cartographer.detail_texture(biome.textures, detail);
|
return cartographer.detail_texture(biome.textures, detail);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user