From: Vanessa Ezekowitz Date: Tue, 9 Apr 2013 04:15:24 +0000 (-0400) Subject: Made settings world-specific - look for moretrees_settings.txt in your world X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=8a1ebec9513535f6f8f4488599eb7ca5560ead96;p=zefram%2Fminetest%2Fmoretrees.git Made settings world-specific - look for moretrees_settings.txt in your world folder. If it isn't found, the mod will create it with the contents of default_settings.txt and then read those default settings and use them. Otherwise, it will read its settings from the world folder. --- diff --git a/default_settings.txt b/default_settings.txt new file mode 100644 index 0000000..766d193 --- /dev/null +++ b/default_settings.txt @@ -0,0 +1,57 @@ +-- Global configuration variables + +-- Enable the various kinds of trees. + +moretrees.enable_apple_tree = true +moretrees.enable_oak = true +moretrees.enable_sequoia = true +moretrees.enable_palm = true +moretrees.enable_pine = true +moretrees.enable_rubber_tree = true +moretrees.enable_willow = true +moretrees.enable_birch = true +moretrees.enable_spruce = true +moretrees.enable_jungle_tree = true +moretrees.enable_fir = true +moretrees.enable_beech = false + +-- Set this to true to enable leaf decay of all trees except the default ones. + +moretrees.enable_leafdecay = true + +-- Enable this one if you want this mod's leafdecay code to affect the old +-- default trees too; this setting is independent of the one above. You'll +-- want to manually disable the default leafdecay code in minetest_game if +-- you enable this, otherwise you'll have two sets of leaf decay code running +-- at the same time, which will just waste CPU for no benefit. + +moretrees.enable_default_leafdecay = true + +-- Enable this if you want moretrees to redefine default apples so that they +-- fall when leaves decay/are dug. + +moretrees.enable_redefine_apple = true + +-- various settings to configure leaf decay in general. + +moretrees.leafdecay_delay = 2 +moretrees.leafdecay_chance = 200 +moretrees.leafdecay_radius = 5 + +moretrees.palm_leafdecay_radius = 12 + +moretrees.default_leafdecay_delay = 3 +moretrees.default_leafdecay_chance = 100 +moretrees.default_leafdecay_radius = 4 + +-- Change these settings if you want default trees to be gradually cut down +-- above the elevation where firs normally generate. + +moretrees.firs_remove_default_trees = false +moretrees.firs_remove_interval = 2 +moretrees.firs_remove_chance = 150 + +-- Sapling settings + +moretrees.sapling_interval = 500 +moretrees.sapling_chance = 20 diff --git a/init.lua b/init.lua index 6773e41..d36baf4 100644 --- a/init.lua +++ b/init.lua @@ -18,13 +18,35 @@ moretrees = {} -dofile(minetest.get_modpath("moretrees").."/settings.lua") -dofile(minetest.get_modpath("moretrees").."/tree_models.lua") -dofile(minetest.get_modpath("moretrees").."/biome_defs.lua") -dofile(minetest.get_modpath("moretrees").."/node_defs.lua") -dofile(minetest.get_modpath("moretrees").."/saplings.lua") -dofile(minetest.get_modpath("moretrees").."/crafts.lua") -dofile(minetest.get_modpath("moretrees").."/leafdecay.lua") +-- If the config file is not found in the world directory, copy the default +-- settings to that location and read them in. + +local worldpath=minetest.get_worldpath() +local modpath=minetest.get_modpath("moretrees") + +if io.open(worldpath.."/moretrees_settings.txt","r") == nil then + + dofile(modpath.."/default_settings.txt") + + io.input(modpath.."/default_settings.txt") + io.output(worldpath.."/moretrees_settings.txt") + + local size = 2^13 -- good buffer size (8K) + while true do + local block = io.read(size) + if not block then break end + io.write(block) + end +end + +dofile(worldpath.."/moretrees_settings.txt") + +dofile(modpath.."/tree_models.lua") +dofile(modpath.."/biome_defs.lua") +dofile(modpath.."/node_defs.lua") +dofile(modpath.."/saplings.lua") +dofile(modpath.."/crafts.lua") +dofile(modpath.."/leafdecay.lua") -- tree spawning setup diff --git a/settings.lua b/settings.lua deleted file mode 100644 index 766d193..0000000 --- a/settings.lua +++ /dev/null @@ -1,57 +0,0 @@ --- Global configuration variables - --- Enable the various kinds of trees. - -moretrees.enable_apple_tree = true -moretrees.enable_oak = true -moretrees.enable_sequoia = true -moretrees.enable_palm = true -moretrees.enable_pine = true -moretrees.enable_rubber_tree = true -moretrees.enable_willow = true -moretrees.enable_birch = true -moretrees.enable_spruce = true -moretrees.enable_jungle_tree = true -moretrees.enable_fir = true -moretrees.enable_beech = false - --- Set this to true to enable leaf decay of all trees except the default ones. - -moretrees.enable_leafdecay = true - --- Enable this one if you want this mod's leafdecay code to affect the old --- default trees too; this setting is independent of the one above. You'll --- want to manually disable the default leafdecay code in minetest_game if --- you enable this, otherwise you'll have two sets of leaf decay code running --- at the same time, which will just waste CPU for no benefit. - -moretrees.enable_default_leafdecay = true - --- Enable this if you want moretrees to redefine default apples so that they --- fall when leaves decay/are dug. - -moretrees.enable_redefine_apple = true - --- various settings to configure leaf decay in general. - -moretrees.leafdecay_delay = 2 -moretrees.leafdecay_chance = 200 -moretrees.leafdecay_radius = 5 - -moretrees.palm_leafdecay_radius = 12 - -moretrees.default_leafdecay_delay = 3 -moretrees.default_leafdecay_chance = 100 -moretrees.default_leafdecay_radius = 4 - --- Change these settings if you want default trees to be gradually cut down --- above the elevation where firs normally generate. - -moretrees.firs_remove_default_trees = false -moretrees.firs_remove_interval = 2 -moretrees.firs_remove_chance = 150 - --- Sapling settings - -moretrees.sapling_interval = 500 -moretrees.sapling_chance = 20