From 8aba2d8c57658baa76cb1aca725c8cb265cab33c Mon Sep 17 00:00:00 2001 From: Hugues Ross Date: Mon, 8 Jun 2020 07:26:18 -0400 Subject: [PATCH] Parameterize biome / marker tables --- init.lua | 18 +++++++++--------- items.lua | 4 ++-- map_api.lua | 10 +++++----- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/init.lua b/init.lua index d228e3e..cdb290d 100644 --- a/init.lua +++ b/init.lua @@ -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); diff --git a/items.lua b/items.lua index d115dbd..dcdc9f4 100644 --- a/items.lua +++ b/items.lua @@ -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"; diff --git a/map_api.lua b/map_api.lua index f07cb0e..f335408 100644 --- a/map_api.lua +++ b/map_api.lua @@ -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