integracions de texture.cpp amb ResourceHelper
This commit is contained in:
@@ -367,16 +367,33 @@ auto Texture::readPalFile(const std::string &file_path) -> Palette {
|
|||||||
Palette palette{};
|
Palette palette{};
|
||||||
palette.fill(0); // Inicializar todo con 0 (transparente por defecto)
|
palette.fill(0); // Inicializar todo con 0 (transparente por defecto)
|
||||||
|
|
||||||
std::ifstream file(file_path);
|
// Intentar cargar desde ResourceHelper primero
|
||||||
if (!file.is_open()) {
|
auto resource_data = ResourceHelper::loadFile(file_path);
|
||||||
throw std::runtime_error("No se pudo abrir el archivo .pal");
|
std::istringstream stream;
|
||||||
|
bool using_resource_data = false;
|
||||||
|
|
||||||
|
if (!resource_data.empty()) {
|
||||||
|
std::string content(resource_data.begin(), resource_data.end());
|
||||||
|
stream.str(content);
|
||||||
|
using_resource_data = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fallback a archivo directo
|
||||||
|
std::ifstream file;
|
||||||
|
if (!using_resource_data) {
|
||||||
|
file.open(file_path);
|
||||||
|
if (!file.is_open()) {
|
||||||
|
throw std::runtime_error("No se pudo abrir el archivo .pal");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::istream& input_stream = using_resource_data ? stream : static_cast<std::istream&>(file);
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
int line_number = 0;
|
int line_number = 0;
|
||||||
int color_index = 0;
|
int color_index = 0;
|
||||||
|
|
||||||
while (std::getline(file, line)) {
|
while (std::getline(input_stream, line)) {
|
||||||
++line_number;
|
++line_number;
|
||||||
|
|
||||||
// Ignorar las tres primeras líneas del archivo
|
// Ignorar las tres primeras líneas del archivo
|
||||||
@@ -401,6 +418,8 @@ auto Texture::readPalFile(const std::string &file_path) -> Palette {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close();
|
if (!using_resource_data && file.is_open()) {
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
return palette;
|
return palette;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user