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

#include "pokergame.h"

bool pokerGameInit(game_t *game) {
  pokergame_t *pokerGame = &game->pokerGame;

  // Load the Assets.
  pokerGameAssetsInit(&pokerGame->assets);

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

  // Initialize the world
  pokerWorldInit(pokerGame);

  vncharacter_t *character = pokerGame->scene.characters + 0;
  vnCharacterInit(character, &pokerGame->assets.pennyTexture, 
    1000, 1920,
    367,256, 280,280
  );
  character->y = -1.7f;
  character->z = -0.3f;

  pokerGame->scene.characterCount++;


  // Initialize the UI.
  pokerUiInit(pokerGame);

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

  return true;
} 

void pokerGameUpdate(game_t *game) {
  pokergame_t *pokerGame;
  pokerGame = &game->pokerGame;

  // Update the VN Engine.
  vnSceneUpdate(&pokerGame->scene, &game->engine);

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

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

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

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

void pokerGameDispose(game_t *game) {
  pokergame_t *pokerGame;
  pokerGame = &game->pokerGame;

  //Cleanup the UI
  pokerUiDispose(pokerGame);

  // Cleanup the world
  pokerWorldDispose(pokerGame);

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

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