-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdata_base.lua
42 lines (31 loc) · 1.07 KB
/
data_base.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
34
35
36
37
38
39
40
41
42
--[[
Hyperloop Mod
=============
Copyright (C) 2017-2019 Joachim Stolberg
LGPLv2.1+
See LICENSE.txt for more information
mod storage and data integrity
]]--
-- for lazy programmers
--local P = minetest.string_to_pos
--local M = minetest.get_meta
hyperloop.Stations = hyperloop.Network:new()
hyperloop.Elevators = hyperloop.Network:new()
local storage = minetest.get_mod_storage()
hyperloop.Stations:deserialize(storage:get_string("Stations"))
hyperloop.Elevators:deserialize(storage:get_string("Elevators"))
local function update_mod_storage()
minetest.log("action", "[Hyperloop] Store data...")
storage:set_string("Stations", hyperloop.Stations:serialize())
storage:set_string("Elevators", hyperloop.Elevators:serialize())
-- store data each hour
minetest.after(60*60, update_mod_storage)
minetest.log("action", "[Hyperloop] Data stored")
end
minetest.register_on_shutdown(function()
update_mod_storage()
end)
-- delete data base entries without corresponding nodes
--minetest.after(5, check_data_base)
-- store data after one hour
minetest.after(60*60, update_mod_storage)