#include "lang.h" #include // for basic_ifstream, basic_istream, ifstream #include "asset.h" // for Asset // Constructor Lang::Lang(Asset *mAsset) { this->mAsset = mAsset; } // Destructor Lang::~Lang() { } // Inicializa los textos del juego en el idioma seleccionado bool Lang::setLang(Uint8 lang) { std::string file; switch (lang) { case es_ES: file = mAsset->get("es_ES.txt"); break; case en_UK: file = mAsset->get("en_UK.txt"); break; case ba_BA: file = mAsset->get("ba_BA.txt"); break; default: file = mAsset->get("en_UK.txt"); break; } for (int i = 0; i < MAX_TEXT_STRINGS; i++) mTextStrings[i] = ""; bool success = false; std::ifstream rfile(file); if (rfile.is_open() && rfile.good()) { success = true; std::string line; // lee el resto de datos del fichero int index = 0; while (std::getline(rfile, line)) { // Almacena solo las lineas que no empiezan por # o no esten vacias const bool test1 = line.substr(0,1) != "#"; const bool test2 = !line.empty(); if (test1 && test2) { mTextStrings[index] = line; index++; } }; } return success; } // Obtiene la cadena de texto del indice std::string Lang::getText(int index) { return mTextStrings[index]; }