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

#pragma once
#include <dawn/dawn.h>
#include "../display/texture.h"
#include "../display/tileset.h"
#include "../display/primitive.h"
#include "../display/shader.h"
#include "../display/primitives/quad.h"
#include "../display/animation/animation.h"

/**
 * Initialize a VN Character.
 * 
 * @param character Character to initialize.
 * @param texture The characters' texture.
 * @param baseWidth The width of the base character within the texture.
 * @param baseHeight The height of the base character within the texture.
 * @param faceX The X position on the face that the faces are cropped.
 * @param faceY The Y position on the face that the faces are cropped.
 * @param faceWidth The width of the cropped face.
 * @param faceHeight The height of the cropped face.
 */
void vnCharacterInit(
  vncharacter_t *character, texture_t *texture,
  int32_t baseWidth, int32_t baseHeight,
  int32_t faceX, int32_t faceY,
  int32_t faceWidth, int32_t faceHeight
);

/**
 * Buffer part of a VN Character texture onto the primitive. All the below units
 * are believed to be in pixels, the relatives will be recalculated on the fly.
 * 
 * @param character Character to buffer to.
 * @param x Local X position of the VN Character to buffer to.
 * @param y Local Y positon of the VN character to buffer to.
 * @param width Width of the subarea.
 * @param height Height of the subarea.
 * @param tx Texture X position.
 * @param ty Texture Y position.
 * @param i Quad index to buffer to.
 */
void _vnCharacterBuffer(vncharacter_t *character,
  int32_t x, int32_t y, int32_t width, int32_t height, int32_t tx, int32_t ty,
  int32_t i
);

/**
 * Buffer the face of a VN Character to the primitive.
 * 
 * @param character Character to buffer to.
 * @param col Face Column.
 * @param i Quad index to buffer to.
 */
void _vnCharacterFaceBuffer(vncharacter_t *character, int32_t col, int32_t i);

void vnCharacterUpdate(vncharacter_t *character, engine_t *engine);
void vnCharacterRender(vncharacter_t *character, shader_t *shader);

void vnCharacterDispose(vncharacter_t *character);