Added compatibility script

to update parameter values coming from older versions
This commit is contained in:
Gaël C 2021-07-24 13:21:06 +02:00
parent 9386ef51f1
commit c2c397c2a5
2 changed files with 53 additions and 0 deletions

34
compatibility.lua Normal file
View File

@ -0,0 +1,34 @@
local function fix_min_catchment(settings, is_global)
local prefix = is_global and "mapgen_rivers_" or ""
local min_catchment = settings:get(prefix.."min_catchment")
if min_catchment then
min_catchment = tonumber(min_catchment)
local blocksize = tonumber(settings:get(prefix.."blocksize") or 15)
settings:set(prefix.."min_catchment", tonumber(min_catchment) * blocksize*blocksize)
local max_catchment = settings:get(prefix.."max_catchment")
if max_catchment then
max_catchment = tonumber(max_catchment)
local wpower = math.log(2*blocksize)/math.log(max_catchment/min_catchment)
settings:set(prefix.."river_widening_power", wpower)
end
end
end
local function fix_compatibility_minetest(settings)
local previous_version = settings:get("mapgen_rivers_version") or "0.0"
if previous_version == "0.0" then
fix_min_catchment(settings, true)
end
end
local function fix_compatibility_mapgen_rivers(settings)
local previous_version = settings:get("version") or "0.0"
if previous_version == "0.0" then
fix_min_catchment(settings, false)
end
end
return fix_compatibility_minetest, fix_compatibility_mapgen_rivers

View File

@ -1,5 +1,24 @@
local mtsettings = minetest.settings
local mgrsettings = Settings(minetest.get_worldpath() .. '/mapgen_rivers.conf')
mapgen_rivers.version = "1.0"
local previous_version_mt = mtsettings:get("mapgen_rivers_version") or "0.0"
local previous_version_mgr = mgrsettings:get("version") or "0.0"
if mapgen_rivers.version ~= previous_version_mt or mapgen_rivers.version ~= previous_version_mgr then
local compat_mt, compat_mgr = dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/compatibility.lua")
if mapgen_rivers.version ~= previous_version_mt then
compat_mt(mtsettings)
end
if mapgen_rivers.version ~= previous_version_mgr then
compat_mgr(mgrsettings)
end
end
mtsettings:set("mapgen_rivers_version", mapgen_rivers.version)
mgrsettings:set("version", mapgen_rivers.version)
function mapgen_rivers.define_setting(name, dtype, default)
if dtype == "number" or dtype == "string" then
local v = mgrsettings:get(name)