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

#include "player.h"

void holdemRenderPlayerInit(poker_t *poker) {
  

  GAME_STATE.kagamiTexture = assetTextureLoad("kagami.png");
  GAME_STATE.kagamiTileset = tilesetCreate(3, 2,
    GAME_STATE.kagamiTexture->width,
    GAME_STATE.kagamiTexture->height,
    0, 0, 0, 0
  );
  GAME_STATE.kagamiQuad = quadCreate(0, 0, 0, 0, 0, 1, 1, 1, 1);
}

uint8_t holdemRenderPlayerGetSeatForPlayer(uint8_t player) { 
  switch(player) {
    case 0x01:
      return HOLDEM_GAME_SEAT_PLAYER1;
    case 0x02:
      return HOLDEM_GAME_SEAT_PLAYER2;
    case 0x03:
      return HOLDEM_GAME_SEAT_PLAYER3;
    case 0x04:
      return HOLDEM_GAME_SEAT_PLAYER4;
    default:
      return HOLDEM_GAME_SEAT_PLAYER0;
  }
}

void holdemRenderPlayer(uint8_t seat) {
  float x, z, angle;

  // Determine position
  angle = HOLDEM_GAME_SEAT_ANGLE(seat);
  x = sin(angle) * -1;
  z = cos(angle) * -1;

  // Determine size
  float w, h;
  w = 0.6, h = (
    (float)GAME_STATE.kagamiTileset->divY /
    (float)GAME_STATE.kagamiTileset->divX
  ) * w;

  // Animation
  int i = (int32_t)(TIME_STATE.current*10)%GAME_STATE.kagamiTileset->count;
  quadBuffer(GAME_STATE.kagamiQuad, 0,
    -w/2, -h/2,
    GAME_STATE.kagamiTileset->divisions[i].x0,
    GAME_STATE.kagamiTileset->divisions[i].y1,
    w/2, h/2,
    GAME_STATE.kagamiTileset->divisions[i].x1,
    GAME_STATE.kagamiTileset->divisions[i].y0,
    0, 0
  );

  // Render
  shaderUseTexture(GAME_STATE.shaderWorld, GAME_STATE.kagamiTexture);
  shaderUsePosition(GAME_STATE.shaderWorld,
    x, 0.34, z,
    0, angle, 0
  );
  primitiveDraw(GAME_STATE.kagamiQuad, 0, -1);
}