Skip to content

Commit

Permalink
Merge pull request #3066 from moisesjpelaez/main
Browse files Browse the repository at this point in the history
Add Signals
  • Loading branch information
luboslenco authored Nov 4, 2024
2 parents 47d078f + 6f75ecd commit 7df0d65
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Sources/armory/system/Signal.hx
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;
}
}

0 comments on commit 7df0d65

Please sign in to comment.