afegit resources.pack y prefixe a les rutes de recursos
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user