#include <catch2/catch_test_macros.hpp>
#include "animation.hpp"
#include "dinkyecs.hpp"
#include "config.hpp"
#include <iostream>

using namespace components;
using namespace textures;

TEST_CASE("animation easing tests", "[animation]") {
  Animation anim;

  anim.easing = ease::NONE;
  float res = anim.twitching();
  REQUIRE(res == 0.0);

  anim.easing = ease::SINE;
  anim.subframe = 1.0f;
  res = anim.twitching();
  REQUIRE(!std::isnan(res));

  anim.easing = ease::OUT_CIRC;
  res = anim.twitching();
  REQUIRE(!std::isnan(res));

  anim.easing = ease::OUT_BOUNCE;
  res = anim.twitching();
  REQUIRE(!std::isnan(res));

  anim.easing = ease::IN_OUT_BACK;
  res = anim.twitching();
  REQUIRE(!std::isnan(res));

  anim.easing = ease::FUCKFACE;
  bool throws = false;
  try { anim.twitching(); } catch(...) { throws = true; }
  REQUIRE(throws);
}


TEST_CASE("animation utility API", "[animation]") {
  textures::init();
  animation::init();

  auto blanket = textures::get("ritual_crafting_area");
  auto anim = animation::load("ritual_blanket");

  anim.play();

  while(animation::apply(anim, blanket)) {
    fmt::println("animation: {}", anim.subframe);
  }
}