A minetest mod for mapmaking
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2KB

  1. -- Arguments
  2. -- settings: The mod settings
  3. local settings = ...;
  4. -- Storage and saving
  5. local mod_storage = minetest.get_mod_storage();
  6. local map_data = {
  7. -- Scanned map data
  8. generated = minetest.deserialize(mod_storage:get_string("map")) or {},
  9. -- Maps
  10. maps = minetest.deserialize(mod_storage:get_string("maps")) or {},
  11. -- The next id
  12. next_map_id = mod_storage:get_int("next_map_id"),
  13. -- The version of the map api
  14. api_version = mod_storage:get_int("api_version"),
  15. };
  16. if map_data.next_map_id == 0 then
  17. map_data.next_map_id = 1;
  18. end
  19. if map_data.api_version == 0 then
  20. map_data.api_version = 1;
  21. end
  22. local function save()
  23. mod_storage:set_string("maps", minetest.serialize(map_data.maps));
  24. mod_storage:set_int("next_map_id", map_data.next_map_id);
  25. mod_storage:set_string("map", minetest.serialize(map_data.generated));
  26. mod_storage:set_string("api_version", minetest.serialize(map_data.api_version));
  27. end
  28. minetest.register_on_shutdown(save);
  29. minetest.register_on_leaveplayer(save);
  30. if settings.autosave_freq ~= 0 then
  31. local function periodic_save()
  32. save();
  33. minetest.after(settings.autosave_freq, periodic_save);
  34. end
  35. minetest.after(settings.autosave_freq, periodic_save);
  36. end
  37. return map_data;