This commit is contained in:
2025-10-19 22:01:31 +02:00
parent 16306f2325
commit 2b4523d644
101 changed files with 2058 additions and 1564 deletions

View File

@@ -1,21 +1,23 @@
#include "resource_helper.hpp"
#include <algorithm>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <algorithm> // Para replace
#include <cstddef> // Para size_t
#include <fstream> // Para basic_ifstream, basic_ostream, basic_ios, operator<<, ios, basic_istream, endl, operator|, basic_istream::read, basic_istream::seekg, basic_istream::tellg, ifstream, streamsize
#include <iostream> // Para cout
#include "resource_loader.hpp" // Para ResourceLoader
namespace ResourceHelper {
static bool resource_system_initialized = false;
bool initializeResourceSystem(const std::string& pack_file) {
auto initializeResourceSystem(const std::string& pack_file) -> bool {
auto& loader = ResourceLoader::getInstance();
resource_system_initialized = loader.initialize(pack_file, true);
if (resource_system_initialized) {
std::cout << "Resource system initialized with pack: " << pack_file << std::endl;
std::cout << "Resource system initialized with pack: " << pack_file << '\n';
} else {
std::cout << "Resource system using fallback mode (filesystem only)" << std::endl;
std::cout << "Resource system using fallback mode (filesystem only)" << '\n';
}
return true; // Always return true as fallback is acceptable
@@ -28,7 +30,7 @@ void shutdownResourceSystem() {
}
}
std::vector<uint8_t> loadFile(const std::string& filepath) {
auto loadFile(const std::string& filepath) -> std::vector<uint8_t> {
if (resource_system_initialized && shouldUseResourcePack(filepath)) {
auto& loader = ResourceLoader::getInstance();
std::string pack_path = getPackPath(filepath);
@@ -45,18 +47,18 @@ std::vector<uint8_t> loadFile(const std::string& filepath) {
return {};
}
std::streamsize fileSize = file.tellg();
std::streamsize file_size = file.tellg();
file.seekg(0, std::ios::beg);
std::vector<uint8_t> data(fileSize);
if (!file.read(reinterpret_cast<char*>(data.data()), fileSize)) {
std::vector<uint8_t> data(file_size);
if (!file.read(reinterpret_cast<char*>(data.data()), file_size)) {
return {};
}
return data;
}
bool shouldUseResourcePack(const std::string& filepath) {
auto shouldUseResourcePack(const std::string& filepath) -> bool {
// Archivos que NO van al pack:
// - config/ (ahora está fuera de data/)
// - archivos absolutos del sistema
@@ -73,11 +75,11 @@ bool shouldUseResourcePack(const std::string& filepath) {
return false;
}
std::string getPackPath(const std::string& asset_path) {
auto getPackPath(const std::string& asset_path) -> std::string {
std::string pack_path = asset_path;
// Normalizar separadores de path a '/'
std::replace(pack_path.begin(), pack_path.end(), '\\', '/');
std::ranges::replace(pack_path, '\\', '/');
// Remover prefijo "data/" si existe
size_t data_pos = pack_path.find("data/");