51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
#include "lang.h"
|
|
#include <fstream> // Para basic_ifstream, basic_istream, ifstream
|
|
#include <vector> // Para vector
|
|
|
|
namespace lang
|
|
{
|
|
std::vector<std::string> texts; // Vector con los textos
|
|
|
|
// Inicializa los textos del juego en el idioma seleccionado
|
|
bool loadFromFile(std::string file_path)
|
|
{
|
|
texts.clear();
|
|
|
|
bool success = false;
|
|
|
|
std::ifstream rfile(file_path);
|
|
if (rfile.is_open() && rfile.good())
|
|
{
|
|
success = true;
|
|
std::string line;
|
|
|
|
// Lee el resto de datos del fichero
|
|
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)
|
|
{
|
|
texts.push_back(line);
|
|
}
|
|
};
|
|
}
|
|
|
|
return success;
|
|
}
|
|
|
|
// Obtiene la cadena de texto del indice
|
|
std::string getText(int index)
|
|
{
|
|
return texts.at(index);
|
|
}
|
|
|
|
// Obtiene el codigo del idioma del siguiente idioma
|
|
Code getNextLangCode(Code lang)
|
|
{
|
|
auto index = static_cast<int>(lang);
|
|
index = (index + 1) % 3;
|
|
return static_cast<Code>(index);
|
|
}
|
|
} |