import { SimActionFireTowers, SimActionMoveEnemies, SimActionMoveProjectiles, SimActionSpawnEnemies, SimCommandStartNextWave, SimLevel } from "./index.js";
export class SimMain {
    _currentLevel;
    _commands = [];
    _actions = [];
    _gdRoot;
    constructor(gdRoot, level) {
        this._gdRoot = gdRoot;
        this._currentLevel = new SimLevel(gdRoot, level);
        this._actions.push(new SimActionMoveEnemies());
        this._actions.push(new SimActionSpawnEnemies());
        this._actions.push(new SimActionFireTowers());
        this._actions.push(new SimActionMoveProjectiles());
        if (true || !this.loadModel()) {
            this.reload();
        }
        this._currentLevel.paused = true;
    }
    get gdRoot() {
        return this._gdRoot;
    }
    get currentLevel() {
        return this._currentLevel;
    }
    executeUntilStep(targetStep) {
        this.executeCommands();
        while (this._currentLevel.currentStep < targetStep) {
            this.executeOneStep();
            this._currentLevel.currentStep += 1;
        }
    }
    executeCommands() {
        const saveModel = false && this._commands.length != 0;
        this._commands.forEach((command) => {
            command.execute();
        });
        this._commands = [];
        if (saveModel) {
            this.saveModel();
        }
    }
    executeOneStep() {
        for (const action of this._actions)
            action.execute(this);
    }
    addCommand(command) {
        this._commands[this._commands.length] = command;
    }
    reload() {
        this._currentLevel = new SimLevel(this._gdRoot, 0);
        this.saveModel();
        this.addCommand(new SimCommandStartNextWave(this._gdRoot, this._currentLevel));
    }
    loadModel() {
        if (!!localStorage.htd) {
            const savedLevel = SimLevel.deserialize(this._gdRoot, localStorage.htd);
            if (!savedLevel)
                return false;
            this._currentLevel = savedLevel;
            return true;
        }
        return false;
    }
    saveModel() {
        localStorage.htd = this._currentLevel.serialize();
    }
}
//# sourceMappingURL=SimMain.js.map