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

#include "world.h"

void holdemRenderWorldInit() {
  GAME_STATE.tablePrimitive = pokerTableCreate();
  GAME_STATE.tableTexture = assetTextureLoad("pokertable.png");
}

void holdemRenderWorld() {
  uint8_t i, j;
  pokerplayer_t *player;
  uint8_t seat;

  // Poker Table
  shaderUsePositionAndScale(GAME_STATE.shaderWorld,
    0, -0.01, 0,
    0, 0, 0,
    3.4, 3.4, 3.4
  );
  shaderUseTexture(GAME_STATE.shaderWorld, GAME_STATE.tableTexture);
  primitiveDraw(GAME_STATE.tablePrimitive, 0, -1);

  // Render the dealer and her hand
  holdemRenderPlayer(HOLDEM_GAME_SEAT_DEALER);
  for(i = 0x00; i < GAME_STATE.cardsFacing; i++) {
    holdemRenderCardForSeat(
      HOLDEM_GAME_SEAT_DEALER,
      GAME_STATE.cards[i],
      HOLDEM_GAME_CARD_SLOT_FLOP0 + i
    );
  }

  // Test
  for(i = 0x00; i < POKER_PLAYER_COUNT; i++) {
    player = GAME_STATE.players + i;
    seat = holdemRenderPlayerGetSeatForPlayer(i);
    holdemRenderPlayer(seat);

    if(player->state & POKER_PLAYER_STATE_SHOWING) continue;

    for(j = 0x00; j < player->cardCount; j++) {
      holdemRenderCardForSeat(seat, player->cards[j], HOLDEM_GAME_CARD_SLOT_HAND0+j);
    }
  }

  holdemRenderChip();
}