local F={}F.__index=F function F.new()local G=setmetatable({_listeners={};_renderStepNames={};_actionNames={}},F)return G end function F.Connect(h,F,G)local l=F:Connect(G)table.insert(h._listeners,l)return l end function F.BindToRenderStep(G,F,...)table.insert(G._renderStepNames,F);(game:GetService("\082\117\110\083\101\114\118\105\099\101")):BindToRenderStep(F,...)end function F.BindAction(G,F,...)table.insert(G._actionNames,F);(game:GetService("\067\111\110\116\101\120\116\065\099\116\105\111\110\083\101\114\118\105\099\101")):BindAction(F,...)end function F.BindActionAtPriority(G,F,...)table.insert(G._actionNames,F);(game:GetService("\067\111\110\116\101\120\116\065\099\116\105\111\110\083\101\114\118\105\099\101")):BindActionAtPriority(F,...)end function F.DisconnectEvents(F)for F,G in pairs(F._listeners)do if G.Connected then G:Disconnect()end end F._listeners={}end function F.DisconnectRenderSteps(F)local G=game:GetService("\082\117\110\083\101\114\118\105\099\101")for F,h in pairs(F._renderStepNames)do G:UnbindFromRenderStep(h)end F._renderStepNames={}end function F.DisconnectActions(F)local G=game:GetService("\067\111\110\116\101\120\116\065\099\116\105\111\110\083\101\114\118\105\099\101")for F,h in pairs(F._actionNames)do G:UnbindAction(h)end F._actionNames={}end function F.DisconnectAll(F)F:DisconnectEvents()F:DisconnectRenderSteps()F:DisconnectActions()end return F
-- Listener List
-- Crazyman32
-- November 1, 2015

--[[
	
	local listeners = ListenerList.new()
	
	listeners:Connect(event, func)
	listeners:BindToRenderStep(name, priority, func)
	listeners:BindAction(actionName, funcToBind, createTouchBtn [, inputTypes...])
	listeners:BindActionAtPriority(actionName, funcToBind, createTouchBtn, priorityLevel [, inputTypes...])

	listeners:DisconnectAll()
	listeners:DisconnectEvents()
	listeners:DisconnectRenderSteps()
	listeners:DisconnectActions()
	
--]]



local ListenerList = {}
ListenerList.__index = ListenerList


function ListenerList.new()
	local self = setmetatable({
		_listeners = {};
		_renderStepNames = {};
		_actionNames = {};
	}, ListenerList)
	return self
end


-- Connect a function to an event and store it in the list:
function ListenerList:Connect(event, func)
	local listener = event:Connect(func)
	table.insert(self._listeners, listener)
	return listener
end


function ListenerList:BindToRenderStep(name, ...)
	table.insert(self._renderStepNames, name)
	game:GetService("RunService"):BindToRenderStep(name, ...)
end


function ListenerList:BindAction(name, ...)
	table.insert(self._actionNames, name)
	game:GetService("ContextActionService"):BindAction(name, ...)
end


function ListenerList:BindActionAtPriority(name, ...)
	table.insert(self._actionNames, name)
	game:GetService("ContextActionService"):BindActionAtPriority(name, ...)
end


function ListenerList:DisconnectEvents()
	for _,l in pairs(self._listeners) do
		if (l.Connected) then
			l:Disconnect()
		end
	end
	self._listeners = {}
end


function ListenerList:DisconnectRenderSteps()
	local runService = game:GetService("RunService")
	for _,n in pairs(self._renderStepNames) do
		runService:UnbindFromRenderStep(n)
	end
	self._renderStepNames = {}
end


function ListenerList:DisconnectActions()
	local ctxService = game:GetService("ContextActionService")
	for _,n in pairs(self._actionNames) do
		ctxService:UnbindAction(n)
	end
	self._actionNames = {}
end


-- Disconnect all events in the list and clear the list:
function ListenerList:DisconnectAll()
	self:DisconnectEvents()
	self:DisconnectRenderSteps()
	self:DisconnectActions()
end


return ListenerList