-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3066 from moisesjpelaez/main
Add Signals
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package armory.system; | ||
|
||
import haxe.Constraints.Function; | ||
|
||
class Signal { | ||
var callbacks:Array<Function> = []; | ||
|
||
public function new() { | ||
|
||
} | ||
|
||
public function connect(callback:Function) { | ||
if (!callbacks.contains(callback)) callbacks.push(callback); | ||
} | ||
|
||
public function disconnect(callback:Function) { | ||
if (callbacks.contains(callback)) callbacks.remove(callback); | ||
} | ||
|
||
public function emit(...args:Any) { | ||
for (callback in callbacks) Reflect.callMethod(this, callback, args); | ||
} | ||
|
||
public function getConnections():Array<Function> { | ||
return callbacks; | ||
} | ||
|
||
public function isConnected(callBack:Function):Bool { | ||
return callbacks.contains(callBack); | ||
} | ||
|
||
public function isNull():Bool { | ||
return callbacks.length == 0; | ||
} | ||
} |