Files
bo3-js/js/core/BO3ScriptSignal.js

41 lines
920 B
JavaScript
Raw Normal View History

2025-10-12 18:03:20 +02:00
// A simple event system that mimics Roblox's RBXScriptSignal.
export class BO3ScriptSignal {
constructor() {
this._connections = [];
}
// Connect a function to the signal.
Connect(fn) {
const connection = { fn, connected: true };
this._connections.push(connection);
return {
Disconnect: () => {
connection.connected = false;
this._connections = this._connections.filter(c => c !== connection);
},
};
}
// Fire all connected callbacks with arguments.
Fire(...args) {
for (const c of this._connections) {
if (c.connected) {
try {
c.fn(...args);
} catch (err) {
console.error("[BO3ScriptSignal] Error in connected function:", err);
}
}
}
}
// Disconnect all listeners.
DisconnectAll() {
this._connections = [];
}
get [Symbol.toStringTag]() {
return "BO3ScriptSignal";
}
}