Skip to content

Commit

Permalink
Use a settings object for the main settings
Browse files Browse the repository at this point in the history
This unifies the settings APIs.

This also unifies the sync and async registration APIs, since the async
registration API did not support adding non-functions to the API table.
  • Loading branch information
ShadowNinja committed May 6, 2017
1 parent a024042 commit 43d1f37
Show file tree
Hide file tree
Showing 46 changed files with 411 additions and 417 deletions.
6 changes: 3 additions & 3 deletions builtin/common/misc_helpers.lua
Expand Up @@ -463,7 +463,7 @@ if INIT == "game" then

core.rotate_node = function(itemstack, placer, pointed_thing)
core.rotate_and_place(itemstack, placer, pointed_thing,
core.setting_getbool("creative_mode"),
core.settings:get_bool("creative_mode"),
{invert_wall = placer:get_player_control().sneak})
return itemstack
end
Expand Down Expand Up @@ -642,8 +642,8 @@ end

local ESCAPE_CHAR = string.char(0x1b)

-- Client-sided mods don't have access to getbool
if core.setting_getbool and core.setting_getbool("disable_escape_sequences") then
-- Client-side mods don't have access to settings
if core.settings and core.settings:get_bool("disable_escape_sequences") then

function core.get_color_escape_sequence(color)
return ""
Expand Down
2 changes: 1 addition & 1 deletion builtin/fstk/tabview.lua
Expand Up @@ -167,7 +167,7 @@ local function switch_to_tab(self, index)
self.current_tab = self.tablist[index].name

if (self.autosave_tab) then
core.setting_set(self.name .. "_LAST",self.current_tab)
core.settings:set(self.name .. "_LAST",self.current_tab)
end

