import { AssetManager } from '../asset-manager';
import { EventBus } from '../event-bus';
import { Input } from '../input';
import Resonator from '../resonator';
import { HTTPLoader } from '../resonator/loaders/http-loader';
import { SceneManager } from '../scene/manager';
import { Scheduler } from '../scheduler';
import { TTS } from '../tts';
import { AriaOutput } from '../tts/outputs/aria';
export class Game extends EventBus {
    constructor(config) {
        super();
        this.config = config;
        this.init();
    }
    init() {
        this.assetManager = new AssetManager(this.config.name, this.config.assetDirectory);
        this.assetLoader = new HTTPLoader();
        this.resonator = new Resonator(this.assetLoader);
        this.input = new Input(this.config.inputTypes, document.body);
        this.tts = new TTS(new AriaOutput());
        this.sceneManager = new SceneManager();
        this.scheduler = new Scheduler(this.config.updatesPerSecond);
        this.emit('ready');
    }
    start() {
        this.scheduler.start();
        this.scheduler.subscribe('update.logic', (dt) => {
            var _a, _b;
            (_a = this.sceneManager.currentScene) === null || _a === void 0 ? void 0 : _a.update(dt);
            (_b = this.world) === null || _b === void 0 ? void 0 : _b.update(dt);
        });
        this.scheduler.subscribe('update.draw', (dt) => { var _a; return (_a = this.sceneManager.currentScene) === null || _a === void 0 ? void 0 : _a.updateDraw(); });
        this.sceneManager.init();
    }
    addScene(scene) {
        this.sceneManager.addScene(scene);
    }
    addDefaultScene(scene) {
        this.sceneManager.addScene(scene);
        this.sceneManager.setDefaultScene(scene);
    }
    setWorld(world) {
        this.world = world;
    }
}
