integrades mes clases amb ResourceHelper
mogudes les dades de la demo a resource.pack
This commit is contained in:
@@ -16,10 +16,12 @@ DATA|${PREFIX}/config/param_320x256.txt
|
|||||||
DATA|${PREFIX}/config/param_red.txt
|
DATA|${PREFIX}/config/param_red.txt
|
||||||
DATA|${PREFIX}/config/pools.txt
|
DATA|${PREFIX}/config/pools.txt
|
||||||
DATA|${PREFIX}/config/stages.txt
|
DATA|${PREFIX}/config/stages.txt
|
||||||
DEMODATA|${PREFIX}/config/demo1.bin
|
|
||||||
DEMODATA|${PREFIX}/config/demo2.bin
|
|
||||||
|
|
||||||
# Música (archivos empaquetados)
|
# Archivos con los datos de la demo
|
||||||
|
DEMODATA|${PREFIX}/data/demo/demo1.bin
|
||||||
|
DEMODATA|${PREFIX}/data/demo/demo2.bin
|
||||||
|
|
||||||
|
# Música
|
||||||
MUSIC|${PREFIX}/data/music/credits.ogg
|
MUSIC|${PREFIX}/data/music/credits.ogg
|
||||||
MUSIC|${PREFIX}/data/music/intro.ogg
|
MUSIC|${PREFIX}/data/music/intro.ogg
|
||||||
MUSIC|${PREFIX}/data/music/playing.ogg
|
MUSIC|${PREFIX}/data/music/playing.ogg
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
BIN
resources.pack
BIN
resources.pack
Binary file not shown.
@@ -11,6 +11,7 @@
|
|||||||
#include "difficulty.h" // Para Difficulty
|
#include "difficulty.h" // Para Difficulty
|
||||||
#include "external/json.hpp" // Para basic_json, iteration_proxy_value, oper...
|
#include "external/json.hpp" // Para basic_json, iteration_proxy_value, oper...
|
||||||
#include "options.h" // Para SettingsOpt...
|
#include "options.h" // Para SettingsOpt...
|
||||||
|
#include "resource_helper.h" // Para ResourceHelper
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
@@ -27,14 +28,24 @@ std::vector<Language> languages = {
|
|||||||
auto loadFromFile(const std::string &file_path) -> bool {
|
auto loadFromFile(const std::string &file_path) -> bool {
|
||||||
texts.clear();
|
texts.clear();
|
||||||
|
|
||||||
std::ifstream rfile(file_path);
|
// Intentar cargar desde ResourceHelper primero
|
||||||
if (!rfile.is_open()) {
|
auto resource_data = ResourceHelper::loadFile(file_path);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
json j;
|
json j;
|
||||||
rfile >> j;
|
|
||||||
|
if (!resource_data.empty()) {
|
||||||
|
// Cargar desde datos del pack
|
||||||
|
std::string content(resource_data.begin(), resource_data.end());
|
||||||
|
j = json::parse(content);
|
||||||
|
} else {
|
||||||
|
// Fallback a filesystem directo
|
||||||
|
std::ifstream rfile(file_path);
|
||||||
|
if (!rfile.is_open()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
rfile >> j;
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto &el : j.items()) {
|
for (const auto &el : j.items()) {
|
||||||
texts[el.key()] = el.value();
|
texts[el.key()] = el.value();
|
||||||
|
|||||||
@@ -225,22 +225,30 @@ auto Texture::loadSurface(const std::string &file_path) -> std::shared_ptr<Surfa
|
|||||||
// Libera la superficie actual
|
// Libera la superficie actual
|
||||||
unloadSurface();
|
unloadSurface();
|
||||||
|
|
||||||
// Abrir el archivo usando std::ifstream para manejo automático del recurso
|
std::vector<Uint8> buffer;
|
||||||
std::ifstream file(file_path, std::ios::binary | std::ios::ate);
|
|
||||||
if (!file) {
|
// Intentar cargar desde ResourceHelper primero
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", file_path.c_str());
|
auto resource_data = ResourceHelper::loadFile(file_path);
|
||||||
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
if (!resource_data.empty()) {
|
||||||
}
|
buffer = resource_data;
|
||||||
|
} else {
|
||||||
|
// Fallback a filesystem directo
|
||||||
|
std::ifstream file(file_path, std::ios::binary | std::ios::ate);
|
||||||
|
if (!file) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", file_path.c_str());
|
||||||
|
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||||
|
}
|
||||||
|
|
||||||
// Obtener el tamaño del archivo
|
// Obtener el tamaño del archivo
|
||||||
std::streamsize size = file.tellg();
|
std::streamsize size = file.tellg();
|
||||||
file.seekg(0, std::ios::beg);
|
file.seekg(0, std::ios::beg);
|
||||||
|
|
||||||
// Leer el contenido del archivo en un buffer
|
// Leer el contenido del archivo en un buffer
|
||||||
std::vector<Uint8> buffer(size);
|
buffer.resize(size);
|
||||||
if (!file.read(reinterpret_cast<char *>(buffer.data()), size)) {
|
if (!file.read(reinterpret_cast<char *>(buffer.data()), size)) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error al leer el fichero %s", file_path.c_str());
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error al leer el fichero %s", file_path.c_str());
|
||||||
throw std::runtime_error("Error al leer el fichero: " + file_path);
|
throw std::runtime_error("Error al leer el fichero: " + file_path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crear un objeto Gif y llamar a la función loadGif
|
// Crear un objeto Gif y llamar a la función loadGif
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <string> // Para basic_string, allocator, string, operator==, operator+, char_traits
|
#include <string> // Para basic_string, allocator, string, operator==, operator+, char_traits
|
||||||
|
|
||||||
#include "lang.h" // Para getText
|
#include "lang.h" // Para getText
|
||||||
|
#include "resource_helper.h" // Para ResourceHelper
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
Overrides overrides = Overrides();
|
Overrides overrides = Overrides();
|
||||||
@@ -323,8 +324,17 @@ void printWithDots(const std::string &text1, const std::string &text2, const std
|
|||||||
auto loadDemoDataFromFile(const std::string &file_path) -> DemoData {
|
auto loadDemoDataFromFile(const std::string &file_path) -> DemoData {
|
||||||
DemoData dd;
|
DemoData dd;
|
||||||
|
|
||||||
// Indicador de éxito en la carga
|
SDL_IOStream *file = nullptr;
|
||||||
auto *file = SDL_IOFromFile(file_path.c_str(), "r+b");
|
|
||||||
|
// Intentar cargar desde ResourceHelper primero
|
||||||
|
auto resource_data = ResourceHelper::loadFile(file_path);
|
||||||
|
if (!resource_data.empty()) {
|
||||||
|
file = SDL_IOFromConstMem(resource_data.data(), resource_data.size());
|
||||||
|
} else {
|
||||||
|
// Fallback a filesystem directo
|
||||||
|
file = SDL_IOFromFile(file_path.c_str(), "r+b");
|
||||||
|
}
|
||||||
|
|
||||||
if (file == nullptr) {
|
if (file == nullptr) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", file_path.c_str());
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", file_path.c_str());
|
||||||
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||||
|
|||||||
BIN
tools/pack_resources
Executable file
BIN
tools/pack_resources
Executable file
Binary file not shown.
@@ -2,22 +2,77 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
|
void showHelp() {
|
||||||
|
std::cout << "Coffee Crisis Arcade Edition - Resource Packer" << std::endl;
|
||||||
|
std::cout << "===============================================" << std::endl;
|
||||||
|
std::cout << "Usage: pack_resources [options] [input_dir] [output_file]" << std::endl;
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << "Options:" << std::endl;
|
||||||
|
std::cout << " --help Show this help message" << std::endl;
|
||||||
|
std::cout << " --list List contents of an existing pack file" << std::endl;
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << "Arguments:" << std::endl;
|
||||||
|
std::cout << " input_dir Directory to pack (default: data)" << std::endl;
|
||||||
|
std::cout << " output_file Pack file name (default: resources.pack)" << std::endl;
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << "Examples:" << std::endl;
|
||||||
|
std::cout << " pack_resources # Pack 'data' to 'resources.pack'" << std::endl;
|
||||||
|
std::cout << " pack_resources mydata # Pack 'mydata' to 'resources.pack'" << std::endl;
|
||||||
|
std::cout << " pack_resources data my.pack # Pack 'data' to 'my.pack'" << std::endl;
|
||||||
|
std::cout << " pack_resources --list my.pack # List contents of 'my.pack'" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void listPackContents(const std::string& packFile) {
|
||||||
|
ResourcePack pack;
|
||||||
|
if (!pack.loadPack(packFile)) {
|
||||||
|
std::cerr << "Error: Cannot open pack file: " << packFile << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto resources = pack.getResourceList();
|
||||||
|
std::cout << "Pack file: " << packFile << std::endl;
|
||||||
|
std::cout << "Resources: " << resources.size() << std::endl;
|
||||||
|
std::cout << "Contents:" << std::endl;
|
||||||
|
|
||||||
|
for (const auto& resource : resources) {
|
||||||
|
std::cout << " " << resource << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
std::string dataDir = "data";
|
std::string dataDir = "data";
|
||||||
std::string outputFile = "resources.pack";
|
std::string outputFile = "resources.pack";
|
||||||
|
bool listMode = false;
|
||||||
|
|
||||||
if (argc > 1) {
|
// Parse arguments
|
||||||
dataDir = argv[1];
|
for (int i = 1; i < argc; i++) {
|
||||||
|
std::string arg = argv[i];
|
||||||
|
if (arg == "--help" || arg == "-h") {
|
||||||
|
showHelp();
|
||||||
|
return 0;
|
||||||
|
} else if (arg == "--list") {
|
||||||
|
listMode = true;
|
||||||
|
if (i + 1 < argc) {
|
||||||
|
outputFile = argv[++i]; // Next argument is pack file to list
|
||||||
|
}
|
||||||
|
} else if (!arg.empty() && arg[0] != '-') {
|
||||||
|
if (dataDir == "data") {
|
||||||
|
dataDir = arg;
|
||||||
|
} else {
|
||||||
|
outputFile = arg;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (argc > 2) {
|
|
||||||
outputFile = argv[2];
|
if (listMode) {
|
||||||
|
listPackContents(outputFile);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Coffee Crisis Arcade Edition - Resource Packer" << std::endl;
|
std::cout << "Coffee Crisis Arcade Edition - Resource Packer" << std::endl;
|
||||||
std::cout << "===============================================" << std::endl;
|
std::cout << "===============================================" << std::endl;
|
||||||
std::cout << "Input directory: " << dataDir << std::endl;
|
std::cout << "Input directory: " << dataDir << std::endl;
|
||||||
std::cout << "Output file: " << outputFile << std::endl;
|
std::cout << "Output file: " << outputFile << std::endl;
|
||||||
std::cout << "Note: config/ directory is excluded from packing" << std::endl;
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
if (!std::filesystem::exists(dataDir)) {
|
if (!std::filesystem::exists(dataDir)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user