diff options
author | Blockhead <jbis1337@hotmail.com> | 2020-08-16 06:05:11 +1000 |
---|---|---|
committer | Gabriel PĂ©rez-Cerezo <gabriel@gpcf.eu> | 2020-08-21 16:02:02 +0200 |
commit | 595f26b45010d8e18433daee1c35b12cc2a7eba5 (patch) | |
tree | b7142feeb7bc81386b295613e171333d74242ac1 /advtrains | |
parent | b707f20ba20a7cd542b9ccc9c939f55a9b88400c (diff) | |
download | advtrains-595f26b45010d8e18433daee1c35b12cc2a7eba5.tar.gz advtrains-595f26b45010d8e18433daee1c35b12cc2a7eba5.tar.bz2 advtrains-595f26b45010d8e18433daee1c35b12cc2a7eba5.zip |
Deprecate old 4590 crossings
This is done with a task that runs once when the nodedb is loaded. A new
field of advtrains_ndb will keep a version integer to indicate migration
versions. This introduces verson 1, no version being equivalent to 0.
An LBM is also registered to replace the tracks in the world.
Diffstat (limited to 'advtrains')
-rw-r--r-- | advtrains/nodedb.lua | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/advtrains/nodedb.lua b/advtrains/nodedb.lua index 37dc3f7..01bf5a4 100644 --- a/advtrains/nodedb.lua +++ b/advtrains/nodedb.lua @@ -30,6 +30,7 @@ local ndb={} --local variables for performance local ndb_nodeids={} local ndb_nodes={} +local ndb_ver local function ndbget(x,y,z) local ny=ndb_nodes[y] @@ -57,6 +58,16 @@ local path=minetest.get_worldpath()..DIR_DELIM.."advtrains_ndb2" --nodeids get loaded by advtrains init.lua and passed here function ndb.load_data(data) ndb_nodeids = data and data.nodeids or {} + ndb_ver = data and data.ver or 0 + if ndb_ver < 1 then + for k,v in pairs(ndb_nodeids) do + if v == "advtrains:dtrack_xing4590_st" then + cidDepr = k + elseif v == "advtrains:dtrack_xing90plusx_45l" then + cidNew = k + end + end + end local file, err = io.open(path, "rb") if not file then atwarn("Couldn't load the node database: ", err or "Unknown Error") @@ -67,6 +78,9 @@ function ndb.load_data(data) local hst_x=file:read(2) local cid=file:read(2) while hst_z and hst_y and hst_x and cid and #hst_z==2 and #hst_y==2 and #hst_x==2 and #cid==2 do + if (ndb_ver < 1 and cid == cidDepr) then + cid = cidNew + end ndbset(bytes_to_int(hst_x), bytes_to_int(hst_y), bytes_to_int(hst_z), bytes_to_int(cid)) cnt=cnt+1 hst_z=file:read(2) @@ -77,6 +91,7 @@ function ndb.load_data(data) atlog("nodedb: read", cnt, "nodes.") file:close() end + ndb_ver = 1 end --save @@ -99,7 +114,7 @@ function ndb.save_data() file:close() end os.rename(tmppath, path) - return {nodeids = ndb_nodeids} + return {nodeids = ndb_nodeids, ver = ndb_ver} end --function to get node. track database is not helpful here. |