package nl.joozey.games.asmallworld;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;

/**
 * Created by mint on 22-4-17.
 */

public class SceneControl {

    private OrthographicCamera camera;
    private IntroScene introScene;
    private OutroScene outroScene;
    private MainGame mainGame;

    private Scene currentScene;

    public SceneControl() {
        camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        resetCamera();

        showIntro();
//        showMainGame();
//        showOutro();
    }

    private void resetCamera() {
        camera.position.set(Gdx.graphics.getWidth() * .5f, Gdx.graphics.getHeight() * .5f, 0f);
        camera.zoom = 1;
    }

    public OrthographicCamera getCamera() {
        return camera;
    }

    public Scene getCurrentScene() {
        return currentScene;
    }

    public void showIntro() {
        disposeAll();
        resetCamera();
        introScene = new IntroScene();
        introScene.setSceneControl(this);
        currentScene = introScene;
        Gdx.input.setInputProcessor(currentScene);
    }

    public void showOutro() {
        disposeAll();
        resetCamera();
        outroScene = new OutroScene();
        outroScene.setSceneControl(this);
        currentScene = outroScene;
        Gdx.input.setInputProcessor(currentScene);
    }

    public void showMainGame() {
        disposeAll();
        resetCamera();
        mainGame = new MainGame();
        mainGame.setSceneControl(this);
        currentScene = mainGame;
        Gdx.input.setInputProcessor(currentScene);
    }

    public void disposeAll() {
        currentScene = null;

        if(introScene != null) {
            introScene.dispose();
            introScene = null;
        }

        if(outroScene != null) {
            outroScene.dispose();
            outroScene = null;
        }

        if(mainGame != null) {
            mainGame.dispose();
            mainGame = null;
        }
    }
}
