package de.frajul.endlessroll.rendering;

import android.content.Context;
import android.view.View;

import de.frajul.endlessroll.data.Vector;
import de.frajul.endlessroll.entities.textures.TexturePack;
import de.frajul.endlessroll.main.GameActivity;
import de.frajul.endlessroll.main.game.Scene;
import de.frajul.endlessroll.main.game.Timer;

/**
 * Created by Julian on 26.11.2015.
 */
public abstract class Rendering<S extends Scene> implements View.OnTouchListener {

    protected S scene;
    private GameActivity gameActivity;
    private boolean alreadyInitiated = false;

    public Rendering(GameActivity gameActivity) {
        this.gameActivity = gameActivity;
    }

    public void initiate(TexturePack texturePack, Timer timer) {
        this.scene = init(texturePack, timer, !alreadyInitiated);
        alreadyInitiated = true;
    }

    protected abstract S init(TexturePack texturePack, Timer timer, boolean isFirstTime);

    public abstract void update();

    public void onException(Exception e) {
        gameActivity.onException(e);
    }

    public void setScreenSize(int width, int height) {
        if (scene != null)
            scene.setScreenSize(new Vector(width, height));
    }

    public Scene getScene() {
        return scene;
    }

    public Context getContext() {
        return gameActivity;
    }

}
