//
// Created by sebastian on 02.08.26.
//

#include "BoardLayout.h"

#include <format>
#include "spdlog/spdlog.h"

glm::vec3 ludo::BoardLayout::getWorldPosition(ludo::PlayerColor color, ludo::PieceState state, int position) const {
    std::string fieldName;
    switch (state) {
        case ludo::PieceState::AtHome:
            fieldName = std::format("Home_{}_{}", ludo::toString(color), position); break;
        case ludo::PieceState::OnTrack:
            fieldName = std::format("Track_{:02}", position); break;
        case ludo::PieceState::InHomeStretch:
        case ludo::PieceState::Finished:
            fieldName = std::format("Ziel_{}_{}", toString(color), position); break;

    }

    auto it = m_positions.find(fieldName);
    if (it == m_positions.end()) {
        spdlog::warn("BoardLayout: Feld '{}' nicht gefunden", fieldName);
        return glm::vec3(0.0f);
    }
    return it->second;
}