import { Application, Assets, Container, Sprite, Rectangle } from "pixi.js";
import { TimedGame } from "./timedGame";
import { KeyBoardListener } from "../common";

export class SmartMonday extends TimedGame {
    constructor(ticker) {
        super(10000, ticker);

        this._gameDesc.text = "Organise le smart monday !!";
        this._instruction.text = "spam le clavier";

        this._goal = 100 * this._difficulty; // number of characters
        this.timeout = 1000 * (this._goal / 10); // 10 chars per second

        this._currentString = "";
        this._keyEventHandle = undefined;
        this.gameContainer.layout = { width: "100%", height: "100%" };
    }

    reset() {
        super.reset();
        this._currentString = "";
    }

    start() {
        super.start();
        this._keyEventHandle = KeyBoardListener.onKeyDown((event) => {
            this._currentString += event.key;
            console.log("current text", this._currentString);
            if (this._currentString.length >= this._goal) {
                this.end(true);
            }
        });
    }

    end(status) {
        super.end(status);
        KeyBoardListener.offKeyDown(this._keyEventHandle);
    }
}
