<commit_before>#include "ad/App/UserInterface.h"
#include "ad/World/ConstructionController.h"
#include "ad/World/Entity.h"
#include "ad/World/Generator.h"
#include "ad/World/Prefabs.h"
#include "ad/World/World.h"
#include "canvas/App.h"
#include "canvas/OpenGL.h"
#include "floats/Intersection.h"
#include "hive/PhysicalResourceLocator.h"
#include "legion/Controllers/TopDownCameraController.h"
#include "legion/Resources/ResourceManager.h"
#include "nucleus/FilePath.h"

class AsteroidDefender : public ca::WindowDelegate {
  NU_DELETE_COPY_AND_MOVE(AsteroidDefender);

public:
  AsteroidDefender() : ca::WindowDelegate{"Asteroid Defender"} {}

  ~AsteroidDefender() override = default;

  bool onWindowCreated(ca::Window* window) override {
    if (!WindowDelegate::onWindowCreated(window)) {
      return false;
    }

    ca::Renderer* renderer = window->getRenderer();

    auto assets_path = nu::getCurrentWorkingDirectory() / "assets";
    LOG(Info) << "Assets path: " << assets_path.getPath();
    physical_file_resource_locator_.setRootPath(assets_path);
    resource_manager_.addResourceLocatorBack(&physical_file_resource_locator_);
    resource_manager_.setRenderer(renderer);

    create_prefabs(&prefabs_);

    Generator::generate(&world_, &prefabs_);

    world_camera_.moveTo({0.0f, 0.0f, 5.0f});
    world_camera_.setNearPlane(0.1f);
    world_camera_.setFarPlane(200.0f);

    user_interface_.initialize(renderer);

    return true;
  }

  void onWindowResized(const fl::Size& size) override {
    WindowDelegate::onWindowResized(size);

    screen_size_ = size;

    auto aspect_ratio = le::Camera::aspectRatioFromScreenSize(screen_size_);

    world_camera_.setAspectRatio(aspect_ratio);

    user_interface_.ui().resize(size);
  }

  void onMouseMoved(const ca::MouseEvent& event) override {
    user_interface_.ui().onMouseMoved(event);

    current_mouse_position_ = event.pos;

    current_camera_->onMouseMoved(
        le::Camera::convertScreenPositionToClipSpace(event.pos, screen_size_));
  }

  bool onMousePressed(const ca::MouseEvent& event) override {
    if (user_interface_.ui().onMousePressed(event)) {
      return true;
    }

    if (construction_controller_.is_building() && event.button == ca::MouseEvent::Button::Left) {
      construction_controller_.build();
      return true;
    }

    if (event.button == ca::MouseEvent::Button::Left) {
      auto entity_under_cursor = world_.get_entity_under_cursor();
      if (entity_under_cursor.is_valid()) {
        LOG(Info) << "testing";
      }
    }

    current_camera_->onMousePressed(
        event.button, le::Camera::convertScreenPositionToClipSpace(event.pos, screen_size_));

    return false;
  }

  void onMouseReleased(const ca::MouseEvent& event) override {
    user_interface_.ui().onMouseReleased(event);

    current_camera_->onMouseReleased(
        event.button, le::Camera::convertScreenPositionToClipSpace(event.pos, screen_size_));
  }

  void onMouseWheel(const ca::MouseWheelEvent& event) override {
    user_interface_.ui().onMouseWheel(event);

    current_camera_->onMouseWheel(
        {static_cast<F32>(event.wheelOffset.x), static_cast<F32>(event.wheelOffset.y)});
  }

  void onKeyPressed(const ca::KeyEvent& event) override {
    current_camera_->onKeyPressed(event.key);

    switch (event.key) {
      case ca::Key::LBracket:
        field_of_view_movement_ -= 1.0f;
        break;

      case ca::Key::RBracket:
        field_of_view_movement_ += 1.0f;
        break;

      default:
        break;
    }
  }

  void onKeyReleased(const ca::KeyEvent& event) override {
    current_camera_->onKeyReleased(event.key);

    switch (event.key) {
      case ca::Key::LBracket:
        field_of_view_movement_ += 1.0f;
        break;

      case ca::Key::RBracket:
        field_of_view_movement_ -= 1.0f;
        break;

      default:
        break;
    }
  }

