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

#include "poker.h"

void pokerInit(poker_t *poker, render_t *render) {
  // Load the main shader
  assetShaderLoad(&poker->shader,
    "shaders/textured.vert", "shaders/textured.frag"
  );

  // Load the main font
  assetFontLoad(&poker->font, "fonts/opensans/OpenSans-Bold.ttf");

  // Initialize the render stuffs.
  pokerFrameInit(poker, render);
  pokerWorldInit(poker);
  pokerCardInit(poker);
  pokerPlayerInit(poker);

  // Hand over to the deal for the first time.
  pokerMatchInit(poker);
}

void pokerUpdate(poker_t *poker, render_t *render) {
  // Game Logic
  switch(poker->round) {
    case POKER_ROUND_MATCH:
      pokerMatchUpdate(poker);
      break;
    default:
      break;
  }
  
  // Rendering
  shaderUse(&poker->shader);
  pokerFrameWorld(poker, render);
  pokerWorldRender(poker);
  for(uint8_t pi = 0; pi < POKER_PLAYER_COUNT; pi++) {
    uint8_t seat = pokerPlayerGetSeatForPlayer(pi);
    pokerPlayerRender(poker, poker->players + pi, seat);
  }

  pokerFrameGui(poker, render);
}

void pokerDispose(poker_t * poker) {
  pokerWorldDispose(poker);
  shaderDispose(&poker->shader);
}