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

#include "pokerworld.h"

void pokerWorldInit(
  pokerworld_t *world,
  vnscene_t *scene,
  pokergameassets_t *assets
) {
  vncharacter_t *character;
  uint8_t i;
  
  world->seat = POKER_WORLD_SEAT_DEALER;
  world->seatTime = 0;

  // Initialize the skywal
  skywallInit(&world->skywall);

  // Initialize the players
  for(i = 0x00; i < POKER_PLAYER_COUNT_MAX; i++) {
    character = scene->characters + scene->characterCount;
    vnCharacterInit(character, &assets->pennyTexture, 
      POKER_WORLD_PENNY_BASE_WIDTH, POKER_WORLD_PENNY_BASE_HEIGHT,
      POKER_WORLD_PENNY_FACE_X, POKER_WORLD_PENNY_FACE_Y,
      POKER_WORLD_PENNY_FACE_WIDTH, POKER_WORLD_PENNY_FACE_HEIGHT
    );
    character->x = POKER_WORLD_SEAT_POSITION_X(POKER_WORLD_SEAT_FOR_PLAYER(i));
    character->y = POKER_WORLD_SEAT_POSITION_Y;
    character->z = POKER_WORLD_SEAT_POSITION_Z(POKER_WORLD_SEAT_FOR_PLAYER(i)); 
    character->yaw = POKER_WORLD_SEAT_ROTATION(POKER_WORLD_SEAT_FOR_PLAYER(i));
    scene->characterCount++;
  }
}

void pokerWorldLookAtPlayer(
  vnscene_t *scene, uint8_t playerIndex
) {
  vncharacter_t *character = scene->characters + playerIndex;
  vnSceneLookAt(scene,
    scene->cameraLook.x,
    scene->cameraLook.y,
    scene->cameraLook.z,
    character->x,
    scene->cameraLook.lookY,
    character->z
  );
}

void pokerWorldRender(pokerworld_t *world, pokergameassets_t *assets) {
  // Render the wall
  shaderUseTexture(&assets->shader, &assets->roomTexture);
  shaderUsePosition(&assets->shader, 0,2,0, 0,0,0);
  primitiveDraw(&world->skywall, 0, -1);
}

void pokerWorldDispose(pokerworld_t *world) {
  primitiveDispose(&world->skywall);
}