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

#include "testscene.h"

void testSceneInit(testscene_t *scene, game_t *game) {
  assetFontLoad(&scene->font, "fonts/opensans/OpenSans-Bold.ttf");
  assetShaderLoad(&scene->shader,
    "shaders/textured.vert", "shaders/textured.frag"
  );

  // Init Conversation
  // vnConversationInit(&scene->conversation, &scene->font);
  scene->conversation.textbox.linesMax = 3;
  scene->conversation.textbox.widthMax = game->engine.render.width;

  // Load characters
  assetTextureLoad(&scene->pennyEyes, "characters/penny/textures/eyes_sm.png");
  assetTextureLoad(&scene->pennyBody, "characters/penny/textures/body_sm.png");
  assetTextureLoad(&scene->pennyMouth,"characters/penny/textures/mouth_sm.png");
  assetTextureLoad(&scene->pennyFace, "characters/penny/textures/face_sm.png");
  
  vnCharacterInit(&scene->character1,
    &scene->pennyEyes,
    &scene->pennyBody,
    &scene->pennyMouth,
    &scene->pennyFace
  );
  
  vnCharacterInit(&scene->character2,
    &scene->pennyEyes,
    &scene->pennyBody,
    &scene->pennyMouth,
    &scene->pennyFace
  );

  scene->character1.x = 0;
  scene->character2.x = 1;
  scene->character1.y = 0;
  scene->character2.y = 0;

  // Add some conversation peices.
  vnConversationTalk(&scene->conversation, "Hello World", &scene->character1);
  queueDelay(&scene->conversation.actionQueue, 1);
  vnConversationTalk(&scene->conversation, "What?", &scene->character2);
  queueNext(&scene->conversation.actionQueue);
}

void testSceneRender(testscene_t *scene, game_t *game) {
  cameraLookAt(&scene->camera,
    0.5, 0.5, 0.75,
    0.5, 0.5, -0.5
  );
  cameraPerspective(&scene->camera, 75,
    game->engine.render.width/game->engine.render.height, 0.01, 1000.0
  );

  shaderUse(&scene->shader);
  shaderUseCamera(&scene->shader, &scene->camera);

  vnCharacterUpdate(&scene->character1, &game->engine);
  vnCharacterUpdate(&scene->character2, &game->engine);
  vnConversationUpdate(&scene->conversation, &game->engine);

  vnCharacterRender(&scene->character1, &scene->shader);
  vnCharacterRender(&scene->character2, &scene->shader);

  
  cameraLookAt(&scene->camera,
    0, 0, 10,
    0, 0, 0
  );

  cameraOrtho(&scene->camera,
    0, game->engine.render.width,
    game->engine.render.height, 0,
    0.01, 1000.0
  );
  shaderUseCamera(&scene->shader, &scene->camera);
  vnConversationRender(&scene->conversation, &scene->shader);
}