mirror of
https://gitlab.com/gaelysam/mapgen_rivers.git
synced 2024-12-29 12:20:41 +01:00
Added compatibility script
to update parameter values coming from older versions
This commit is contained in:
parent
9386ef51f1
commit
c2c397c2a5
34
compatibility.lua
Normal file
34
compatibility.lua
Normal 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
|
19
settings.lua
19
settings.lua
@ -1,5 +1,24 @@
|
|||||||
local mtsettings = minetest.settings
|
local mtsettings = minetest.settings
|
||||||
local mgrsettings = Settings(minetest.get_worldpath() .. '/mapgen_rivers.conf')
|
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)
|
function mapgen_rivers.define_setting(name, dtype, default)
|
||||||
if dtype == "number" or dtype == "string" then
|
if dtype == "number" or dtype == "string" then
|
||||||
local v = mgrsettings:get(name)
|
local v = mgrsettings:get(name)
|
||||||
|
Loading…
Reference in New Issue
Block a user