Skip to content

Commit

Permalink
advtrains compat
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Aug 12, 2024
1 parent 8dbf737 commit d73e19e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ globals = {
"mapsync",
"worldedit",
"minetest",
"travelnet"
-- mods
"travelnet",
"advtrains",
"serialize_lib"
}

read_globals = {
Expand Down
4 changes: 4 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
54 changes: 54 additions & 0 deletions integrations/advtrains.lua
Original file line number Diff line number Diff line change
@@ -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
})
2 changes: 1 addition & 1 deletion mod.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name = mapsync
depends = mtzip
optional_depends = worldedit, screwdriver2, mtt, travelnet
optional_depends = worldedit, screwdriver2, mtt, travelnet, advtrains, serialize_lib

0 comments on commit d73e19e

Please sign in to comment.