storage-mod_storage.lua 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. -- ===================================================================
  2. -- /storage-mod_storage.lua
  3. -- Persistent storage via Minetest's mod_storage method
  4. -- See https://dev.minetest.net/StorageRef
  5. -- Loads content of stored orgs and ledger from mod_storage
  6. --get modstorageref
  7. local mod_storage = minetest.get_mod_storage()
  8. modpol.load_storage = function()
  9. -- load orgs
  10. local stored_orgs = minetest.deserialize(mod_storage:get_string("orgs"))
  11. if (stored_orgs ~= nil) then
  12. modpol.orgs = stored_orgs
  13. end
  14. -- load ledger
  15. local stored_ledger = minetest.deserialize(mod_storage:get_string("ledger"))
  16. if (stored_ledger ~= nil) then
  17. modpol.ledger = stored_ledger
  18. end
  19. -- load old_ledgers
  20. local old_stored_ledgers = minetest.deserialize(mod_storage:get_string("old_ledgers"))
  21. if (stored_ledger ~= nil) then
  22. modpol.old_ledgers = old_stored_ledgers
  23. end
  24. end
  25. -- Stores content of current orgs and ledger to mod_storage
  26. modpol.store_data = function()
  27. -- write to storage
  28. mod_storage:set_string("orgs", minetest.serialize(modpol.orgs))
  29. mod_storage:set_string("ledger", minetest.serialize(modpol.ledger))
  30. mod_storage:set_string("old_ledgers", minetest.serialize(modpol.old_ledgers))
  31. end