#include "lang.h" #include #include #include "json.hpp" using json = nlohmann::json; namespace lang { std::unordered_map texts; // Inicializa los textos del juego en el idioma seleccionado bool loadFromFile(const std::string &file_path) { texts.clear(); std::ifstream rfile(file_path); if (!rfile.is_open()) return false; try { json j; rfile >> j; for (auto &el : j.items()) { texts[el.key()] = el.value(); } } catch (const std::exception &e) { // Puedes loguear el error si quieres return false; } return true; } // Obtiene el texto por clave std::string getText(const std::string &key) { auto it = texts.find(key); if (it != texts.end()) return it->second; else return "[missing text: " + key + "]"; } // Obtiene el código del siguiente idioma disponible Code getNextLangCode(Code lang) { auto index = static_cast(lang); index = (index + 1) % 3; return static_cast(index); } }