modlib/data.lua

19 lines
809 B
Lua
Raw Permalink Normal View History

2020-02-09 01:39:54 +01:00
minetest.mkdir(minetest.get_worldpath().."/data")
function create_mod_storage(modname)
minetest.mkdir(minetest.get_worldpath().."/data/"..modname)
2021-03-27 21:01:29 +01:00
end
2020-02-09 01:39:54 +01:00
function get_path(modname, filename)
return minetest.get_worldpath().."/data/"..modname.."/"..filename
2021-03-27 21:01:29 +01:00
end
2020-02-09 01:39:54 +01:00
function load(modname, filename)
return minetest.deserialize(modlib.file.read(get_path(modname, filename)..".lua"))
2021-03-27 21:01:29 +01:00
end
2020-02-09 01:39:54 +01:00
function save(modname, filename, stuff)
return modlib.file.write(get_path(modname, filename)..".lua", minetest.serialize(stuff))
2021-03-27 21:01:29 +01:00
end
2020-02-09 01:39:54 +01:00
function load_json(modname, filename)
return minetest.parse_json(modlib.file.read(get_path(modname, filename)..".json") or "null")
2021-03-27 21:01:29 +01:00
end
2020-02-09 01:39:54 +01:00
function save_json(modname, filename, stuff)
return modlib.file.write(get_path(modname, filename)..".json", minetest.write_json(stuff))
2021-03-27 21:01:29 +01:00
end