import * as PIXI from "../../pixi/pixi.mjs"
import { addToCleaningQueue } from "../GameState/GameState";

/**
 * Base class for all game objects.
 */
export class GameObject {
    
    //currently not in use
    majorId = -1;
    //primary game object id
    minorId = -1;
    _tickEnabled = false;
    _markedPendingKill = false;
    // markedAsInitialized = false;

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

    /**
     * inits GameObject with id. Without id object will not be added to the scene. id must be unique
     */
    init_byGameState(major_id, minor_id)
    {
        this.majorId = major_id;
        this.minorId = minor_id;
    };

    /**
     * Removes object from scene in the next frame and delete it completely after several frames
     */
    kill()
    {
        if(this._markedPendingKill) return;
        this.preDestroy();
        this._markedPendingKill = true;
        addToCleaningQueue(this.majorId, this.minorId);
    };

    /**
     * called before object's destruction
     */
    preDestroy(){};

    /**
     * called after spawn
     */
    onSpawn(){};

    /**
     * called after initialization
     */
    onInit(){};

    /**
     * called every frame
     * @param {PIXI.Ticker} ticker 
     */
    tick(ticker){};

    isTickEnabled(){return this._tickEnabled;};
    isMarkedPendingKill(){return this._markedPendingKill;};
    isInitialized(){return (this.minorId > -1 && this.majorId > -1);};
    /**
     * 
     * @param {GameObject} objectA 
     * @param {GameObject} objectB 
     * @returns 
     */
    static isEqual(objectA, objectB)
    {
        if(!objectA || !objectB) return false;
        return (objectA.minorId === objectB.minorId) && (objectA.majorId === objectB.majorId); 
    };
};