Remove duplicate code since 8ca08a850ff2494652aa0ac2daa3d00f03aa4e7a
authorLoic Blot <loic.blot@unix-experience.fr>
Sun, 22 Mar 2015 09:22:25 +0000 (10:22 +0100)
committerLoic Blot <loic.blot@unix-experience.fr>
Wed, 25 Mar 2015 08:08:17 +0000 (09:08 +0100)
builtin/mainmenu/common.lua

index c1e8ee9c46d220ed1ac423a1319128c1b5aa14e8..d6e2588fad640b363771ef66bf548600bc43e73e 100644 (file)
@@ -40,6 +40,18 @@ local function render_client_count(n)
        end
 end
 
+local function configure_selected_world_params(idx)
+       local worldconfig = modmgr.get_worldconfig(
+               menudata.worldlist:get_list()[idx].path)
+
+       if worldconfig.creative_mode ~= nil then
+               core.setting_set("creative_mode", worldconfig.creative_mode)
+       end
+       if worldconfig.enable_damage ~= nil then
+               core.setting_set("enable_damage", worldconfig.enable_damage)
+       end
+end
+
 --------------------------------------------------------------------------------
 function image_column(tooltip, flagname)
        return "image," ..
@@ -197,15 +209,7 @@ function menu_handle_key_up_down(fields,textlist,settingname)
                        core.setting_set(settingname,
                                menudata.worldlist:get_raw_index(newidx))
 
-                       local worldconfig = modmgr.get_worldconfig(
-                                       menudata.worldlist:get_list()[newidx].path)
-
-                       if worldconfig.creative_mode ~= nil then
-                               core.setting_set("creative_mode", worldconfig.creative_mode)
-                       end
-                       if worldconfig.enable_damage ~= nil then
-                               core.setting_set("enable_damage", worldconfig.enable_damage)
-                       end
+                       configure_selected_world_params(newidx)
                end
                return true
        end
@@ -217,15 +221,8 @@ function menu_handle_key_up_down(fields,textlist,settingname)
                        local newidx = oldidx + 1
                        core.setting_set(settingname,
                                menudata.worldlist:get_raw_index(newidx))
-                       local worldconfig = modmgr.get_worldconfig(
-                                       menudata.worldlist:get_list()[newidx].path)
 
-                       if worldconfig.creative_mode ~= nil then
-                               core.setting_set("creative_mode", worldconfig.creative_mode)
-                       end
-                       if worldconfig.enable_damage ~= nil then
-                               core.setting_set("enable_damage", worldconfig.enable_damage)
-                       end
+                       configure_selected_world_params(newidx)
                end
                
                return true