replace minetest.settings based worlds specific settings storage by file io based
This commit is contained in:
parent
c58d294754
commit
6cb331e08d
@ -19,6 +19,55 @@
|
|||||||
--! @ingroup framework_int
|
--! @ingroup framework_int
|
||||||
--! @{
|
--! @{
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
-- name: mobf_init_world_specific_settings(name,value)
|
||||||
|
--
|
||||||
|
--! @brief check if world specific settings are supported by core if not do in lua
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
function mobf_init_world_specific_settings()
|
||||||
|
local mobf_world_settings_data = nil
|
||||||
|
|
||||||
|
if minetest.world_setting_set == nil or
|
||||||
|
type(minetest.world_setting_set) ~= "function" then
|
||||||
|
|
||||||
|
local mobf_world_path = minetest.get_worldpath()
|
||||||
|
|
||||||
|
--initialy read settings file
|
||||||
|
mobf_world_settings_data = nil
|
||||||
|
local file,error = io.open(mobf_world_path .. "/mobf_settings.conf","r")
|
||||||
|
|
||||||
|
if error ~= nil then
|
||||||
|
minetest.log(LOGLEVEL_WARNING,"MOBF: failed to open world specific config file")
|
||||||
|
mobf_world_settings_data = {}
|
||||||
|
else
|
||||||
|
mobf_world_settings_data = minetest.deserialize(file:read("*a"))
|
||||||
|
file:close()
|
||||||
|
end
|
||||||
|
|
||||||
|
--set world settings function
|
||||||
|
minetest.world_setting_set = function(name,value)
|
||||||
|
mobf_world_settings_data[name] = value
|
||||||
|
|
||||||
|
local file,error = io.open(mobf_world_path .. "/mobf_settings.conf","w")
|
||||||
|
|
||||||
|
if error ~= nil then
|
||||||
|
minetest.log(LOGLEVEL_ERROR,"MOBF: failed to open world specific config file")
|
||||||
|
end
|
||||||
|
mobf_assert_backtrace(file ~= nil)
|
||||||
|
|
||||||
|
file:write(minetest.serialize(mobf_world_settings_data))
|
||||||
|
file:close()
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.world_setting_get = function(name)
|
||||||
|
mobf_assert_backtrace(mobf_world_settings_data ~= nil)
|
||||||
|
|
||||||
|
return mobf_world_settings_data[name]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- name: mobf_set_world_setting(name,value)
|
-- name: mobf_set_world_setting(name,value)
|
||||||
--
|
--
|
||||||
@ -28,14 +77,7 @@
|
|||||||
--! @param value to save
|
--! @param value to save
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
function mobf_set_world_setting(name,value)
|
function mobf_set_world_setting(name,value)
|
||||||
|
|
||||||
if minetest.world_setting_set == nil then
|
|
||||||
local worldid = minetest.get_worldpath()
|
|
||||||
local access_name = "mobf:" .. worldid .. ": " .. name
|
|
||||||
minetest.setting_set(access_name,value)
|
|
||||||
else
|
|
||||||
minetest.world_setting_set(name,value)
|
minetest.world_setting_set(name,value)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
@ -46,15 +88,9 @@ end
|
|||||||
--! @param name key to use for storage
|
--! @param name key to use for storage
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
function mobf_get_world_setting(name)
|
function mobf_get_world_setting(name)
|
||||||
|
|
||||||
if minetest.world_setting_get == nil then
|
|
||||||
local worldid = minetest.get_worldpath()
|
|
||||||
local access_name = "mobf:" .. worldid .. ": " .. name
|
|
||||||
return minetest.setting_get(access_name)
|
|
||||||
else
|
|
||||||
return minetest.world_setting_get(name)
|
return minetest.world_setting_get(name)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
mobf_init_world_specific_settings()
|
||||||
|
|
||||||
--!@}
|
--!@}
|
Loading…
x
Reference in New Issue
Block a user