fix signal types
This commit is contained in:
parent
723d3f9e9c
commit
52bc94cef2
3 changed files with 41 additions and 13 deletions
|
|
@ -51,12 +51,12 @@ function module.init(shared)
|
||||||
end
|
end
|
||||||
new.Disconnecter = disconnecterClass
|
new.Disconnecter = disconnecterClass
|
||||||
|
|
||||||
local customConnection = {}
|
local connection = {}
|
||||||
customConnection.__index = customConnection
|
connection.__index = connection
|
||||||
function customConnection.New(signal,func)
|
function connection.New(signal,func)
|
||||||
return {signal = signal,func = func}
|
return {signal = signal,func = func}
|
||||||
end
|
end
|
||||||
function customConnection:Disconnect(slient)
|
function connection:Disconnect(slient)
|
||||||
local signal = self.signal
|
local signal = self.signal
|
||||||
local onceConnection = signal.onceConnection
|
local onceConnection = signal.onceConnection
|
||||||
local connection = signal.connection
|
local connection = signal.connection
|
||||||
|
|
@ -78,11 +78,12 @@ function module.init(shared)
|
||||||
warn(("Connection %s is not found from signal %s, but tried :Disconnect(). Maybe disconnected aleady?"):format(tostring(self),tostring(signal)))
|
warn(("Connection %s is not found from signal %s, but tried :Disconnect(). Maybe disconnected aleady?"):format(tostring(self),tostring(signal)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function customConnection:Destroy()
|
function connection:Destroy()
|
||||||
return self:Disconnect(true)
|
return self:Disconnect(true)
|
||||||
end
|
end
|
||||||
new.Connection = customConnection
|
new.Connection = connection
|
||||||
|
|
||||||
|
local signals = {}
|
||||||
local signal = {}
|
local signal = {}
|
||||||
signal.__index = signal
|
signal.__index = signal
|
||||||
function signal:Fire(...)
|
function signal:Fire(...)
|
||||||
|
|
@ -126,7 +127,7 @@ function module.init(shared)
|
||||||
if self:CheckConnected(func) then
|
if self:CheckConnected(func) then
|
||||||
warn(("[Quad] Function %s Connected already on signal %s"):format(tostring(func),tostring(self)))
|
warn(("[Quad] Function %s Connected already on signal %s"):format(tostring(func),tostring(self)))
|
||||||
end
|
end
|
||||||
local thisConnection = customConnection.New(self,func)
|
local thisConnection = connection.New(self,func)
|
||||||
insert(self.connection,{func=func,connection=thisConnection})
|
insert(self.connection,{func=func,connection=thisConnection})
|
||||||
return thisConnection
|
return thisConnection
|
||||||
end
|
end
|
||||||
|
|
@ -134,13 +135,26 @@ function module.init(shared)
|
||||||
if self:CheckConnected(func) then
|
if self:CheckConnected(func) then
|
||||||
warn(("[Quad] Function %s Connected already on signal %s"):format(tostring(func),tostring(self)))
|
warn(("[Quad] Function %s Connected already on signal %s"):format(tostring(func),tostring(self)))
|
||||||
end
|
end
|
||||||
local thisConnection = customConnection.New(self,func)
|
local thisConnection = connection.New(self,func)
|
||||||
insert(self.onceConnection,{func=func,connection=thisConnection})
|
insert(self.onceConnection,{func=func,connection=thisConnection})
|
||||||
return thisConnection
|
return thisConnection
|
||||||
end
|
end
|
||||||
function signal.New()
|
function signal:Destroy()
|
||||||
local self = {waitting={},onceConnection={},connection={}}
|
self.waitting = nil
|
||||||
setmetatable(self,signal)
|
self.onceConnection = nil
|
||||||
|
self.connection = nil
|
||||||
|
setmetatable(self,nil)
|
||||||
|
end
|
||||||
|
function signal.New(id)
|
||||||
|
if id and signals[id] then
|
||||||
|
return signals[id]
|
||||||
|
end
|
||||||
|
local this = {waitting={},onceConnection={},connection={}}
|
||||||
|
setmetatable(this,signal)
|
||||||
|
if id then
|
||||||
|
signals[id] = this
|
||||||
|
end
|
||||||
|
return this
|
||||||
end
|
end
|
||||||
new.Bindable = signal
|
new.Bindable = signal
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,20 @@ export type module_event = {
|
||||||
-------------------
|
-------------------
|
||||||
-- module_signal
|
-- module_signal
|
||||||
-------------------
|
-------------------
|
||||||
export type signal = {}
|
export type connection = {
|
||||||
|
Disconnect: (self:connection)->();
|
||||||
|
Destroy: (self:connection)->();
|
||||||
|
New: (signal,(...any)->())->();
|
||||||
|
}
|
||||||
|
export type signal = {
|
||||||
|
Fire: (self:signal,...any)->();
|
||||||
|
Wait: (self:signal)->();
|
||||||
|
CheckConnected: (self:signal,(...any)->())->boolean;
|
||||||
|
Connect: (self:signal,(...any)->())->connection;
|
||||||
|
Once: (self:signal,(...any)->())->connection;
|
||||||
|
Destroy: (self:signal)->();
|
||||||
|
New: (id:string?)->signal;
|
||||||
|
}
|
||||||
export type disconnecter = {
|
export type disconnecter = {
|
||||||
Add: (self:disconnecter,connection:RBXScriptConnection)->();
|
Add: (self:disconnecter,connection:RBXScriptConnection)->();
|
||||||
Destroy: (self:disconnecter)->();
|
Destroy: (self:disconnecter)->();
|
||||||
|
|
@ -63,6 +76,7 @@ export type disconnecter = {
|
||||||
}
|
}
|
||||||
export type module_signal = {
|
export type module_signal = {
|
||||||
Disconnecter: disconnecter;
|
Disconnecter: disconnecter;
|
||||||
|
Bindable: signal;
|
||||||
}
|
}
|
||||||
|
|
||||||
-------------------
|
-------------------
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ function module.init()
|
||||||
local TweenTest = Class(script.tween)
|
local TweenTest = Class(script.tween)
|
||||||
local LangTest = Class(script.lang)
|
local LangTest = Class(script.lang)
|
||||||
|
|
||||||
Signal.
|
-- Signal.
|
||||||
|
|
||||||
SetTheme(Global)
|
SetTheme(Global)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue