diff --git a/data/maps/p1/r1.yaml b/data/maps/p1/r1.yaml index eac3d3a..77d35c9 100644 --- a/data/maps/p1/r1.yaml +++ b/data/maps/p1/r1.yaml @@ -90,7 +90,6 @@ entities: position: [12, 2] - type: torch position: [16, 2] - - type: sarcophagus sarc_position: [0, 0] - type: sarcophagus @@ -131,17 +130,11 @@ entities: sarc_position: [2, 4] - type: sarcophagus sarc_position: [3, 4] - - type: door - - - type: mummy position: [10, 7] - type: mummy position: [7, 9] - - - type: hole - position: [11, 5] - type: hole position: [4, 7] - type: hole @@ -150,3 +143,5 @@ entities: position: [15, 11] - type: hole position: [15, 5] + - type: hole + position: [6, 5] diff --git a/source/game/editor/editor.cpp b/source/game/editor/editor.cpp index 5ced037..6acd873 100644 --- a/source/game/editor/editor.cpp +++ b/source/game/editor/editor.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include "core/input/key_config.hpp" @@ -223,16 +224,31 @@ void Editor::ensureEditableEntities() { const auto& sp = tmpl["sprite"]; if (!sp.contains("path") || !sp.contains("size")) { continue; } - const auto SPRITE_PATH = "data/entities/" + name + "/" + sp["path"].get_value(); + // Mateixa convenció de claus que `entity_manager_loadlevel.cpp`: + // la key del cache és el basename del fitxer (p.ex. "door.gif"), + // i el full_path només s'usa per a `loadSurface`. `getSurface` + // llança si no troba — provem primer i, en cas de miss, carreguem. + const auto REL = sp["path"].get_value(); + const std::string KEY = std::filesystem::path(REL).filename().string(); + std::string full = "data/entities/"; + full += name; + full += '/'; + full += REL; const auto SIZE = sp["size"]; if (!SIZE.is_sequence() || SIZE.size() < 2) { continue; } const int FRAME_W = SIZE[0].get_value(); const int FRAME_H = SIZE[1].get_value(); - auto surface = cache.getSurface(SPRITE_PATH); - if (surface == nullptr) { - cache.loadSurface(SPRITE_PATH, SPRITE_PATH); - surface = cache.getSurface(SPRITE_PATH); + std::shared_ptr surface; + try { + surface = cache.getSurface(KEY); + } catch (const std::exception&) { + try { + cache.loadSurface(KEY, full); + surface = cache.getSurface(KEY); + } catch (const std::exception&) { + continue; + } } if (surface == nullptr) { continue; } @@ -269,8 +285,15 @@ namespace { s.sarc_row = (static_cast(LOGICAL.y) - Map::origin_y) / Map::pitch_y; } } else if (s.type != "door") { + // Invertir des del rect de col·lisió, no del pixel_rect: + // amb anchor=feet (típic d'actors com la mòmia) el + // pixel_rect està desplaçat verticalment respecte a la + // cel·la-pivot, perquè el sprite sobresurt cap amunt amb + // falsa perspectiva. La caixa de col·lisió, en canvi, ja + // està alineada amb la cel·la del tilemap, i això és el + // que el `position: [col, row]` del YAML representa. if (Map::tile_size > 0) { - const auto R = e->getPixelRect(); + const auto R = e->getCollisionRect(); s.col = (static_cast(R.x) - Map::tilemap_origin_x) / Map::tile_size; s.row = (static_cast(R.y) - Map::tilemap_origin_y) / Map::tile_size; }