import { addGameObjectToGameState } from "../GameState/GameState";
import { BC_VIEWPORT } from "../GlobalVariables/GlobalVariables";
import { SceneObject } from "../SceneObjects/SceneObject";

export class GameScene {
    /**
     * @type Map<Number, SceneObject>
     */
    #SceneObjects = new Map();

    getObjectById(minor_id) {
        return this.#SceneObjects.get(minor_id);
    };

    /**
     * SceneObject must be initialized!
     * @param {SceneObject} sceneObject
     */
    addObjectToScene(sceneObject) {
        sceneObject.onSpawn();
        this.#SceneObjects.set(sceneObject.minorId, sceneObject);
        BC_VIEWPORT.addChild(sceneObject.drawObject);
    };

    /**
     * For uninitialized SceneObjects
     * @param {SceneObject} sceneObject
     */
    addObjectToSceneWithInitialization(sceneObject) {
        addGameObjectToGameState(sceneObject);
        this.addObjectToScene(sceneObject);
    };

    /**
     * Removes object from render stage and Scene storage
     * @param {SceneObject} sceneObject 
     */
    removeObjectFromScene(sceneObject) {
        if(this.#SceneObjects.has(sceneObject.minorId))
        {
            BC_VIEWPORT.removeChild(sceneObject.drawObject);
            this.#SceneObjects.delete(sceneObject.minorId);
        }
    };
}
