Simplify `areas:save()`

master
Maksim 2022-01-02 01:12:15 +01:00 committed by MoNTE48
parent 1efd8955cc
commit d4f9ba9329
1 changed files with 2 additions and 14 deletions

View File

@ -4,26 +4,14 @@ function areas:player_exists(name)
return minetest.get_auth_handler().get_auth(name) ~= nil
end
local safe_file_write = minetest.safe_file_write
if safe_file_write == nil then
function safe_file_write(path, content)
local file, err = io.open(path, "w")
if err then
return err
end
file:write(content)
file:close()
end
end
-- Save the areas table to a file
function areas:save()
local datastr = minetest.write_json(self.areas)
local datastr = minetest.write_json(self.areas, true)
if not datastr then
minetest.log("error", "[areas] Failed to serialize area data!")
return
end
return safe_file_write(self.config.filename, datastr)
return minetest.safe_file_write(self.config.filename, datastr)
end
-- Load the areas table from the save file