-- call for tab to enter
Expand Down
6 changes: 3 additions & 3 deletions builtin/game/auth.lua
Expand Up @@ -106,7 +106,7 @@ core.builtin_auth_handler = {
end
end
-- For the admin, give everything
elseif name == core.setting_get("name") then
elseif name == core.settings:get("name") then
for priv, def in pairs(core.registered_privileges) do
privileges[priv] = true
end
Expand All @@ -125,7 +125,7 @@ core.builtin_auth_handler = {
core.log('info', "Built-in authentication handler adding player '"..name.."'")
core.auth_table[name] = {
password = password,
privileges = core.string_to_privs(core.setting_get("default_privs")),
privileges = core.string_to_privs(core.settings:get("default_privs")),
last_login = os.time(),
}
save_auth_file()
Expand All @@ -148,7 +148,7 @@ core.builtin_auth_handler = {
if not core.auth_table[name] then
core.builtin_auth_handler.create_auth(name,
core.get_password_hash(name,
core.setting_get("default_password")))
core.settings:get("default_password")))
end
core.auth_table[name].privileges = privileges
core.notify_authentication_modified(name)
Expand Down
20 changes: 10 additions & 10 deletions builtin/game/chatcommands.lua
Expand Up @@ -39,7 +39,7 @@ core.register_on_chat_message(function(name, message)
return true -- Handled chat message
end)

if core.setting_getbool("profiler.load") then
if core.settings:get_bool("profiler.load") then
-- Run after register_chatcommand and its register_on_chat_message
-- Before any chattcommands that should be profiled
profiler.init_chatcommand()
Expand Down Expand Up @@ -82,7 +82,7 @@ core.register_chatcommand("me", {
core.register_chatcommand("admin", {
description = "Show the name of the server owner",
func = function(name)
local admin = minetest.setting_get("name")
local admin = minetest.settings:get("name")
if admin then
return true, "The administrator of this server is "..admin.."."
else
Expand Down Expand Up @@ -119,7 +119,7 @@ local function handle_grant_command(caller, grantname, grantprivstr)
local privs = core.get_player_privs(grantname)
local privs_unknown = ""
local basic_privs =
core.string_to_privs(core.setting_get("basic_privs") or "interact,shout")
core.string_to_privs(core.settings:get("basic_privs") or "interact,shout")
for priv, _ in pairs(grantprivs) do
if not basic_privs[priv] and not caller_privs.privs then
return false, "Your privileges are insufficient."
Expand Down Expand Up @@ -185,7 +185,7 @@ core.register_chatcommand("revoke", {
local revoke_privs = core.string_to_privs(revoke_priv_str)
local privs = core.get_player_privs(revoke_name)
local basic_privs =
core.string_to_privs(core.setting_get("basic_privs") or "interact,shout")
core.string_to_privs(core.settings:get("basic_privs") or "interact,shout")
for priv, _ in pairs(revoke_privs) do
if not basic_privs[priv] and
not core.check_player_privs(name, {privs=true}) then
Expand Down Expand Up @@ -419,20 +419,20 @@ core.register_chatcommand("set", {
func = function(name, param)
local arg, setname, setvalue = string.match(param, "(-[n]) ([^ ]+) (.+)")
if arg and arg == "-n" and setname and setvalue then
core.setting_set(setname, setvalue)
core.settings:set(setname, setvalue)
return true, setname .. " = " .. setvalue
end
local setname, setvalue = string.match(param, "([^ ]+) (.+)")
if setname and setvalue then
if not core.setting_get(setname) then
if not core.settings:get(setname) then
return false, "Failed. Use '/set -n <name> <value>' to create a new setting."
end
core.setting_set(setname, setvalue)
core.settings:set(setname, setvalue)
return true, setname .. " = " .. setvalue
end
local setname = string.match(param, "([^ ]+)")
if setname then
local setvalue = core.setting_get(setname)
local setvalue = core.settings:get(setname)
if not setvalue then
setvalue = "<not set>"
end
Expand Down Expand Up @@ -667,7 +667,7 @@ core.register_chatcommand("rollback_check", {
.. " seconds = 86400 = 24h, limit = 5",
privs = {rollback=true},
func = function(name, param)
if not core.setting_getbool("enable_rollback_recording") then
if not core.settings:get_bool("enable_rollback_recording") then
return false, "Rollback functions are disabled."
end
local range, seconds, limit =
Expand Down Expand Up @@ -718,7 +718,7 @@ core.register_chatcommand("rollback", {
description = "Revert actions of a player. Default for <seconds> is 60",
privs = {rollback=true},
func = function(name, param)
if not core.setting_getbool("enable_rollback_recording") then
if not core.settings:get_bool("enable_rollback_recording") then
return false, "Rollback functions are disabled."
end
local target_name, seconds = string.match(param, ":([^ ]+) *(%d*)")
Expand Down
21 changes: 21 additions & 0 deletions builtin/game/deprecated.lua
Expand Up @@ -49,3 +49,24 @@ setmetatable(core.env, {
function core.rollback_get_last_node_actor(pos, range, seconds)
return core.rollback_get_node_actions(pos, range, seconds, 1)[1]
end

--
-- core.setting_*
--

local settings = core.settings

local function setting_proxy(name)
return function(...)
core.log("deprecated", "WARNING: minetest.setting_* "..
"functions are deprecated. "..
"Use methods on the minetest.settings object.")
return settings[name](settings, ...)
end
end

core.setting_set = setting_proxy("set")
core.setting_get = setting_proxy("get")
core.setting_setbool = setting_proxy("set_bool")
core.setting_getbool = setting_proxy("get_bool")
core.setting_save = setting_proxy("write")
2 changes: 1 addition & 1 deletion builtin/game/forceloading.lua
Expand Up @@ -40,7 +40,7 @@ function core.forceload_block(pos, transient)
elseif other_table[hash] ~= nil then
relevant_table[hash] = 1
else
if total_forceloaded >= (tonumber(core.setting_get("max_forceloaded_blocks")) or 16) then
if total_forceloaded >= (tonumber(core.settings:get("max_forceloaded_blocks")) or 16) then
return false
end
total_forceloaded = total_forceloaded+1
Expand Down
2 changes: 1 addition & 1 deletion builtin/game/init.lua
Expand Up @@ -13,7 +13,7 @@ dofile(gamepath.."constants.lua")
assert(loadfile(gamepath.."item.lua"))(builtin_shared)
dofile(gamepath.."register.lua")

if core.setting_getbool("profiler.load") then
if core.settings:get_bool("profiler.load") then
profiler = dofile(scriptpath.."profiler"..DIR_DELIM.."init.lua")
end

Expand Down
2 changes: 1 addition & 1 deletion builtin/game/item.lua
Expand Up @@ -483,7 +483,7 @@ function core.node_dig(pos, node, digger)
wielded = wdef.after_use(wielded, digger, node, dp) or wielded
else
-- Wear out tool
if not core.setting_getbool("creative_mode") then
if not core.settings:get_bool("creative_mode") then
wielded:add_wear(dp.wear)
if wielded:get_count() == 0 and wdef.sound and wdef.sound.breaks then
core.sound_play(wdef.sound.breaks, {pos = pos, gain = 0.5})
Expand Down
2 changes: 1 addition & 1 deletion builtin/game/item_entity.lua
Expand Up @@ -14,7 +14,7 @@ end
-- If item_entity_ttl is not set, enity will have default life time
-- Setting it to -1 disables the feature

local time_to_live = tonumber(core.setting_get("item_entity_ttl"))
local time_to_live = tonumber(core.settings:get("item_entity_ttl"))
if not time_to_live then
time_to_live = 900
end
Expand Down
2 changes: 1 addition & 1 deletion builtin/game/misc.lua
Expand Up @@ -121,7 +121,7 @@ function core.get_node_group(name, group)
end

function core.setting_get_pos(name)
local value = core.setting_get(name)
local value = core.settings:get(name)
if not value then
return nil
end
Expand Down
2 changes: 1 addition & 1 deletion builtin/game/statbars.lua
@@ -1,5 +1,5 @@
-- cache setting
local enable_damage = core.setting_getbool("enable_damage") == true
local enable_damage = core.settings:get_bool("enable_damage")

local health_bar_definition =
{
Expand Down
4 changes: 2 additions & 2 deletions builtin/game/static_spawn.lua
@@ -1,10 +1,10 @@
-- Minetest: builtin/static_spawn.lua

local function warn_invalid_static_spawnpoint()
if core.setting_get("static_spawnpoint") and
if core.settings:get("static_spawnpoint") and
not core.setting_get_pos("static_spawnpoint") then
core.log("error", "The static_spawnpoint setting is invalid: \""..
core.setting_get("static_spawnpoint").."\"")
core.settings:get("static_spawnpoint").."\"")
end
end

Expand Down
2 changes: 1 addition & 1 deletion builtin/init.lua
Expand Up @@ -38,7 +38,7 @@ dofile(commonpath .. "misc_helpers.lua")
if INIT == "game" then
dofile(gamepath .. "init.lua")
elseif INIT == "mainmenu" then
local mm_script = core.setting_get("main_menu_script")
local mm_script = core.settings:get("main_menu_script")
if mm_script and mm_script ~= "" then
dofile(mm_script)
else
Expand Down
14 changes: 7 additions & 7 deletions builtin/mainmenu/common.lua
Expand Up @@ -43,10 +43,10 @@ end
local function configure_selected_world_params(idx)
local worldconfig = modmgr.get_worldconfig(menudata.worldlist:get_list()[idx].path)
if worldconfig.creative_mode then
core.setting_set("creative_mode", worldconfig.creative_mode)
core.settings:set("creative_mode", worldconfig.creative_mode)
end
if worldconfig.enable_damage then
core.setting_set("enable_damage", worldconfig.enable_damage)
core.settings:set("enable_damage", worldconfig.enable_damage)
end
end

Expand Down Expand Up @@ -164,8 +164,8 @@ end

--------------------------------------------------------------------------------
os.tempfolder = function()
if core.setting_get("TMPFolder") then
return core.setting_get("TMPFolder") .. DIR_DELIM .. "MT_" .. math.random(0,10000)
if core.settings:get("TMPFolder") then
return core.settings:get("TMPFolder") .. DIR_DELIM .. "MT_" .. math.random(0,10000)
end

local filetocheck = os.tmpname()
Expand Down Expand Up @@ -206,7 +206,7 @@ function menu_handle_key_up_down(fields, textlist, settingname)
oldidx < menudata.worldlist:size() then
newidx = oldidx + 1
end
core.setting_set(settingname, menudata.worldlist:get_raw_index(newidx))
core.settings:set(settingname, menudata.worldlist:get_raw_index(newidx))
configure_selected_world_params(newidx)
return true
end
Expand Down Expand Up @@ -328,9 +328,9 @@ function menu_worldmt_legacy(selected)
for _, mode_name in pairs(modes_names) do
local mode_val = menu_worldmt(selected, mode_name)
if mode_val then
core.setting_set(mode_name, mode_val)
core.settings:set(mode_name, mode_val)
else
menu_worldmt(selected, mode_name, core.setting_get(mode_name))
menu_worldmt(selected, mode_name, core.settings:get(mode_name))
end
end
end
4 changes: 2 additions & 2 deletions builtin/mainmenu/dlg_config_world.lua
Expand Up @@ -123,7 +123,7 @@ local function handle_buttons(this, fields)
if fields["world_config_modlist"] ~= nil then
local event = core.explode_table_event(fields["world_config_modlist"])
this.data.selected_mod = event.row
core.setting_set("world_config_selected_mod", event.row)
core.settings:set("world_config_selected_mod", event.row)

if event.type == "DCL" then
enable_mod(this)
Expand Down Expand Up @@ -227,7 +227,7 @@ function create_configure_world_dlg(worldidx)
handle_buttons,
nil)

dlg.data.selected_mod = tonumber(core.setting_get("world_config_selected_mod"))
dlg.data.selected_mod = tonumber(core.settings:get("world_config_selected_mod"))
if dlg.data.selected_mod == nil then
dlg.data.selected_mod = 0
end
Expand Down
14 changes: 7 additions & 7 deletions builtin/mainmenu/dlg_create_world.lua
Expand Up @@ -18,8 +18,8 @@
local function create_world_formspec(dialogdata)
local mapgens = core.get_mapgen_names()

local current_seed = core.setting_get("fixed_map_seed") or ""
local current_mg = core.setting_get("mg_name")
local current_seed = core.settings:get("fixed_map_seed") or ""
local current_mg = core.settings:get("mg_name")

local mglist = ""
local selindex = 1
Expand All @@ -33,7 +33,7 @@ local function create_world_formspec(dialogdata)
end
mglist = mglist:sub(1, -2)

local gameid = core.setting_get("menu_last_game")
local gameid = core.settings:get("menu_last_game")

local game, gameidx = nil , 0
if gameid ~= nil then
Expand Down Expand Up @@ -90,10 +90,10 @@ local function create_world_buttonhandler(this, fields)

local message = nil

core.setting_set("fixed_map_seed", fields["te_seed"])
core.settings:set("fixed_map_seed", fields["te_seed"])

if not menudata.worldlist:uid_exists_raw(worldname) then
core.setting_set("mg_name",fields["dd_mapgen"])
core.settings:set("mg_name",fields["dd_mapgen"])
message = core.create_world(worldname,gameindex)
else
message = fgettext("A world named \"$1\" already exists", worldname)
Expand All @@ -102,13 +102,13 @@ local function create_world_buttonhandler(this, fields)
if message ~= nil then
gamedata.errormessage = message
else
core.setting_set("menu_last_game",gamemgr.games[gameindex].id)
core.settings:set("menu_last_game",gamemgr.games[gameindex].id)
if this.data.update_worldlist_filter then
menudata.worldlist:set_filtercriteria(gamemgr.games[gameindex].id)
mm_texture.update("singleplayer", gamemgr.games[gameindex].id)
end
menudata.worldlist:refresh()
core.setting_set("mainmenu_last_selected_world",
core.settings:set("mainmenu_last_selected_world",
menudata.worldlist:raw_index_by_uid(worldname))
end
else
Expand Down

0 comments on commit 43d1f37

Please sign in to comment.