#include "game.h"
#include "menu.h"
#include "level.h"
#include <editor/editor.h>

namespace game {

Scene *currentScene;
Scene *nextScene;
Scene *scenes[3];

void Init()
{
    currentScene = nullptr;
    nextScene = nullptr;

    scenes[0] = new Menu();
    scenes[1] = new Level();
    scenes[2] = new editor::Editor();
}

void Free()
{
    for (auto i: scenes) {
        delete i;
    }
}


Level *GetLevel()
{
    return (Level*) scenes[1];
}

Menu *GetMenu()
{
    return (Menu*) scenes[0];
}

void SetState(gameState state)
{
    if (currentScene == scenes[(int) state]) {
        return;
    }

    nextScene = scenes[(int) state];
}

void Update()
{
    if (nextScene) {
        if (currentScene) {
            currentScene->Hide();
        }

        currentScene = nextScene;
        currentScene->Show();
        nextScene = nullptr;
    }

    currentScene->Update();
}


void Render()
{
    currentScene->Render();
}

}

