corregida la llista de inicialització en clang-format

creat Balloon::Config per a inicialitzar globos
This commit is contained in:
2025-08-24 17:16:49 +02:00
parent fe950e6f17
commit 928335576c
61 changed files with 964 additions and 733 deletions

View File

@@ -1,13 +1,15 @@
#include "resource_loader.h"
#include <algorithm>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <filesystem>
#include <algorithm>
std::unique_ptr<ResourceLoader> ResourceLoader::instance = nullptr;
ResourceLoader::ResourceLoader()
: resourcePack(nullptr), fallbackToFiles(true) {}
ResourceLoader::ResourceLoader()
: resourcePack(nullptr),
fallbackToFiles(true) {}
ResourceLoader& ResourceLoader::getInstance() {
if (!instance) {
@@ -22,10 +24,10 @@ ResourceLoader::~ResourceLoader() {
bool ResourceLoader::initialize(const std::string& packFile, bool enableFallback) {
shutdown();
fallbackToFiles = enableFallback;
packPath = packFile;
if (std::filesystem::exists(packFile)) {
resourcePack = new ResourcePack();
if (resourcePack->loadPack(packFile)) {
@@ -38,12 +40,12 @@ bool ResourceLoader::initialize(const std::string& packFile, bool enableFallback
std::cerr << "Failed to load resource pack: " << packFile << std::endl;
}
}
if (fallbackToFiles) {
std::cout << "Using fallback mode: loading resources from data/ directory" << std::endl;
return true;
}
std::cerr << "Resource pack not found and fallback disabled: " << packFile << std::endl;
return false;
}
@@ -59,11 +61,11 @@ std::vector<uint8_t> ResourceLoader::loadResource(const std::string& filename) {
if (resourcePack && resourcePack->hasResource(filename)) {
return resourcePack->getResource(filename);
}
if (fallbackToFiles) {
return loadFromFile(filename);
}
std::cerr << "Resource not found: " << filename << std::endl;
return {};
}
@@ -72,33 +74,33 @@ bool ResourceLoader::resourceExists(const std::string& filename) {
if (resourcePack && resourcePack->hasResource(filename)) {
return true;
}
if (fallbackToFiles) {
std::string fullPath = getDataPath(filename);
return std::filesystem::exists(fullPath);
}
return false;
}
std::vector<uint8_t> ResourceLoader::loadFromFile(const std::string& filename) {
std::string fullPath = getDataPath(filename);
std::ifstream file(fullPath, std::ios::binary | std::ios::ate);
if (!file) {
std::cerr << "Error: Could not open file: " << fullPath << std::endl;
return {};
}
std::streamsize fileSize = file.tellg();
file.seekg(0, std::ios::beg);
std::vector<uint8_t> data(fileSize);
if (!file.read(reinterpret_cast<char*>(data.data()), fileSize)) {
std::cerr << "Error: Could not read file: " << fullPath << std::endl;
return {};
}
return data;
}
@@ -117,7 +119,7 @@ std::vector<std::string> ResourceLoader::getAvailableResources() const {
if (resourcePack) {
return resourcePack->getResourceList();
}
std::vector<std::string> result;
if (fallbackToFiles && std::filesystem::exists("data")) {
for (const auto& entry : std::filesystem::recursive_directory_iterator("data")) {
@@ -128,6 +130,6 @@ std::vector<std::string> ResourceLoader::getAvailableResources() const {
}
}
}
return result;
}