afegit resources.pack y prefixe a les rutes de recursos

This commit is contained in:
2025-12-08 21:48:52 +01:00
parent 4b7cbd88bb
commit a41e696b69
21 changed files with 1066 additions and 36 deletions
+24 -10
View File
@@ -3,6 +3,8 @@
#include "core/graphics/shape_loader.hpp"
#include "core/resources/resource_helper.hpp"
#include <iostream>
namespace Graphics {
@@ -19,28 +21,40 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
return it->second; // Cache hit
}
// Resolve full path
std::string fullpath = resolve_path(filename);
// Normalize path: "ship.shp" → "shapes/ship.shp"
// "logo/letra_j.shp" → "shapes/logo/letra_j.shp"
std::string normalized = filename;
if (normalized.find("shapes/") != 0) {
// Doesn't start with "shapes/", so add it
normalized = "shapes/" + normalized;
}
// Create and load shape
// Load from resource system
std::vector<uint8_t> data = Resource::Helper::loadFile(normalized);
if (data.empty()) {
std::cerr << "[ShapeLoader] Error: no s'ha pogut carregar " << normalized
<< std::endl;
return nullptr;
}
// Convert bytes to string and parse
std::string file_content(data.begin(), data.end());
auto shape = std::make_shared<Shape>();
if (!shape->carregar(fullpath)) {
std::cerr << "[ShapeLoader] Error: no s'ha pogut carregar " << filename
if (!shape->parsejar_fitxer(file_content)) {
std::cerr << "[ShapeLoader] Error: no s'ha pogut parsejar " << normalized
<< std::endl;
return nullptr;
}
// Verify shape is valid
if (!shape->es_valida()) {
std::cerr << "[ShapeLoader] Error: forma invàlida " << filename
<< std::endl;
std::cerr << "[ShapeLoader] Error: forma invàlida " << normalized << std::endl;
return nullptr;
}
// Cache and return
std::cout << "[ShapeLoader] Carregat: " << filename << " ("
<< shape->get_nom() << ", " << shape->get_num_primitives()
<< " primitives)" << std::endl;
std::cout << "[ShapeLoader] Carregat: " << normalized << " (" << shape->get_nom()
<< ", " << shape->get_num_primitives() << " primitives)" << std::endl;
cache_[filename] = shape;
return shape;