diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index fc284c8..1ca4006 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -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 @@ -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 "" diff --git a/builtin/fstk/tabview.lua b/builtin/fstk/tabview.lua index 72551af..3715e23 100644 --- a/builtin/fstk/tabview.lua +++ b/builtin/fstk/tabview.lua @@ -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 diff --git a/builtin/game/auth.lua b/builtin/game/auth.lua index 46fe3d3..8cb4ebf 100644 --- a/builtin/game/auth.lua +++ b/builtin/game/auth.lua @@ -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 @@ -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() @@ -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) diff --git a/builtin/game/chatcommands.lua b/builtin/game/chatcommands.lua index cbf75c1..b792a01 100644 --- a/builtin/game/chatcommands.lua +++ b/builtin/game/chatcommands.lua @@ -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() @@ -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 @@ -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." @@ -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 @@ -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 ' 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 = "" end @@ -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 = @@ -718,7 +718,7 @@ core.register_chatcommand("rollback", { description = "Revert actions of a player. Default for 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*)") diff --git a/builtin/game/deprecated.lua b/builtin/game/deprecated.lua index cd1cf5e..1a9a96f 100644 --- a/builtin/game/deprecated.lua +++ b/builtin/game/deprecated.lua @@ -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") diff --git a/builtin/game/forceloading.lua b/builtin/game/forceloading.lua index 8a05de3..7c5537e 100644 --- a/builtin/game/forceloading.lua +++ b/builtin/game/forceloading.lua @@ -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 diff --git a/builtin/game/init.lua b/builtin/game/init.lua index 3e192a3..e2635f0 100644 --- a/builtin/game/init.lua +++ b/builtin/game/init.lua @@ -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 diff --git a/builtin/game/item.lua b/builtin/game/item.lua index 671a994..e36745f 100644 --- a/builtin/game/item.lua +++ b/builtin/game/item.lua @@ -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}) diff --git a/builtin/game/item_entity.lua b/builtin/game/item_entity.lua index 7b82471..c0e36be 100644 --- a/builtin/game/item_entity.lua +++ b/builtin/game/item_entity.lua @@ -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 diff --git a/builtin/game/misc.lua b/builtin/game/misc.lua index a3eb26a..bfe407b 100644 --- a/builtin/game/misc.lua +++ b/builtin/game/misc.lua @@ -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 diff --git a/builtin/game/statbars.lua b/builtin/game/statbars.lua index 4e7781e..6aa1061 100644 --- a/builtin/game/statbars.lua +++ b/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 = { diff --git a/builtin/game/static_spawn.lua b/builtin/game/static_spawn.lua index 1003342..b1157b4 100644 --- a/builtin/game/static_spawn.lua +++ b/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 diff --git a/builtin/init.lua b/builtin/init.lua index c9fa70f..356e119 100644 --- a/builtin/init.lua +++ b/builtin/init.lua @@ -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 diff --git a/builtin/mainmenu/common.lua b/builtin/mainmenu/common.lua index 57950c6..294e1a6 100644 --- a/builtin/mainmenu/common.lua +++ b/builtin/mainmenu/common.lua @@ -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 @@ -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() @@ -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 @@ -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 diff --git a/builtin/mainmenu/dlg_config_world.lua b/builtin/mainmenu/dlg_config_world.lua index 619c927..3e5ba16 100644 --- a/builtin/mainmenu/dlg_config_world.lua +++ b/builtin/mainmenu/dlg_config_world.lua @@ -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) @@ -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 diff --git a/builtin/mainmenu/dlg_create_world.lua b/builtin/mainmenu/dlg_create_world.lua index 477b8bc..e9ca779 100644 --- a/builtin/mainmenu/dlg_create_world.lua +++ b/builtin/mainmenu/dlg_create_world.lua @@ -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 @@ -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 @@ -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) @@ -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 diff --git a/builtin/mainmenu/dlg_settings_advanced.lua b/builtin/mainmenu/dlg_settings_advanced.lua index c63eb97..206ce16 100644 --- a/builtin/mainmenu/dlg_settings_advanced.lua +++ b/builtin/mainmenu/dlg_settings_advanced.lua @@ -423,7 +423,7 @@ local settings = full_settings local selected_setting = 1 local function get_current_value(setting) - local value = core.setting_get(setting.name) + local value = core.settings:get(setting.name) if value == nil then value = setting.default end @@ -539,11 +539,11 @@ local function handle_change_setting_buttons(this, fields) if setting.type == "bool" then local new_value = fields["dd_setting_value"] -- Note: new_value is the actual (translated) value shown in the dropdown - core.setting_setbool(setting.name, new_value == fgettext("Enabled")) + core.settings:set_bool(setting.name, new_value == fgettext("Enabled")) elseif setting.type == "enum" then local new_value = fields["dd_setting_value"] - core.setting_set(setting.name, new_value) + core.settings:set(setting.name, new_value) elseif setting.type == "int" then local new_value = tonumber(fields["te_setting_value"]) @@ -565,7 +565,7 @@ local function handle_change_setting_buttons(this, fields) core.update_formspec(this:get_formspec()) return true end - core.setting_set(setting.name, new_value) + core.settings:set(setting.name, new_value) elseif setting.type == "float" then local new_value = tonumber(fields["te_setting_value"]) @@ -575,7 +575,7 @@ local function handle_change_setting_buttons(this, fields) core.update_formspec(this:get_formspec()) return true end - core.setting_set(setting.name, new_value) + core.settings:set(setting.name, new_value) elseif setting.type == "flags" then local new_value = fields["te_setting_value"] @@ -589,13 +589,13 @@ local function handle_change_setting_buttons(this, fields) return true end end - core.setting_set(setting.name, new_value) + core.settings:set(setting.name, new_value) else local new_value = fields["te_setting_value"] - core.setting_set(setting.name, new_value) + core.settings:set(setting.name, new_value) end - core.setting_save() + core.settings:write() this:delete() return true end @@ -629,7 +629,7 @@ local function create_settings_formspec(tabview, name, tabdata) local current_level = 0 for _, entry in ipairs(settings) do local name - if not core.setting_getbool("main_menu_technical_settings") and entry.readable_name then + if not core.settings:get_bool("main_menu_technical_settings") and entry.readable_name then name = fgettext_ne(entry.readable_name) else name = entry.name @@ -666,7 +666,7 @@ local function create_settings_formspec(tabview, name, tabdata) "button[10,6;2,1;btn_edit;" .. fgettext("Edit") .. "]" .. "button[7,6;3,1;btn_restore;" .. fgettext("Restore Default") .. "]" .. "checkbox[0,5.3;cb_tech_settings;" .. fgettext("Show technical names") .. ";" - .. dump(core.setting_getbool("main_menu_technical_settings")) .. "]" + .. dump(core.settings:get_bool("main_menu_technical_settings")) .. "]" return formspec end @@ -680,8 +680,8 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) local setting = settings[selected_setting] if setting and setting.type == "bool" then local current_value = get_current_value(setting) - core.setting_setbool(setting.name, not core.is_yes(current_value)) - core.setting_save() + core.settings:set_bool(setting.name, not core.is_yes(current_value)) + core.settings:write() return true else list_enter = true @@ -736,8 +736,8 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) if fields["btn_restore"] then local setting = settings[selected_setting] if setting and setting.type ~= "category" then - core.setting_set(setting.name, setting.default) - core.setting_save() + core.settings:set(setting.name, setting.default) + core.settings:write() core.update_formspec(this:get_formspec()) end return true @@ -749,8 +749,8 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) end if fields["cb_tech_settings"] then - core.setting_set("main_menu_technical_settings", fields["cb_tech_settings"]) - core.setting_save() + core.settings:set("main_menu_technical_settings", fields["cb_tech_settings"]) + core.settings:write() core.update_formspec(this:get_formspec()) return true end diff --git a/builtin/mainmenu/init.lua b/builtin/mainmenu/init.lua index 79e6d5c..492bb22 100644 --- a/builtin/mainmenu/init.lua +++ b/builtin/mainmenu/init.lua @@ -119,9 +119,9 @@ local function init_globals() menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic) menudata.worldlist:set_sortmode("alphabetic") - if not core.setting_get("menu_last_game") then - local default_game = core.setting_get("default_game") or "minetest" - core.setting_set("menu_last_game", default_game) + if not core.settings:get("menu_last_game") then + local default_game = core.settings:get("default_game") or "minetest" + core.settings:set("menu_last_game", default_game) end mm_texture.init() @@ -149,7 +149,7 @@ local function init_globals() tv_main:set_fixed_size(false) if PLATFORM ~= "Android" then - tv_main:set_tab(core.setting_get("maintab_LAST")) + tv_main:set_tab(core.settings:get("maintab_LAST")) end ui.set_default("maintab") tv_main:show() diff --git a/builtin/mainmenu/store.lua b/builtin/mainmenu/store.lua index ad86108..59391f8 100644 --- a/builtin/mainmenu/store.lua +++ b/builtin/mainmenu/store.lua @@ -233,14 +233,14 @@ function modstore.handle_buttons(parent, fields, name, data) if not core.handle_async( function(param) - local fullurl = core.setting_get("modstore_download_url") .. + local fullurl = core.settings:get("modstore_download_url") .. param.moddetails.download_url if param.version ~= nil then local found = false for i=1,#param.moddetails.versions, 1 do if param.moddetails.versions[i].date:sub(1,10) == param.version then - fullurl = core.setting_get("modstore_download_url") .. + fullurl = core.settings:get("modstore_download_url") .. param.moddetails.versions[i].download_url found = true end @@ -400,7 +400,7 @@ function modstore.getscreenshot(ypos,listentry) listentry.texturename = "in progress" --prepare url and filename - local fullurl = core.setting_get("modstore_download_url") .. + local fullurl = core.settings:get("modstore_download_url") .. listentry.details.screenshot_url local filename = os.tempfolder() .. "_MID_" .. listentry.id diff --git a/builtin/mainmenu/tab_multiplayer.lua b/builtin/mainmenu/tab_multiplayer.lua index 0f4921b..a9b2b35 100644 --- a/builtin/mainmenu/tab_multiplayer.lua +++ b/builtin/mainmenu/tab_multiplayer.lua @@ -39,14 +39,14 @@ local function get_formspec(tabview, name, tabdata) -- Address / Port "label[7.75,-0.25;" .. fgettext("Address / Port") .. "]" .. "field[8,0.65;3.25,0.5;te_address;;" .. - core.formspec_escape(core.setting_get("address")) .. "]" .. + core.formspec_escape(core.settings:get("address")) .. "]" .. "field[11.1,0.65;1.4,0.5;te_port;;" .. - core.formspec_escape(core.setting_get("remote_port")) .. "]" .. + core.formspec_escape(core.settings:get("remote_port")) .. "]" .. -- Name / Password "label[7.75,0.95;" .. fgettext("Name / Password") .. "]" .. "field[8,1.85;2.9,0.5;te_name;;" .. - core.formspec_escape(core.setting_get("name")) .. "]" .. + core.formspec_escape(core.settings:get("name")) .. "]" .. "pwdfield[10.73,1.85;1.77,0.5;te_pwd;]" .. -- Description Background @@ -135,7 +135,7 @@ local function main_button_handler(tabview, fields, name, tabdata) if fields.te_name then gamedata.playername = fields.te_name - core.setting_set("name", fields.te_name) + core.settings:set("name", fields.te_name) end if fields.favourites then @@ -163,8 +163,8 @@ local function main_button_handler(tabview, fields, name, tabdata) gamedata.serverdescription = fav.description if gamedata.address and gamedata.port then - core.setting_set("address", gamedata.address) - core.setting_set("remote_port", gamedata.port) + core.settings:set("address", gamedata.address) + core.settings:set("remote_port", gamedata.port) core.start() end end @@ -187,8 +187,8 @@ local function main_button_handler(tabview, fields, name, tabdata) end if address and port then - core.setting_set("address", address) - core.setting_set("remote_port", port) + core.settings:set("address", address) + core.settings:set("remote_port", port) end tabdata.fav_selected = event.row end @@ -219,8 +219,8 @@ local function main_button_handler(tabview, fields, name, tabdata) local port = fav.port gamedata.serverdescription = fav.description if address and port then - core.setting_set("address", address) - core.setting_set("remote_port", port) + core.settings:set("address", address) + core.settings:set("remote_port", port) end tabdata.fav_selected = fav_idx @@ -235,8 +235,8 @@ local function main_button_handler(tabview, fields, name, tabdata) asyncOnlineFavourites() tabdata.fav_selected = nil - core.setting_set("address", "") - core.setting_set("remote_port", "30000") + core.settings:set("address", "") + core.settings:set("remote_port", "30000") return true end @@ -293,8 +293,8 @@ local function main_button_handler(tabview, fields, name, tabdata) end) menudata.search_result = search_result local first_server = search_result[1] - core.setting_set("address", first_server.address) - core.setting_set("remote_port", first_server.port) + core.settings:set("address", first_server.address) + core.settings:set("remote_port", first_server.port) end return true end @@ -325,8 +325,8 @@ local function main_button_handler(tabview, fields, name, tabdata) gamedata.serverdescription = "" end - core.setting_set("address", fields.te_address) - core.setting_set("remote_port", fields.te_port) + core.settings:set("address", fields.te_address) + core.settings:set("remote_port", fields.te_port) core.start() return true diff --git a/builtin/mainmenu/tab_server.lua b/builtin/mainmenu/tab_server.lua index be57ad7..8f25ce8 100644 --- a/builtin/mainmenu/tab_server.lua +++ b/builtin/mainmenu/tab_server.lua @@ -19,7 +19,7 @@ local function get_formspec(tabview, name, tabdata) local index = menudata.worldlist:get_current_index( - tonumber(core.setting_get("mainmenu_last_selected_world")) + tonumber(core.settings:get("mainmenu_last_selected_world")) ) local retval = @@ -29,29 +29,29 @@ local function get_formspec(tabview, name, tabdata) "button[8.5,5;3.25,0.5;start_server;" .. fgettext("Start Game") .. "]" .. "label[4,-0.25;" .. fgettext("Select World:") .. "]" .. "checkbox[0.25,0.25;cb_creative_mode;" .. fgettext("Creative Mode") .. ";" .. - dump(core.setting_getbool("creative_mode")) .. "]" .. + dump(core.settings:get_bool("creative_mode")) .. "]" .. "checkbox[0.25,0.7;cb_enable_damage;" .. fgettext("Enable Damage") .. ";" .. - dump(core.setting_getbool("enable_damage")) .. "]" .. + dump(core.settings:get_bool("enable_damage")) .. "]" .. "checkbox[0.25,1.15;cb_server_announce;" .. fgettext("Public") .. ";" .. - dump(core.setting_getbool("server_announce")) .. "]" .. + dump(core.settings:get_bool("server_announce")) .. "]" .. "label[0.25,2.2;" .. fgettext("Name/Password") .. "]" .. "field[0.55,3.2;3.5,0.5;te_playername;;" .. - core.formspec_escape(core.setting_get("name")) .. "]" .. + core.formspec_escape(core.settings:get("name")) .. "]" .. "pwdfield[0.55,4;3.5,0.5;te_passwd;]" - local bind_addr = core.setting_get("bind_address") + local bind_addr = core.settings:get("bind_address") if bind_addr ~= nil and bind_addr ~= "" then retval = retval .. "field[0.55,5.2;2.25,0.5;te_serveraddr;" .. fgettext("Bind Address") .. ";" .. - core.formspec_escape(core.setting_get("bind_address")) .. "]" .. + core.formspec_escape(core.settings:get("bind_address")) .. "]" .. "field[2.8,5.2;1.25,0.5;te_serverport;" .. fgettext("Port") .. ";" .. - core.formspec_escape(core.setting_get("port")) .. "]" + core.formspec_escape(core.settings:get("port")) .. "]" else retval = retval .. "field[0.55,5.2;3.5,0.5;te_serverport;" .. fgettext("Server Port") .. ";" .. - core.formspec_escape(core.setting_get("port")) .. "]" + core.formspec_escape(core.settings:get("port")) .. "]" end - + retval = retval .. "textlist[4,0.25;7.5,3.7;srv_worlds;" .. menu_render_worldlist() .. @@ -75,7 +75,7 @@ local function main_button_handler(this, fields, name, tabdata) world_doubleclick = true end if event.type == "CHG" then - core.setting_set("mainmenu_last_selected_world", + core.settings:set("mainmenu_last_selected_world", menudata.worldlist:get_raw_index(core.get_textlist_index("srv_worlds"))) return true end @@ -86,7 +86,7 @@ local function main_button_handler(this, fields, name, tabdata) end if fields["cb_creative_mode"] then - core.setting_set("creative_mode", fields["cb_creative_mode"]) + core.settings:set("creative_mode", fields["cb_creative_mode"]) local selected = core.get_textlist_index("srv_worlds") menu_worldmt(selected, "creative_mode", fields["cb_creative_mode"]) @@ -94,7 +94,7 @@ local function main_button_handler(this, fields, name, tabdata) end if fields["cb_enable_damage"] then - core.setting_set("enable_damage", fields["cb_enable_damage"]) + core.settings:set("enable_damage", fields["cb_enable_damage"]) local selected = core.get_textlist_index("srv_worlds") menu_worldmt(selected, "enable_damage", fields["cb_enable_damage"]) @@ -102,7 +102,7 @@ local function main_button_handler(this, fields, name, tabdata) end if fields["cb_server_announce"] then - core.setting_set("server_announce", fields["cb_server_announce"]) + core.settings:set("server_announce", fields["cb_server_announce"]) local selected = core.get_textlist_index("srv_worlds") menu_worldmt(selected, "server_announce", fields["cb_server_announce"]) @@ -120,16 +120,16 @@ local function main_button_handler(this, fields, name, tabdata) gamedata.port = fields["te_serverport"] gamedata.address = "" - core.setting_set("port",gamedata.port) + core.settings:set("port",gamedata.port) if fields["te_serveraddr"] ~= nil then - core.setting_set("bind_address",fields["te_serveraddr"]) + core.settings:set("bind_address",fields["te_serveraddr"]) end --update last game local world = menudata.worldlist:get_raw_element(gamedata.selected_world) if world then local game, index = gamemgr.find_by_gameid(world.gameid) - core.setting_set("menu_last_game", game.id) + core.settings:set("menu_last_game", game.id) end core.start() diff --git a/builtin/mainmenu/tab_settings.lua b/builtin/mainmenu/tab_settings.lua index 8a97d83..69683ea 100644 --- a/builtin/mainmenu/tab_settings.lua +++ b/builtin/mainmenu/tab_settings.lua @@ -70,39 +70,39 @@ local dd_options = { local getSettingIndex = { Leaves = function() - local style = core.setting_get("leaves_style") + local style = core.settings:get("leaves_style") for idx, name in pairs(dd_options.leaves[2]) do if style == name then return idx end end return 1 end, NodeHighlighting = function() - local style = core.setting_get("node_highlighting") + local style = core.settings:get("node_highlighting") for idx, name in pairs(dd_options.node_highlighting[2]) do if style == name then return idx end end return 1 end, Filter = function() - if core.setting_get(dd_options.filters[2][3]) == "true" then + if core.settings:get(dd_options.filters[2][3]) == "true" then return 3 - elseif core.setting_get(dd_options.filters[2][3]) == "false" and - core.setting_get(dd_options.filters[2][2]) == "true" then + elseif core.settings:get(dd_options.filters[2][3]) == "false" and + core.settings:get(dd_options.filters[2][2]) == "true" then return 2 end return 1 end, Mipmap = function() - if core.setting_get(dd_options.mipmap[2][3]) == "true" then + if core.settings:get(dd_options.mipmap[2][3]) == "true" then return 3 - elseif core.setting_get(dd_options.mipmap[2][3]) == "false" and - core.setting_get(dd_options.mipmap[2][2]) == "true" then + elseif core.settings:get(dd_options.mipmap[2][3]) == "false" and + core.settings:get(dd_options.mipmap[2][2]) == "true" then return 2 end return 1 end, Antialiasing = function() - local antialiasing_setting = core.setting_get("fsaa") + local antialiasing_setting = core.settings:get("fsaa") for i = 1, #dd_options.antialiasing[2] do if antialiasing_setting == dd_options.antialiasing[2][i] then return i @@ -177,15 +177,15 @@ local function formspec(tabview, name, tabdata) local tab_string = "box[0,0;3.5,4.5;#999999]" .. "checkbox[0.25,0;cb_smooth_lighting;" .. fgettext("Smooth Lighting") .. ";" - .. dump(core.setting_getbool("smooth_lighting")) .. "]" .. + .. dump(core.settings:get_bool("smooth_lighting")) .. "]" .. "checkbox[0.25,0.5;cb_particles;" .. fgettext("Particles") .. ";" - .. dump(core.setting_getbool("enable_particles")) .. "]" .. + .. dump(core.settings:get_bool("enable_particles")) .. "]" .. "checkbox[0.25,1;cb_3d_clouds;" .. fgettext("3D Clouds") .. ";" - .. dump(core.setting_getbool("enable_3d_clouds")) .. "]" .. + .. dump(core.settings:get_bool("enable_3d_clouds")) .. "]" .. "checkbox[0.25,1.5;cb_opaque_water;" .. fgettext("Opaque Water") .. ";" - .. dump(core.setting_getbool("opaque_water")) .. "]" .. + .. dump(core.settings:get_bool("opaque_water")) .. "]" .. "checkbox[0.25,2.0;cb_connected_glass;" .. fgettext("Connected Glass") .. ";" - .. dump(core.setting_getbool("connected_glass")) .. "]" .. + .. dump(core.settings:get_bool("connected_glass")) .. "]" .. "dropdown[0.25,2.8;3.3;dd_node_highlighting;" .. dd_options.node_highlighting[1] .. ";" .. getSettingIndex.NodeHighlighting() .. "]" .. "dropdown[0.25,3.6;3.3;dd_leaves_style;" .. dd_options.leaves[1] .. ";" @@ -201,10 +201,10 @@ local function formspec(tabview, name, tabdata) .. getSettingIndex.Antialiasing() .. "]" .. "label[3.85,3.45;" .. fgettext("Screen:") .. "]" .. "checkbox[3.85,3.6;cb_autosave_screensize;" .. fgettext("Autosave screen size") .. ";" - .. dump(core.setting_getbool("autosave_screensize")) .. "]" .. + .. dump(core.settings:get_bool("autosave_screensize")) .. "]" .. "box[7.75,0;4,4.4;#999999]" .. "checkbox[8,0;cb_shaders;" .. fgettext("Shaders") .. ";" - .. dump(core.setting_getbool("enable_shaders")) .. "]" + .. dump(core.settings:get_bool("enable_shaders")) .. "]" if PLATFORM == "Android" then tab_string = tab_string .. @@ -221,29 +221,29 @@ local function formspec(tabview, name, tabdata) .. fgettext("Advanced Settings") .. "]" - if core.setting_get("touchscreen_threshold") ~= nil then + if core.settings:get("touchscreen_threshold") ~= nil then tab_string = tab_string .. "label[4.3,4.1;" .. fgettext("Touchthreshold (px)") .. "]" .. "dropdown[3.85,4.55;3.85;dd_touchthreshold;0,10,20,30,40,50;" .. - ((tonumber(core.setting_get("touchscreen_threshold")) / 10) + 1) .. "]" + ((tonumber(core.settings:get("touchscreen_threshold")) / 10) + 1) .. "]" end - if core.setting_getbool("enable_shaders") then + if core.settings:get_bool("enable_shaders") then tab_string = tab_string .. "checkbox[8,0.5;cb_bumpmapping;" .. fgettext("Bump Mapping") .. ";" - .. dump(core.setting_getbool("enable_bumpmapping")) .. "]" .. + .. dump(core.settings:get_bool("enable_bumpmapping")) .. "]" .. "checkbox[8,1;cb_tonemapping;" .. fgettext("Tone Mapping") .. ";" - .. dump(core.setting_getbool("tone_mapping")) .. "]" .. + .. dump(core.settings:get_bool("tone_mapping")) .. "]" .. "checkbox[8,1.5;cb_generate_normalmaps;" .. fgettext("Normal Mapping") .. ";" - .. dump(core.setting_getbool("generate_normalmaps")) .. "]" .. + .. dump(core.settings:get_bool("generate_normalmaps")) .. "]" .. "checkbox[8,2;cb_parallax;" .. fgettext("Parallax Occlusion") .. ";" - .. dump(core.setting_getbool("enable_parallax_occlusion")) .. "]" .. + .. dump(core.settings:get_bool("enable_parallax_occlusion")) .. "]" .. "checkbox[8,2.5;cb_waving_water;" .. fgettext("Waving Water") .. ";" - .. dump(core.setting_getbool("enable_waving_water")) .. "]" .. + .. dump(core.settings:get_bool("enable_waving_water")) .. "]" .. "checkbox[8,3;cb_waving_leaves;" .. fgettext("Waving Leaves") .. ";" - .. dump(core.setting_getbool("enable_waving_leaves")) .. "]" .. + .. dump(core.settings:get_bool("enable_waving_leaves")) .. "]" .. "checkbox[8,3.5;cb_waving_plants;" .. fgettext("Waving Plants") .. ";" - .. dump(core.setting_getbool("enable_waving_plants")) .. "]" + .. dump(core.settings:get_bool("enable_waving_plants")) .. "]" else tab_string = tab_string .. "tablecolumns[color;text]" .. @@ -274,64 +274,64 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) return true end if fields["cb_smooth_lighting"] then - core.setting_set("smooth_lighting", fields["cb_smooth_lighting"]) + core.settings:set("smooth_lighting", fields["cb_smooth_lighting"]) return true end if fields["cb_particles"] then - core.setting_set("enable_particles", fields["cb_particles"]) + core.settings:set("enable_particles", fields["cb_particles"]) return true end if fields["cb_3d_clouds"] then - core.setting_set("enable_3d_clouds", fields["cb_3d_clouds"]) + core.settings:set("enable_3d_clouds", fields["cb_3d_clouds"]) return true end if fields["cb_opaque_water"] then - core.setting_set("opaque_water", fields["cb_opaque_water"]) + core.settings:set("opaque_water", fields["cb_opaque_water"]) return true end if fields["cb_connected_glass"] then - core.setting_set("connected_glass", fields["cb_connected_glass"]) + core.settings:set("connected_glass", fields["cb_connected_glass"]) return true end if fields["cb_autosave_screensize"] then - core.setting_set("autosave_screensize", fields["cb_autosave_screensize"]) + core.settings:set("autosave_screensize", fields["cb_autosave_screensize"]) return true end if fields["cb_shaders"] then - if (core.setting_get("video_driver") == "direct3d8" or - core.setting_get("video_driver") == "direct3d9") then - core.setting_set("enable_shaders", "false") + if (core.settings:get("video_driver") == "direct3d8" or + core.settings:get("video_driver") == "direct3d9") then + core.settings:set("enable_shaders", "false") gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.") else - core.setting_set("enable_shaders", fields["cb_shaders"]) + core.settings:set("enable_shaders", fields["cb_shaders"]) end return true end if fields["cb_bumpmapping"] then - core.setting_set("enable_bumpmapping", fields["cb_bumpmapping"]) + core.settings:set("enable_bumpmapping", fields["cb_bumpmapping"]) return true end if fields["cb_tonemapping"] then - core.setting_set("tone_mapping", fields["cb_tonemapping"]) + core.settings:set("tone_mapping", fields["cb_tonemapping"]) return true end if fields["cb_generate_normalmaps"] then - core.setting_set("generate_normalmaps", fields["cb_generate_normalmaps"]) + core.settings:set("generate_normalmaps", fields["cb_generate_normalmaps"]) return true end if fields["cb_parallax"] then - core.setting_set("enable_parallax_occlusion", fields["cb_parallax"]) + core.settings:set("enable_parallax_occlusion", fields["cb_parallax"]) return true end if fields["cb_waving_water"] then - core.setting_set("enable_waving_water", fields["cb_waving_water"]) + core.settings:set("enable_waving_water", fields["cb_waving_water"]) return true end if fields["cb_waving_leaves"] then - core.setting_set("enable_waving_leaves", fields["cb_waving_leaves"]) + core.settings:set("enable_waving_leaves", fields["cb_waving_leaves"]) end if fields["cb_waving_plants"] then - core.setting_set("enable_waving_plants", fields["cb_waving_plants"]) + core.settings:set("enable_waving_plants", fields["cb_waving_plants"]) return true end if fields["btn_change_keys"] then @@ -339,7 +339,7 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) return true end if fields["cb_touchscreen_target"] then - core.setting_set("touchtarget", fields["cb_touchscreen_target"]) + core.settings:set("touchtarget", fields["cb_touchscreen_target"]) return true end if fields["btn_reset_singleplayer"] then @@ -352,49 +352,49 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) for i = 1, #labels.leaves do if fields["dd_leaves_style"] == labels.leaves[i] then - core.setting_set("leaves_style", dd_options.leaves[2][i]) + core.settings:set("leaves_style", dd_options.leaves[2][i]) ddhandled = true end end for i = 1, #labels.node_highlighting do if fields["dd_node_highlighting"] == labels.node_highlighting[i] then - core.setting_set("node_highlighting", dd_options.node_highlighting[2][i]) + core.settings:set("node_highlighting", dd_options.node_highlighting[2][i]) ddhandled = true end end if fields["dd_filters"] == labels.filters[1] then - core.setting_set("bilinear_filter", "false") - core.setting_set("trilinear_filter", "false") + core.settings:set("bilinear_filter", "false") + core.settings:set("trilinear_filter", "false") ddhandled = true elseif fields["dd_filters"] == labels.filters[2] then - core.setting_set("bilinear_filter", "true") - core.setting_set("trilinear_filter", "false") + core.settings:set("bilinear_filter", "true") + core.settings:set("trilinear_filter", "false") ddhandled = true elseif fields["dd_filters"] == labels.filters[3] then - core.setting_set("bilinear_filter", "false") - core.setting_set("trilinear_filter", "true") + core.settings:set("bilinear_filter", "false") + core.settings:set("trilinear_filter", "true") ddhandled = true end if fields["dd_mipmap"] == labels.mipmap[1] then - core.setting_set("mip_map", "false") - core.setting_set("anisotropic_filter", "false") + core.settings:set("mip_map", "false") + core.settings:set("anisotropic_filter", "false") ddhandled = true elseif fields["dd_mipmap"] == labels.mipmap[2] then - core.setting_set("mip_map", "true") - core.setting_set("anisotropic_filter", "false") + core.settings:set("mip_map", "true") + core.settings:set("anisotropic_filter", "false") ddhandled = true elseif fields["dd_mipmap"] == labels.mipmap[3] then - core.setting_set("mip_map", "true") - core.setting_set("anisotropic_filter", "true") + core.settings:set("mip_map", "true") + core.settings:set("anisotropic_filter", "true") ddhandled = true end if fields["dd_antialiasing"] then - core.setting_set("fsaa", + core.settings:set("fsaa", antialiasing_fname_to_name(fields["dd_antialiasing"])) ddhandled = true end if fields["dd_touchthreshold"] then - core.setting_set("touchscreen_threshold", fields["dd_touchthreshold"]) + core.settings:set("touchscreen_threshold", fields["dd_touchthreshold"]) ddhandled = true end diff --git a/builtin/mainmenu/tab_simple_main.lua b/builtin/mainmenu/tab_simple_main.lua index 23820aa..90a743f 100644 --- a/builtin/mainmenu/tab_simple_main.lua +++ b/builtin/mainmenu/tab_simple_main.lua @@ -25,12 +25,12 @@ local function get_formspec(tabview, name, tabdata) local retval = "label[9.5,0;".. fgettext("Name / Password") .. "]" .. "field[0.25,3.35;5.5,0.5;te_address;;" .. - core.formspec_escape(core.setting_get("address")) .."]" .. + core.formspec_escape(core.settings:get("address")) .."]" .. "field[5.75,3.35;2.25,0.5;te_port;;" .. - core.formspec_escape(core.setting_get("remote_port")) .."]" .. + core.formspec_escape(core.settings:get("remote_port")) .."]" .. "button[10,2.6;2,1.5;btn_mp_connect;".. fgettext("Connect") .. "]" .. "field[9.8,1;2.6,0.5;te_name;;" .. - core.formspec_escape(core.setting_get("name")) .."]" .. + core.formspec_escape(core.settings:get("name")) .."]" .. "pwdfield[9.8,2;2.6,0.5;te_pwd;]" @@ -89,9 +89,9 @@ local function get_formspec(tabview, name, tabdata) -- checkboxes retval = retval .. "checkbox[8.0,3.9;cb_creative;".. fgettext("Creative Mode") .. ";" .. - dump(core.setting_getbool("creative_mode")) .. "]".. + dump(core.settings:get_bool("creative_mode")) .. "]".. "checkbox[8.0,4.4;cb_damage;".. fgettext("Enable Damage") .. ";" .. - dump(core.setting_getbool("enable_damage")) .. "]" + dump(core.settings:get_bool("enable_damage")) .. "]" -- buttons retval = retval .. "button[0,3.7;8,1.5;btn_start_singleplayer;" .. fgettext("Start Singleplayer") .. "]" .. @@ -128,8 +128,8 @@ local function main_button_handler(tabview, fields, name, tabdata) end if address and port then - core.setting_set("address", address) - core.setting_set("remote_port", port) + core.settings:set("address", address) + core.settings:set("remote_port", port) end tabdata.fav_selected = event.row end @@ -145,18 +145,18 @@ local function main_button_handler(tabview, fields, name, tabdata) asyncOnlineFavourites() tabdata.fav_selected = nil - core.setting_set("address", "") - core.setting_set("remote_port", "30000") + core.settings:set("address", "") + core.settings:set("remote_port", "30000") return true end if fields.cb_creative then - core.setting_set("creative_mode", fields.cb_creative) + core.settings:set("creative_mode", fields.cb_creative) return true end if fields.cb_damage then - core.setting_set("enable_damage", fields.cb_damage) + core.settings:set("enable_damage", fields.cb_damage) return true end @@ -186,12 +186,8 @@ local function main_button_handler(tabview, fields, name, tabdata) gamedata.selected_world = 0 - core.setting_set("address", fields.te_address) - core.setting_set("remote_port", fields.te_port) - - core.start() - return true - end + core.settings:set("address", fields.te_address) + core.settings:set("remote_port", fields.te_port) if fields.btn_config_sp_world then local configdialog = create_configure_world_dlg(1) diff --git a/builtin/mainmenu/tab_singleplayer.lua b/builtin/mainmenu/tab_singleplayer.lua index 236de76..c58ad41 100644 --- a/builtin/mainmenu/tab_singleplayer.lua +++ b/builtin/mainmenu/tab_singleplayer.lua @@ -16,7 +16,7 @@ --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. local function current_game() - local last_game_id = core.setting_get("menu_last_game") + local last_game_id = core.settings:get("menu_last_game") local game, index = gamemgr.find_by_gameid(last_game_id) return game @@ -36,10 +36,10 @@ local function singleplayer_refresh_gamebar() if ("game_btnbar_" .. gamemgr.games[j].id == key) then mm_texture.update("singleplayer", gamemgr.games[j]) core.set_topleft_text(gamemgr.games[j].name) - core.setting_set("menu_last_game",gamemgr.games[j].id) + core.settings:set("menu_last_game",gamemgr.games[j].id) menudata.worldlist:set_filtercriteria(gamemgr.games[j].id) local index = filterlist.get_current_index(menudata.worldlist, - tonumber(core.setting_get("mainmenu_last_selected_world"))) + tonumber(core.settings:get("mainmenu_last_selected_world"))) if not index or index < 1 then local selected = core.get_textlist_index("sp_worlds") if selected ~= nil and selected < #menudata.worldlist:get_list() then @@ -89,7 +89,7 @@ local function get_formspec(tabview, name, tabdata) local retval = "" local index = filterlist.get_current_index(menudata.worldlist, - tonumber(core.setting_get("mainmenu_last_selected_world")) + tonumber(core.settings:get("mainmenu_last_selected_world")) ) retval = retval .. @@ -99,9 +99,9 @@ local function get_formspec(tabview, name, tabdata) "button[8.5,5;3.25,0.5;play;".. fgettext("Play") .. "]" .. "label[4,-0.25;".. fgettext("Select World:") .. "]".. "checkbox[0.25,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" .. - dump(core.setting_getbool("creative_mode")) .. "]".. + dump(core.settings:get_bool("creative_mode")) .. "]".. "checkbox[0.25,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" .. - dump(core.setting_getbool("enable_damage")) .. "]".. + dump(core.settings:get_bool("enable_damage")) .. "]".. "textlist[4,0.25;7.5,3.7;sp_worlds;" .. menu_render_worldlist() .. ";" .. index .. "]" @@ -125,7 +125,7 @@ local function main_button_handler(this, fields, name, tabdata) end if event.type == "CHG" and selected ~= nil then - core.setting_set("mainmenu_last_selected_world", + core.settings:set("mainmenu_last_selected_world", menudata.worldlist:get_raw_index(selected)) return true end @@ -136,7 +136,7 @@ local function main_button_handler(this, fields, name, tabdata) end if fields["cb_creative_mode"] then - core.setting_set("creative_mode", fields["cb_creative_mode"]) + core.settings:set("creative_mode", fields["cb_creative_mode"]) local selected = core.get_textlist_index("sp_worlds") menu_worldmt(selected, "creative_mode", fields["cb_creative_mode"]) @@ -144,7 +144,7 @@ local function main_button_handler(this, fields, name, tabdata) end if fields["cb_enable_damage"] then - core.setting_set("enable_damage", fields["cb_enable_damage"]) + core.settings:set("enable_damage", fields["cb_enable_damage"]) local selected = core.get_textlist_index("sp_worlds") menu_worldmt(selected, "enable_damage", fields["cb_enable_damage"]) diff --git a/builtin/mainmenu/tab_texturepacks.lua b/builtin/mainmenu/tab_texturepacks.lua index 4638bea..2957481 100644 --- a/builtin/mainmenu/tab_texturepacks.lua +++ b/builtin/mainmenu/tab_texturepacks.lua @@ -54,9 +54,9 @@ local function get_formspec(tabview, name, tabdata) local retval = "label[4,-0.25;" .. fgettext("Select texture pack:") .. "]" .. "textlist[4,0.25;7.5,5.0;TPs;" - local current_texture_path = core.setting_get("texture_path") + local current_texture_path = core.settings:get("texture_path") local list = filter_texture_pack_list(core.get_dir_list(core.get_texturepath(), true)) - local index = tonumber(core.setting_get("mainmenu_last_selected_TP")) + local index = tonumber(core.settings:get("mainmenu_last_selected_TP")) if not index then index = 1 end @@ -106,7 +106,7 @@ local function main_button_handler(tabview, fields, name, tabdata) local event = core.explode_textlist_event(fields["TPs"]) if event.type == "CHG" or event.type == "DCL" then local index = core.get_textlist_index("TPs") - core.setting_set("mainmenu_last_selected_TP", index) + core.settings:set("mainmenu_last_selected_TP", index) local list = filter_texture_pack_list(core.get_dir_list(core.get_texturepath(), true)) local current_index = core.get_textlist_index("TPs") if current_index and #list >= current_index then @@ -114,7 +114,7 @@ local function main_button_handler(tabview, fields, name, tabdata) if list[current_index] == fgettext("None") then new_path = "" end - core.setting_set("texture_path", new_path) + core.settings:set("texture_path", new_path) end end return true diff --git a/builtin/mainmenu/textures.lua b/builtin/mainmenu/textures.lua index dadbb09..9ba4ade 100644 --- a/builtin/mainmenu/textures.lua +++ b/builtin/mainmenu/textures.lua @@ -24,7 +24,7 @@ function mm_texture.init() DIR_DELIM .. "pack" .. DIR_DELIM mm_texture.basetexturedir = mm_texture.defaulttexturedir - mm_texture.texturepack = core.setting_get("texture_path") + mm_texture.texturepack = core.settings:get("texture_path") mm_texture.gameid = nil end @@ -61,7 +61,7 @@ function mm_texture.reset() mm_texture.set_generic("header") if not have_bg then - if core.setting_getbool("menu_clouds") then + if core.settings:get_bool("menu_clouds") then core.set_clouds(true) else mm_texture.set_dirt_bg() @@ -88,7 +88,7 @@ function mm_texture.update_game(gamedetails) if not have_bg then - if core.setting_getbool("menu_clouds") then + if core.settings:get_bool("menu_clouds") then core.set_clouds(true) else mm_texture.set_dirt_bg() diff --git a/builtin/profiler/init.lua b/builtin/profiler/init.lua index c1597d2..8749503 100644 --- a/builtin/profiler/init.lua +++ b/builtin/profiler/init.lua @@ -15,10 +15,18 @@ --with this program; if not, write to the Free Software Foundation, Inc., --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +local function get_bool_default(name, default) + local val = core.settings:get_bool(name) + if val == nil then + return default + end + return val +end + local profiler_path = core.get_builtin_path()..DIR_DELIM.."profiler"..DIR_DELIM local profiler = {} local sampler = assert(loadfile(profiler_path .. "sampling.lua"))(profiler) -local instrumentation = assert(loadfile(profiler_path .. "instrumentation.lua"))(profiler, sampler) +local instrumentation = assert(loadfile(profiler_path .. "instrumentation.lua"))(profiler, sampler, get_bool_default) local reporter = dofile(profiler_path .. "reporter.lua") profiler.instrument = instrumentation.instrument @@ -27,7 +35,7 @@ profiler.instrument = instrumentation.instrument -- Is called later, after `core.register_chatcommand` was set up. -- function profiler.init_chatcommand() - local instrument_profiler = core.setting_getbool("instrument.profiler") or false + local instrument_profiler = get_bool_default("instrument.profiler", false) if instrument_profiler then instrumentation.init_chatcommand() end diff --git a/builtin/profiler/instrumentation.lua b/builtin/profiler/instrumentation.lua index 4311215..be3a460 100644 --- a/builtin/profiler/instrumentation.lua +++ b/builtin/profiler/instrumentation.lua @@ -17,8 +17,9 @@ local format, pairs, type = string.format, pairs, type local core, get_current_modname = core, core.get_current_modname -local profiler, sampler = ... -local instrument_builtin = core.setting_getbool("instrument.builtin") or false +local profiler, sampler, get_bool_default = ... + +local instrument_builtin = get_bool_default("instrument.builtin", false) local register_functions = { register_globalstep = 0, @@ -137,7 +138,7 @@ local function instrument_register(func, func_name) end local function init_chatcommand() - if core.setting_getbool("instrument.chatcommand") or true then + if get_bool_default("instrument.chatcommand", true) then local orig_register_chatcommand = core.register_chatcommand core.register_chatcommand = function(cmd, def) def.func = instrument { @@ -153,8 +154,7 @@ end -- Start instrumenting selected functions -- local function init() - local is_set = core.setting_getbool - if is_set("instrument.entity") or true then + if get_bool_default("instrument.entity", true) then -- Explicitly declare entity api-methods. -- Simple iteration would ignore lookup via __index. local entity_instrumentation = { @@ -180,7 +180,7 @@ local function init() end end - if is_set("instrument.abm") or true then + if get_bool_default("instrument.abm", true) then -- Wrap register_abm() to automatically instrument abms. local orig_register_abm = core.register_abm core.register_abm = function(spec) @@ -193,7 +193,7 @@ local function init() end end - if is_set("instrument.lbm") or true then + if get_bool_default("instrument.lbm", true) then -- Wrap register_lbm() to automatically instrument lbms. local orig_register_lbm = core.register_lbm core.register_lbm = function(spec) @@ -206,13 +206,13 @@ local function init() end end - if is_set("instrument.global_callback") or true then + if get_bool_default("instrument.global_callback", true) then for func_name, _ in pairs(register_functions) do core[func_name] = instrument_register(core[func_name], func_name) end end - if is_set("instrument.profiler") or false then + if get_bool_default("instrument.profiler", false) then -- Measure overhead of instrumentation, but keep it down for functions -- So keep the `return` for better optimization. profiler.empty_instrument = instrument { diff --git a/builtin/profiler/reporter.lua b/builtin/profiler/reporter.lua index 5b38ed4..fed47a3 100644 --- a/builtin/profiler/reporter.lua +++ b/builtin/profiler/reporter.lua @@ -18,7 +18,7 @@ local DIR_DELIM, LINE_DELIM = DIR_DELIM, "\n" local table, unpack, string, pairs, io, os = table, unpack, string, pairs, io, os local rep, sprintf, tonumber = string.rep, string.format, tonumber -local core, setting_get = core, core.setting_get +local core, settings = core, core.settings local reporter = {} --- @@ -229,7 +229,7 @@ end local worldpath = core.get_worldpath() local function get_save_path(format, filter) - local report_path = setting_get("profiler.report_path") or "" + local report_path = settings:get("profiler.report_path") or "" if report_path ~= "" then core.mkdir(sprintf("%s%s%s", worldpath, DIR_DELIM, report_path)) end @@ -249,7 +249,7 @@ end -- function reporter.save(profile, format, filter) if not format or format == "" then - format = setting_get("profiler.default_report_format") or "txt" + format = settings:get("profiler.default_report_format") or "txt" end if filter == "" then filter = nil diff --git a/builtin/profiler/sampling.lua b/builtin/profiler/sampling.lua index 1d1ef25..4b53399 100644 --- a/builtin/profiler/sampling.lua +++ b/builtin/profiler/sampling.lua @@ -185,7 +185,7 @@ end function sampler.init() sampler.reset() - if core.setting_getbool("instrument.profiler") then + if core.settings:get_bool("instrument.profiler") then core.register_globalstep(function() if logged_time == 0 then return