diff --git a/.luacheckrc b/.luacheckrc index 2ba8c0c..fb4eedd 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -4,7 +4,10 @@ globals = { "mapsync", "worldedit", "minetest", - "travelnet" + -- mods + "travelnet", + "advtrains", + "serialize_lib" } read_globals = { diff --git a/init.lua b/init.lua index 86fcfbb..4bdd9b2 100644 --- a/init.lua +++ b/init.lua @@ -60,6 +60,10 @@ if minetest.get_modpath("travelnet") then dofile(MP.."/integrations/travelnet.lua") end +if minetest.get_modpath("advtrains") then + dofile(MP.."/integrations/advtrains.lua") +end + -- testing if minetest.get_modpath("mtt") and mtt.enabled then dofile(MP.."/init.spec.lua") diff --git a/integrations/advtrains.lua b/integrations/advtrains.lua new file mode 100644 index 0000000..af8abd7 --- /dev/null +++ b/integrations/advtrains.lua @@ -0,0 +1,54 @@ +-- sanity checks +assert(type(advtrains.load_version_4) == "function") +assert(type(advtrains.ndb.save_callback) == "function") +assert(type(advtrains.ndb.load_callback) == "function") +assert(type(advtrains.read_component) == "function") +assert(type(advtrains.save_component) == "function") +assert(type(serialize_lib.load_atomic) == "function") +assert(type(serialize_lib.save_atomic_multiple) == "function") +assert(type(advtrains.fpath) == "string") + +-- local old_advtrains_read_component = advtrains.read_component +function advtrains.read_component(name) + assert(name == "version") + return 4 +end + +-- local old_advtrains_save_component = advtrains.save_component +function advtrains.save_component() + -- no-op +end + +local old_load_atomic = serialize_lib.load_atomic +function serialize_lib.load_atomic(filename, load_callback) + print(dump({ + fn = "serialize_lib.load_atomic", + filename = filename, + fpath = advtrains.fpath, + relpath = string.sub(filename, #advtrains.fpath + 2) + })) + return old_load_atomic(filename, load_callback) +end + +local old_save_atomic_multiple = serialize_lib.save_atomic_multiple +function serialize_lib.save_atomic_multiple(parts_table, filename_prefix, callback_table, config) + print(dump({ + fn = "serialize_lib.save_atomic_multiple", + parts_table = parts_table, + filename_prefix = filename_prefix, + config = config + })) + return old_save_atomic_multiple(parts_table, filename_prefix, callback_table, config) +end + +local advtrains_parts = {"atlatc.ls", "interlocking.ls", "core.ls", "lines.ls", "ndb4.ls"} + +minetest.register_chatcommand("mapsync_save_advtrains", { + privs = { mapsync = true }, + func = function() + for _, part in ipairs(advtrains_parts) do + local path = advtrains.fpath .. "_" .. part + print(path) + end + end +}) \ No newline at end of file diff --git a/mod.conf b/mod.conf index dfe7034..093cabe 100644 --- a/mod.conf +++ b/mod.conf @@ -1,3 +1,3 @@ name = mapsync depends = mtzip -optional_depends = worldedit, screwdriver2, mtt, travelnet \ No newline at end of file +optional_depends = worldedit, screwdriver2, mtt, travelnet, advtrains, serialize_lib \ No newline at end of file