Refactor coordinate api into its own file
This commit is contained in:
parent
ca910ad29d
commit
6a3938d996
17
chunk_api.lua
Normal file
17
chunk_api.lua
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
local CHUNK_SIZE = 16;
|
||||||
|
|
||||||
|
-- Contains functions for converting coordinates between world units and the
|
||||||
|
-- unit used by cartographer's maps
|
||||||
|
return {
|
||||||
|
-- Convert world coordinates to map coordinates
|
||||||
|
-- coord: The coordinate value
|
||||||
|
to = function(coord)
|
||||||
|
return math.floor(coord / CHUNK_SIZE);
|
||||||
|
end,
|
||||||
|
|
||||||
|
-- Convert map coordinates to world coordinates
|
||||||
|
-- coord: The coordinate value
|
||||||
|
from = function(coord)
|
||||||
|
return math.floor(coord * CHUNK_SIZE);
|
||||||
|
end
|
||||||
|
};
|
23
init.lua
23
init.lua
@ -1,8 +1,9 @@
|
|||||||
local mod_storage = minetest.get_mod_storage();
|
|
||||||
|
|
||||||
-- The path to this mod, for including files
|
-- The path to this mod, for including files
|
||||||
local modpath = minetest.get_modpath("cartographer");
|
local modpath = minetest.get_modpath("cartographer");
|
||||||
|
|
||||||
|
|
||||||
|
-- Storage and saving
|
||||||
|
local mod_storage = minetest.get_mod_storage();
|
||||||
local map_data = {
|
local map_data = {
|
||||||
generated = minetest.deserialize(mod_storage:get_string("map")) or {},
|
generated = minetest.deserialize(mod_storage:get_string("map")) or {},
|
||||||
|
|
||||||
@ -28,20 +29,10 @@ local function periodic_save()
|
|||||||
end
|
end
|
||||||
minetest.after(60, periodic_save);
|
minetest.after(60, periodic_save);
|
||||||
|
|
||||||
local chunk_size = 16;
|
|
||||||
local chunk = {
|
|
||||||
to = function(coord)
|
|
||||||
return math.floor(coord / chunk_size);
|
|
||||||
end,
|
|
||||||
|
|
||||||
from = function(coord)
|
|
||||||
return math.floor(coord * chunk_size);
|
|
||||||
end
|
|
||||||
};
|
|
||||||
|
|
||||||
local marker_lookup = {};
|
local marker_lookup = {};
|
||||||
|
|
||||||
-- Includes
|
-- Includes
|
||||||
|
local chunk = loadfile(modpath .. "/chunk_api.lua") ();
|
||||||
local skin = loadfile(modpath .. "/skin_api.lua") ();
|
local skin = loadfile(modpath .. "/skin_api.lua") ();
|
||||||
local gui = loadfile(modpath .. "/formspec.lua") ();
|
local gui = loadfile(modpath .. "/formspec.lua") ();
|
||||||
local audio = loadfile(modpath .. "/audio.lua") ();
|
local audio = loadfile(modpath .. "/audio.lua") ();
|
||||||
@ -61,10 +52,16 @@ loadfile(modpath .. "/autofill.lua") (chunk, scanner, maps);
|
|||||||
|
|
||||||
-- The API object
|
-- The API object
|
||||||
cartographer = {
|
cartographer = {
|
||||||
|
-- skin_api.lua: Allows the visual customization of formspecs
|
||||||
skin = skin;
|
skin = skin;
|
||||||
|
-- biome_api.lua: Allows biome data to be registered for display in maps
|
||||||
biomes = biomes;
|
biomes = biomes;
|
||||||
|
-- marker_api.lua: Allows markers to be registered for placement on maps
|
||||||
markers = markers;
|
markers = markers;
|
||||||
|
-- map_api.lua: Allows the creation, lookup, and management of map objects
|
||||||
maps = maps;
|
maps = maps;
|
||||||
|
-- items.lua: Allows the creation of map items with proper metadata
|
||||||
map_item = map_item;
|
map_item = map_item;
|
||||||
|
-- materials.lua: Allows items to be registered as mapmaking materials
|
||||||
materials = materials;
|
materials = materials;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user