2021-06-16 15:51:26 +00:00
-- The functions and variables in this file are only for use in the mod itself. Those that do real work should be local and wrapped in public functions
local debug = true
local function say ( text )
if yl_template.debug then
core.log ( " action " , " [MOD] yl_template : " .. text )
end
end
local function save_path ( file )
return yl_template.worldpath .. file .. " .json "
end
local function save_json ( filename , content )
if type ( filename ) ~= " string " or type ( content ) ~= " table " then
return false
end
local savepath = save_path ( filename )
local savecontent = minetest.write_json ( content )
return minetest.safe_file_write ( savepath , savecontent )
end
local function load_json ( filename ) -- returns the saved dialog
local savepath = save_path ( filename )
local file , err = io.open ( savepath , " r " )
if err then
return { }
end
io.input ( file )
local savecontent = io.read ( )
local content = minetest.parse_json ( savecontent )
io.close ( file )
if type ( content ) ~= " table " then
content = { }
end
return content
end
-- Public functions wrap the private ones, so they can be exchanged easily
function yl_template . load ( filename , ... )
return load_json ( filename , ... )
end
2021-12-11 02:18:35 +00:00
function yl_template . save ( filename , content , ... )
return save_json ( filename , content , ... )
2021-06-16 15:51:26 +00:00
end