aboutsummaryrefslogtreecommitdiff
path: root/storage.lua
diff options
context:
space:
mode:
authorBeha <shacknetisp@mail.com>2020-04-02 00:13:33 -0400
committerGitHub <noreply@github.com>2020-04-02 00:13:33 -0400
commit4924457eac47fc3a1c6c47834ed064b1b2089923 (patch)
treed514005ca26b792ce3f9f33050970945b06e2e63 /storage.lua
parentffedde3bd611a8f29398f9db71b198be5b23c4dc (diff)
parent13f7c692cbddb53618e904170c6ac1d6762cfa4f (diff)
downloadelevator-4924457eac47fc3a1c6c47834ed064b1b2089923.tar.gz
elevator-4924457eac47fc3a1c6c47834ed064b1b2089923.tar.bz2
elevator-4924457eac47fc3a1c6c47834ed064b1b2089923.zip
Merge pull request #10 from S-S-X/refactor
Refactoring mod structure
Diffstat (limited to 'storage.lua')
-rw-r--r--storage.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/storage.lua b/storage.lua
new file mode 100644
index 0000000..e923e5d
--- /dev/null
+++ b/storage.lua
@@ -0,0 +1,33 @@
+
+local elevator_file = minetest.get_worldpath() .. "/elevator"
+
+local str = minetest.get_mod_storage and minetest.get_mod_storage()
+
+-- Central "network" table.
+elevator.motors = {}
+
+local function load_elevator()
+ local data = nil
+ if str and ((str.contains and str:contains("data")) or (str:get_string("data") and str:get_string("data") ~= "")) then
+ data = minetest.deserialize(str:get_string("data"))
+ else
+ local file = io.open(elevator_file)
+ if file then
+ data = minetest.deserialize(file:read("*all")) or {}
+ file:close()
+ end
+ end
+ elevator.motors = (data and data.motors) and data.motors or {}
+end
+
+elevator.save_elevator = function()
+ if str then
+ str:set_string("data", minetest.serialize({motors = elevator.motors}))
+ return
+ end
+ local f = io.open(elevator_file, "w")
+ f:write(minetest.serialize({motors = elevator.motors}))
+ f:close()
+end
+
+load_elevator()