From 595f26b45010d8e18433daee1c35b12cc2a7eba5 Mon Sep 17 00:00:00 2001 From: Blockhead Date: Sun, 16 Aug 2020 06:05:11 +1000 Subject: 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. --- advtrains/nodedb.lua | 17 ++++++++++++++++- advtrains_train_track/init.lua | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) 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. diff --git a/advtrains_train_track/init.lua b/advtrains_train_track/init.lua index d6b8e52..d85f8a1 100644 --- a/advtrains_train_track/init.lua +++ b/advtrains_train_track/init.lua @@ -62,6 +62,25 @@ minetest.register_craft({ {'', '', 'advtrains:dtrack_placer'} } }) +-- Deprecate any rails using the old name scheme +minetest.register_lbm({ + label = "Upgrade legacy 4590 rails", + name = "advtrains_train_track:replace_legacy_4590", + nodenames = {"advtrains:dtrack_xing4590_st"}, + run_at_every_load = true, + action = function(pos, node) + minetest.log("actionPos!: " .. pos.x .. "," .. pos.y .. "," .. pos.z) + minetest.log("node!: " .. node.name .. "," .. node.param1 .. "," .. node.param2) + advtrains.ndb.swap_node(pos, + { + name="advtrains:dtrack_xing90plusx_45l", + param1=node.param1, + param2=node.param2, + }) + end +}) +-- This will replace any items left in the inventory +minetest.register_alias("advtrains:dtrack_xing4590_placer", "advtrains:dtrack_xing90plusx_placer") -- Diagonal -- This set of rail crossings is named based on the angle of each intersecting -- cgit v1.2.3