import { Model } from '../models';
import Locator from '../services/Locator';
import { ViewportOptions } from '../types';

export default class BaseGame
{
    public model: Model;
    constructor()
    {
        this.createScenes();
        this.createModel();
        this.createController();
        this.setListeners();
    }

    protected createScenes() {}

    protected createModel() {}

    protected createController() {}

    protected setListeners()
    {
        Locator.clock.on('tick', (e: number) =>
        {
            this.update(e);
        });

        // @ts-expect-error types
        Locator.viewport.on('resize', (e: ViewportOptions) =>
        {
            this.resize(e);
        });
    }

    public start()
    {
        Locator.clock.run();
        Locator.viewport.resize();
    }

    public update(dtMS: number)
    {
        Locator.scenes.update(dtMS);
        Locator.renderer.render(Locator.viewport);
    }

    resize(resizeData: ViewportOptions)
    {
        Locator.scenes.resize(resizeData);
    }
}
