Add bundled command support

This commit is contained in:
cheapie 2016-09-21 21:13:52 -05:00
parent 551b470b16
commit 0e3b6dda83

@ -80,12 +80,7 @@ digistuff.ts_on_receive_fields = function (pos, formname, fields, sender)
end end
end end
digistuff.ts_on_digiline_receive = function (pos, node, channel, msg) digistuff.process_command = function (meta, data, msg)
local meta = minetest.get_meta(pos)
local setchan = meta:get_string("channel")
if channel ~= setchan then return end
if type(msg) ~= "table" then return end
local data = minetest.deserialize(meta:get_string("data")) or {}
if msg.command == "clear" then if msg.command == "clear" then
data = {} data = {}
elseif msg.command == "addimage" then elseif msg.command == "addimage" then
@ -217,6 +212,24 @@ digistuff.ts_on_digiline_receive = function (pos, node, channel, msg)
elseif msg.command == "unlock" then elseif msg.command == "unlock" then
meta:set_int("locked",0) meta:set_int("locked",0)
end end
return data
end
digistuff.ts_on_digiline_receive = function (pos, node, channel, msg)
local meta = minetest.get_meta(pos)
local setchan = meta:get_string("channel")
if channel ~= setchan then return end
if type(msg) ~= "table" then return end
local data = minetest.deserialize(meta:get_string("data")) or {}
if msg.command then
data = digistuff.process_command(meta,data,msg)
else
for _,i in ipairs(msg) do
if i.command then
data = digistuff.process_command(meta,data,i)
end
end
end
meta:set_string("data",minetest.serialize(data)) meta:set_string("data",minetest.serialize(data))
digistuff.update_ts_formspec(pos) digistuff.update_ts_formspec(pos)
end end