-
Notifications
You must be signed in to change notification settings - Fork 14
/
storage.lua
33 lines (27 loc) · 917 Bytes
/
storage.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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()