//
// Created by sebastian on 08.02.26.
//

#include "TileInteractionSystem.h"

#include "../engine/layer/entities/Camera.h"
#include "../engine/platform/glfw/InputManager.h"
#include "../engine/renderer/model/AssetManager.h"
#include "GLFW/glfw3.h"

void TileInteractionSystem::update(Map &map, const Camera &camera, const MousePicker &mousePicker) {
    for (HexTile& tile : map.tiles) {
        glm::vec3 intersectionPoint;
        tile.isHighlighted = tile.intersect(camera.getPosition(), mousePicker.getCurrentRay(), intersectionPoint);
    }


}

void TileInteractionSystem::handleBuildAction(Map &map) {
    for (HexTile& tile : map.tiles) {
        if (tile.isHighlighted && InputManager::isMouseButtonPressed(GLFW_MOUSE_BUTTON_1)) {
            if (!tile.building && tile.resourceType == RessourceType::WOOD) {
                tile.entitiesOnTile.clear();
                tile.building = std::make_shared<Entity>(AssetManager::getModel("cabin"), tile.worldPos, 0,0,0,1.f);
            }
        }
    }
}
