Parameterize biome / marker tables

This commit is contained in:
Hugues Ross 2020-06-08 07:26:18 -04:00
parent 93b6ab6ee8
commit 8aba2d8c57
3 changed files with 16 additions and 16 deletions

View File

@ -8,10 +8,6 @@ cartographer = {
scan_queue = {},
};
_cartographer = {
CHUNK_SIZE = 16,
biome_lookup = {},
marker_lookup = {},
maps = minetest.deserialize(mod_storage:get_string("maps")) or {},
next_map_id = mod_storage:get_int("next_map_id"),
@ -41,23 +37,27 @@ local function periodic_save()
end
minetest.after(60, periodic_save);
local chunk_size = 16;
local chunk = {
to = function(coord)
return math.floor(coord / _cartographer.CHUNK_SIZE);
return math.floor(coord / chunk_size);
end,
from = function(coord)
return math.floor(coord * _cartographer.CHUNK_SIZE);
return math.floor(coord * chunk_size);
end
};
local biome_lookup = {};
local marker_lookup = {};
-- Includes
cartographer.skin = loadfile(modpath .. "/skin_api.lua") ();
cartographer.gui = loadfile(modpath .. "/formspec.lua") ();
loadfile(modpath .. "/scanner.lua") (map_data, chunk);
loadfile(modpath .. "/map_api.lua") (chunk);
loadfile(modpath .. "/items.lua") (chunk, cartographer.gui, cartographer.skin);
_cartographer.generate_marker_formspec = loadfile(modpath .. "/marker_formspec.lua") (_cartographer.marker_lookup, cartographer.gui);
loadfile(modpath .. "/map_api.lua") (chunk, biome_lookup, marker_lookup);
loadfile(modpath .. "/items.lua") (chunk, marker_lookup, cartographer.gui, cartographer.skin);
_cartographer.generate_marker_formspec = loadfile(modpath .. "/marker_formspec.lua") (marker_lookup, cartographer.gui);
loadfile(modpath .. "/map_formspec.lua") (map_data);
loadfile(modpath .. "/commands.lua") ();
loadfile(modpath .. "/table.lua") (_cartographer.materials_by_name, _cartographer.materials_by_group, cartographer.gui, cartographer.skin);

View File

@ -1,4 +1,4 @@
local chunk, gui, skin = ...
local chunk, marker_lookup, gui, skin = ...
-- The list of players looking at maps, and the map IDs that they're looking at
local player_maps = {};
@ -22,7 +22,7 @@ local function show_map_id_formspec(id, player_x, player_z, player_name, height_
player_x, player_z = cartographer.to_map_coordinates(map, player_x, player_z)
local formspec, formspec_width, _ = cartographer.get_map_formspec_map(map, player_x, player_z, height_mode);
if #_cartographer.marker_lookup > 0 then
if #marker_lookup > 0 then
local height_button_texture;
if height_mode then
height_button_texture = skin.height_button_texture .. ".png";

View File

@ -1,4 +1,4 @@
local chunk = ...;
local chunk, biome_lookup, marker_lookup = ...;
function cartographer.create_map(x, z, w, h, filled, detail, scale)
local id = _cartographer.next_map_id;
@ -143,7 +143,7 @@ minetest.after(5, fill_loop);
-- (Optional) min_height: The minimum Y position where this biome data should be used
-- (Optional) max_height: The maximum Y position where this biome data should be used
function cartographer.register_biome(name, textures, min_height, max_height)
_cartographer.biome_lookup[#_cartographer.biome_lookup + 1] = {
biome_lookup[#biome_lookup + 1] = {
name = name,
textures = textures,
min_height = min_height,
@ -171,7 +171,7 @@ function cartographer.get_marker_data(id)
end
id = format_marker_id(id);
for _,marker in pairs(_cartographer.marker_lookup) do
for _,marker in pairs(marker_lookup) do
if marker.id == id then
return marker;
end
@ -197,7 +197,7 @@ function cartographer.register_marker(id, name, textures)
existing_marker.name = name;
existing_marker.textures = textures;
else
_cartographer.marker_lookup[#_cartographer.marker_lookup+1] = {
marker_lookup[#marker_lookup+1] = {
id = id,
name = name,
textures = textures,
@ -228,7 +228,7 @@ end
-- detail: The detail level
-- Returns a string with a texture name, or nil if no matching biome entry was found.
function cartographer.get_biome_texture(name, height, detail)
for _,biome in ipairs(_cartographer.biome_lookup) do
for _,biome in ipairs(biome_lookup) do
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