#include "arena_fsm.hpp"
#include "textures.hpp"
#include "sound.hpp"
#include "ai.hpp"
#include "animation.hpp"
#include <iostream>

int main(int argc, char* argv[]) {
  try {
    dbc::check(argc == 2, "USAGE: arena enemy_name");
    std::string enemy_name{argv[1]};

    textures::init();
    sound::init();
    ai::init("assets/ai.json");
    animation::init();

    sound::mute(false);
    sound::play("ambient_1", true);

    arena::FSM main(enemy_name);

    main.event(arena::Event::STARTED);

    while(main.active()) {
      main.render();

      // ZED: need to sort out how to deal with this in the FSM
      if(main.in_state(arena::State::IDLE)) {
        main.event(arena::Event::TICK);
      }

      main.keyboard_mouse();

      main.handle_world_events();
    }

    return 0;
  } catch(const std::system_error& e) {
    std::cout << "WARNING: On OSX you'll get this error on shutdown.\n";
    std::cout << "Caught system_error with code "
                 "[" << e.code() << "] meaning "
                 "[" << e.what() << "]\n";
  }
}