import PrimaryCanvasContainer from "@client/canvas/primary/primary-canvas-container.mjs";

/**
 * A special subclass of PrimaryCanvasContainer used for the animation of related display objects in VFXEffects.
 * TODO we might not need this in the end and we can just use PrimaryCanvasContainer directly. TBD.
 */
export default class VFXCanvasContainer extends PrimaryCanvasContainer {
  constructor() {
    super();
    this.on("childAdded", this.#onChildAdded.bind(this));
    this.on("childRemoved", this.#onChildRemoved.bind(this));
  }

  /**
   * A registry of named display objects which belong to this container
   * @type {Record<string, PIXI.DisplayObject>}
   */
  sprites = {};

  /**
   * @param {PIXI.DisplayObject} child
   */
  #onChildAdded(child) {
    if ( child.name ) this.sprites[child.name] = child;
  }

  /**
   * @param {PIXI.Sprite} child
   */
  #onChildRemoved(child) {
    if ( child.name ) delete this.sprites[child.name];
  }
}
