From 0e3b6dda835f3b71b636670a898c277db69b77e1 Mon Sep 17 00:00:00 2001 From: cheapie Date: Wed, 21 Sep 2016 21:13:52 -0500 Subject: Add bundled command support --- init.lua | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/init.lua b/init.lua index 92bb3fe..490cff0 100644 --- a/init.lua +++ b/init.lua @@ -80,12 +80,7 @@ digistuff.ts_on_receive_fields = function (pos, formname, fields, sender) end 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 {} +digistuff.process_command = function (meta, data, msg) if msg.command == "clear" then data = {} elseif msg.command == "addimage" then @@ -217,6 +212,24 @@ digistuff.ts_on_digiline_receive = function (pos, node, channel, msg) elseif msg.command == "unlock" then meta:set_int("locked",0) 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)) digistuff.update_ts_formspec(pos) end -- cgit v1.2.3