From 4b7be7442a59d2e27252b17e3fd839791706eeb6 Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Mon, 23 Sep 2024 12:57:09 +0200 Subject: [PATCH] persist template metadata --- init.lua | 4 +++- registry.lua | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 784bf89..70981fd 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,7 @@ -pick_and_place = {} +pick_and_place = { + store = minetest.get_mod_storage() +} local MP = minetest.get_modpath("pick_and_place") dofile(MP .. "/common.lua") diff --git a/registry.lua b/registry.lua index e4b2ddc..93e69bc 100644 --- a/registry.lua +++ b/registry.lua @@ -9,4 +9,19 @@ end function pick_and_place.get_template(id) return registry[id] -end \ No newline at end of file +end + +local function load() + local json = pick_and_place.store:get_string("registry") + if json ~= "" then + registry = minetest.parse_json(json, {}) + end +end + +load() + +local function save() + pick_and_place.store:set_string("registry", minetest.write_json(registry)) +end + +minetest.register_on_shutdown(save) \ No newline at end of file