  void tick(F32 delta) override {
    current_camera_->tick(delta);

    {<commit_msg>Use new input interface changes.<commit_after>#include "ad/App/UserInterface.h"
#include "ad/World/ConstructionController.h"
#include "ad/World/Entity.h"
#include "ad/World/Generator.h"
#include "ad/World/Prefabs.h"
#include "ad/World/World.h"
#include "canvas/App.h"
#include "canvas/OpenGL.h"
#include "floats/Intersection.h"
#include "hive/PhysicalResourceLocator.h"
#include "legion/Controllers/TopDownCameraController.h"
#include "legion/Resources/ResourceManager.h"
#include "nucleus/FilePath.h"

class AsteroidDefender : public ca::WindowDelegate {
  NU_DELETE_COPY_AND_MOVE(AsteroidDefender);

public:
  AsteroidDefender() : ca::WindowDelegate{"Asteroid Defender"} {}

  ~AsteroidDefender() override = default;

  bool onWindowCreated(ca::Window* window) override {
    if (!WindowDelegate::onWindowCreated(window)) {
      return false;
    }

    ca::Renderer* renderer = window->getRenderer();

    auto assets_path = nu::getCurrentWorkingDirectory() / "assets";
    LOG(Info) << "Assets path: " << assets_path.getPath();
    physical_file_resource_locator_.setRootPath(assets_path);
    resource_manager_.addResourceLocatorBack(&physical_file_resource_locator_);
    resource_manager_.setRenderer(renderer);

    create_prefabs(&prefabs_);

    Generator::generate(&world_, &prefabs_);

    world_camera_.moveTo({0.0f, 0.0f, 5.0f});
    world_camera_.setNearPlane(0.1f);
    world_camera_.setFarPlane(200.0f);

    user_interface_.initialize(renderer);

    return true;
  }

  void onWindowResized(const fl::Size& size) override {
    WindowDelegate::onWindowResized(size);

    screen_size_ = size;

    auto aspect_ratio = le::Camera::aspectRatioFromScreenSize(screen_size_);

    world_camera_.setAspectRatio(aspect_ratio);

    user_interface_.ui().resize(size);
  }

  void on_mouse_moved(const ca::MouseEvent& event) override {
    user_interface_.ui().on_mouse_moved(event);

    current_mouse_position_ = event.pos;

    current_camera_->onMouseMoved(
        le::Camera::convertScreenPositionToClipSpace(event.pos, screen_size_));
  }

  bool onMousePressed(const ca::MouseEvent& event) override {
    if (user_interface_.ui().on_mouse_pressed(event)) {
      return true;
    }

    if (construction_controller_.is_building() && event.button == ca::MouseEvent::Button::Left) {
      construction_controller_.build();
      return true;
    }

    if (event.button == ca::MouseEvent::Button::Left) {
      auto entity_under_cursor = world_.get_entity_under_cursor();
      if (entity_under_cursor.is_valid()) {
        LOG(Info) << "testing";
      }
    }

    current_camera_->onMousePressed(
        event.button, le::Camera::convertScreenPositionToClipSpace(event.pos, screen_size_));

    return false;
  }

  void on_mouse_released(const ca::MouseEvent& event) override {
    user_interface_.ui().on_mouse_released(event);

    current_camera_->onMouseReleased(
        event.button, le::Camera::convertScreenPositionToClipSpace(event.pos, screen_size_));
  }

  void on_mouse_wheel(const ca::MouseWheelEvent& event) override {
    user_interface_.ui().on_mouse_wheel(event);

    current_camera_->onMouseWheel(
        {static_cast<F32>(event.wheelOffset.x), static_cast<F32>(event.wheelOffset.y)});
  }

  void on_key_pressed(const ca::KeyEvent& event) override {
    current_camera_->onKeyPressed(event.key);

    switch (event.key) {
      case ca::Key::LBracket:
        field_of_view_movement_ -= 1.0f;
        break;

      case ca::Key::RBracket:
        field_of_view_movement_ += 1.0f;
        break;

      default:
        break;
    }
  }

  void on_key_released(const ca::KeyEvent& event) override {
    current_camera_->onKeyReleased(event.key);

    switch (event.key) {
      case ca::Key::LBracket:
        field_of_view_movement_ += 1.0f;
        break;

      case ca::Key::RBracket:
        field_of_view_movement_ -= 1.0f;
        break;

      default:
        break;
    }
  }

  void tick(F32 delta) override {
    current_camera_->tick(delta);

    {
{'fraction_non_alphanumeric': 0.12633295696901267, 'fraction_numerical': 0.006523648224814954, 'mean_word_length': 4.051964512040557, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '340402', 'n_tokens_mistral': 2675, 'n_tokens_neox': 2559, 'n_words': 386}