local R=(require(((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\083\099\114\105\112\116\115")):WaitForChild("\067\111\110\115\111\108\101"))).sourced("\069\118\101\110\116")R.log("\073\110\105\116\105\097\108\105\122\105\110\103 \118\097\114\105\097\098\108\101\115\046\046\046")local s={}R.log("\067\111\110\115\116\114\117\099\116\105\110\103 \111\098\106\101\099\116\115\046\046\046")s.__index=s function s.new()local R=setmetatable({},s)R.listeners={}R.Registrar={}R.Registrar.listeners=R.listeners R.Registrar.Connect=R.Connect R.Registrar.Disconnect=R.Disconnect R.Activator={}R.Activator.listeners=R.listeners R.Activator.Fire=R.Fire return R end function s.Connect(s,R)table.insert(s.listeners,R)return#s.listeners end function s.Disconnect(s,R)table.remove(s.listeners,R)end function s.Fire(R,...)for R,s in ipairs(R.listeners)do s(...)end end R.log("\068\111\110\101\046")return s
--- An general purpose event.
-- It can accept multiple listener functions that all actiavte when fired. It
-- includes a registrar and activator that allow a separation of listeners and
-- activators.
--
-- @author LastTalon
-- @version 0.1.0, 2020-03-31
-- @since 0.1
--
-- @module Event
-- @field Registrar allows connecting and disconnecting listeners. Has the same
-- Connect and Disconnect methods as the Event.
-- @field Activator allows firing the Event. Has the same Fire method as the
-- Event.

local Console = require(game:GetService("ReplicatedStorage"):WaitForChild("Scripts"):WaitForChild("Console")).sourced("Event")

-- Variables --
Console.log("Initializing variables...")

local Event = {}

-- Local Objects --
Console.log("Constructing objects...")

Event.__index = Event

--- The default Event constructor.
-- Creates a new empty Event with a registrar and activator.
--
-- @return the new Event
function Event.new()
	local self = setmetatable({}, Event)
	self.listeners = {}
	self.Registrar = {}
	self.Registrar.listeners = self.listeners
	self.Registrar.Connect = self.Connect
	self.Registrar.Disconnect = self.Disconnect
	self.Activator = {}
	self.Activator.listeners = self.listeners
	self.Activator.Fire = self.Fire
	return self
end

--- Connects a new listener.
-- The listener will be activated every time the event fires. Activation order
-- of listeners is not guaranteed, but all listeners will activate at the same
-- time before execution resumes elsewhere.
--
-- @param fn the listening function to connect
-- @return the id of the listener
function Event:Connect(fn)
	table.insert(self.listeners, fn)
	return #self.listeners
end

--- Disconnects a listener.
-- Disconnects a listener that was perviously connected so that it will no
-- longer fire when the Event is activated.
--
-- @param id the id of the listener to disconnect
function Event:Disconnect(id)
	table.remove(self.listeners, id)
end

--- Fires the Event and activates any listeners.
-- Immediately activates and blocks until all listeners are activated.
--
-- @param ... parameters to pass to all listeners
function Event:Fire(...)
	for _, fn in ipairs(self.listeners) do
		fn(...)
	end
end

-- End --
Console.log("Done.")

return Event
