[1.9.x] Remote Interface for other mods
Posted: Mon Oct 08, 2018 3:22 pm
I've added a remote interface to register callbacks to secondary mods remote interfaces into the development branch to version 1.9.0.
This allows other mods to grab LTN's data and display it in a GUI or create a combinator showing all items currently available in a network.
Currently supported are registration for stop status and the whole dispatcher data structure. I may break the dispatcher up into smaller chunks depending on feedback.
control.lua of a demo mod grabbing stop status and dispatcher and writing the data with serpent.block to logfile:
I'm open for feedback on this feature.
This allows other mods to grab LTN's data and display it in a GUI or create a combinator showing all items currently available in a network.
Currently supported are registration for stop status and the whole dispatcher data structure. I may break the dispatcher up into smaller chunks depending on feedback.
control.lua of a demo mod grabbing stop status and dispatcher and writing the data with serpent.block to logfile:
Code: Select all
-- LTN callback handers, triggered by LTN during runtime
remote.add_interface("ltn_interface_demo", {
-- log recieved stop data
stop_updates = function(data)
if data then
log("Stop Data:"..serpent.block(data) )
end
end,
-- log recieved dispatcher data
dispatcher_updates = function(data)
if data then
log("Dispatcher Data:"..serpent.block(data) )
end
end
})
---- Initialisation ----
do
script.on_init(function()
-- register callbacks with LTN
-- format remote.call("ltn_interface", "register_reciever_stop_status", <this-mod-interface-name>, <this-mod-interface-function>)
remote.call("ltn_interface", "register_reciever_stop_status", "ltn_interface_demo", "stop_updates")
remote.call("ltn_interface", "register_reciever_dispatcher_status", "ltn_interface_demo", "dispatcher_updates")
end)
script.on_configuration_changed(function(data)
-- register callbacks with LTN
-- format remote.call("ltn_interface", "register_reciever_stop_status", <this-mod-interface-name>, <this-mod-interface-function>)
remote.call("ltn_interface", "register_reciever_stop_status", "ltn_interface_demo", "stop_updates")
remote.call("ltn_interface", "register_reciever_dispatcher_status", "ltn_interface_demo", "dispatcher_updates")
end)
end