import { GameObject } from "../GameObject/GameObject";
import { Container } from "../../pixi/pixi.mjs";
import { Point2D, PointInt2D } from "../Utils/Math.utils";
import { addGameObjectToGameState } from "../GameState/GameState";

export class SceneObject extends GameObject {
    /**
     * Pixi container. This container will be added to render stage.
     * @type Container
     */
    drawObject = new Container();

    /**
     * Props for scene object. Defined in children classes
     */
    props = {};

    /**
     * world position for scene object
     */
    worldPosition = new PointInt2D();

    /**
     *
     * @param {Boolean} tickAble
     */
    constructor(tickAble) {
        super(tickAble);
        // this._tickEnabled = tickAble;
    }

    /**
     *
     * @param {SceneObject} childObject
     */
    addChild(childObject) {
        if (childObject.isMarkedPendingKill()) return;
        if (childObject.isInitialized() === false) {
            addGameObjectToGameState(childObject);
        }
        this.drawObject.addChild(childObject.drawObject);
        childObject.onSpawn();
    }

    /**
     * Instantly* kills drawObject (by PIXI) and after several ticks kills SceneObject
     *
     * * not sure about instant killing
     */
    kill() {
        super.kill();
        this.drawObject.destroy();
    }
}
