UNPKG

@polygonjs/polygonjs

Version:

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

42 lines (41 loc) 889 B
"use strict"; export class BaseFlag { constructor(node) { this.node = node; this._state = true; this._hooks = null; } onUpdate(hook) { this._hooks = this._hooks || []; this._hooks.push(hook); } _onUpdate() { } set(newState) { if (this._state != newState) { if (this.node.insideALockedParent()) { const lockedParent = this.node.lockedParent(); console.warn( `node '${this.node.path()}' cannot have its flag changed, since it is inside '${lockedParent ? lockedParent.path() : ""}', which is locked` ); return; } this._state = newState; this._onUpdate(); this.runHooks(); } } active() { return this._state; } toggle() { this.set(!this._state); } runHooks() { if (this._hooks) { for (const hook of this._hooks) { hook(); } } } }