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

#include "chip.h"

void holdemRenderChipSet(int32_t count,float x,float y,float z,float yaw) {
  shaderUsePositionAndScale(GAME_STATE.shaderWorld,
    x, y, z,
    0, yaw, 0,
    0.2, 0.2, 0.2
  );
  shaderUseTexture(GAME_STATE.shaderWorld, GAME_STATE.chipTexture);
  primitiveDraw(GAME_STATE.chipPrimitive, 0, -1);
}

pokerposition_t holdemRenderChipGetPosition(uint8_t seat) {
  pokerposition_t position;
  float t, t2;

  position.yaw = HOLDEM_GAME_SEAT_ANGLE(seat);
  position.x = sin(position.yaw) * -0.675;
  position.z = cos(position.yaw) * -0.675;

  t = position.yaw + mathDeg2Rad(90);

  t2 = -0.175;
  position.x += t2 * sin(t);
  position.z += t2 * cos(t);
  return position;
}

void holdemRenderChipInit() {
  GAME_STATE.chipPrimitive = pokerChipCreate();
  GAME_STATE.chipTexture = assetTextureLoad("pokerchip.png");
}

void holdemRenderChip() {
  for(uint8_t seat = 0; seat < 0x08; seat++) {
    pokerposition_t position = holdemRenderChipGetPosition(HOLDEM_GAME_SEAT_PLAYER0);
    holdemRenderChipSet(0, position.x, 0.05, position.z, position.yaw);
  }
}