resource.pack
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
#include "lang.h"
|
||||
|
||||
#include <fstream> // for basic_ifstream, basic_istream, ifstream
|
||||
#include <sstream>
|
||||
|
||||
#include "asset.h" // for Asset
|
||||
#include "resource_helper.h"
|
||||
|
||||
// Constructor
|
||||
Lang::Lang(Asset *mAsset) {
|
||||
@@ -38,27 +40,27 @@ bool Lang::setLang(Uint8 lang) {
|
||||
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++;
|
||||
}
|
||||
};
|
||||
// Lee el fichero via ResourceHelper (pack o filesystem)
|
||||
auto bytes = ResourceHelper::loadFile(file);
|
||||
if (bytes.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return success;
|
||||
std::string content(reinterpret_cast<const char *>(bytes.data()), bytes.size());
|
||||
std::stringstream ss(content);
|
||||
std::string line;
|
||||
int index = 0;
|
||||
while (std::getline(ss, 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 true;
|
||||
}
|
||||
|
||||
// Obtiene la cadena de texto del indice
|
||||
|
||||
Reference in New Issue
Block a user