UNPKG

polygonjs-engine

Version:

node-based webgl 3D engine https://polygonjs.com

34 lines (33 loc) 571 B
export class BaseFlag { constructor(node) { this.node = node; this._state = true; this._hooks = null; } add_hook(hook) { this._hooks = this._hooks || []; this._hooks.push(hook); } on_update() { } set(new_state) { if (this._state != new_state) { this._state = new_state; this.on_update(); this.run_hooks(); } } active() { return this._state; } toggle() { this.set(!this._state); } run_hooks() { if (this._hooks) { for (let hook of this._hooks) { hook(); } } } }