PluginInfo = { Name = "CallQueue", Version = "0.1.0-master", Id = "callqueue.plugin.0.1.0-master", Description = "Plugin for taking incoming call objects and maintaining a queue", Author = "Joel Wetzell" } require("json") function GetPrettyName() return "Call Queue" end function GetProperties() local props = { { Name = "Call Count", Type = "integer", Min = 0, Max = 20, Value = 1 }, } return props end function RectifyProperties(props) return props end function GetControls(props) local controls = { { Name = "PopCall", ControlType = "Button", ButtonType = "Trigger", PinStyle = "Input", UserPin = true }, { Name = "CallList", ControlType = "Text", PinStyle = "Output", UserPin = true }, { Name = "ClearAll", ControlType = "Button", ButtonType = "Trigger", Pinstyle = "Input", UserPin = true } } for i=1,props["Call Count"].Value do local name = "Call" .. i table.insert(controls, { Name = name .. "In", ControlType = "Text", PinStyle = "Input", UserPin = true }) table.insert(controls, { Name = name .. "Clear", ControlType = "Button", ButttonType = "Trigger", PinStyle = "Output", UserPin = true }) end return controls end function ClearCalls() CallList = {} for i=1, Properties["Call Count"].Value do Controls["Call"..i.."Clear"]:Trigger() end UpdateOutputs() end function UpdateOutputs() local listString = "" if (#CallList > 0) then for i, v in pairs(CallList) do listString = listString .. v.Name .. "\n" end end Controls["CallList"].String = listString end function PushCall(call) for i, value in pairs(CallList) do if value.Position == call.Position then print("call already in queue for position " .. call.Position) return end end table.insert(CallList, call) print("call for " .. call.Name .. " at position " .. call.Position .. " pushed") UpdateOutputs() end function PopCall() call = table.remove(CallList,1) if call then print("call for " .. call.Name .. " at position " .. call.Position .. " popped") Controls["Call"..call.Position.."Clear"]:Trigger() end UpdateOutputs() end function RemoveCall(call) for i, value in pairs(CallList) do if value.Position == call.Position then print("removing call for position " .. call.Position) table.remove(CallList, i) end end UpdateOutputs() end function Initialize() ClearCalls() end function SetupControlHandlers() Controls["PopCall"].EventHandler = function (ctrl) PopCall() end Controls["ClearAll"].EventHandler = function (ctrl) ClearCalls() end for i=1, Properties["Call Count"].Value do Controls["Call"..i.."In"].EventHandler = function (ctrl) if ctrl.String ~= "" then local call = json.decode(ctrl.String) call.Position = i if call.Queue then PushCall(call) else RemoveCall(call) end end end end end if(Controls) then Initialize() SetupControlHandlers() end