/**
 * Copyright (c) 2021 Dominic Masters
 * 
 * This software is released under the MIT License.
 * https://opensource.org/licenses/MIT
 */

#include "game.h"

bool pokerGameInit(pokergame_t *game) {
  // Load the Assets.
  pokerGameAssetsInit(&game->assets);

  // Initialize the Visual Novel Engine.
  vnSceneInit(&game->scene,
    &game->assets.font,
    &game->assets.testTexture
  );

  // Initialize the world
  pokerWorldInit(&game->world, &game->scene, &game->assets);

  // Initialize the UI.
  pokerUiInit(&game->ui);

  // Add the first action, the game action, and then start the action queue.
  pokerGameActionStartAdd(game);
  queueNext(&game->scene.conversation.actionQueue);

  return true;
} 

void pokerGameUpdate(pokergame_t *game) {
  // Update the VN Engine.
  vnSceneUpdate(&game->scene, &game->engine);

  // Update the UI
  pokerUiUpdate(
    &game->ui,
    &game->engine,
    &game->assets.shader,
    game->scene.characters,
    game->poker.players
  );


  // Bind the shader.
  shaderUse(&game->assets.shader);

  // Render the visual novel scene.
  vnSceneRenderWorld(&game->scene, &game->engine, &game->assets.shader);

  pokerWorldRender(&game->world, &game->assets);
  vnSceneRenderCharacters(&game->scene, &game->assets.shader);

  // Render the UI
  vnSceneRenderGui(&game->scene, &game->engine, &game->assets.shader);
  pokerUiRender(&game->ui, &game->engine, &game->assets, &game->poker);
}

void pokerGameDispose(pokergame_t *game) {
  //Cleanup the UI
  pokerUiDispose(&game->ui);

  // Cleanup the world
  pokerWorldDispose(&game->world);

  // Destroy the Visual Novel engine.
  vnSceneDispose(&game->scene);

  // Unload all assets
  pokerGameAssetsDispose(&game->assets);
}
