fix(editor): inverteix posició des del collision_rect i restaura mòmies r1
This commit is contained in:
1 parent
d13313503c
commit
c0362abf67
2 files changed
+31
-13
No files matched your search
@@ -90,7 +90,6 @@ entities:
|
|||||||
position: [12, 2]
|
position: [12, 2]
|
||||||
- type: torch
|
- type: torch
|
||||||
position: [16, 2]
|
position: [16, 2]
|
||||||
|
|
||||||
- type: sarcophagus
|
- type: sarcophagus
|
||||||
sarc_position: [0, 0]
|
sarc_position: [0, 0]
|
||||||
- type: sarcophagus
|
- type: sarcophagus
|
||||||
@@ -131,17 +130,11 @@ entities:
|
|||||||
sarc_position: [2, 4]
|
sarc_position: [2, 4]
|
||||||
- type: sarcophagus
|
- type: sarcophagus
|
||||||
sarc_position: [3, 4]
|
sarc_position: [3, 4]
|
||||||
|
|
||||||
- type: door
|
- type: door
|
||||||
|
|
||||||
|
|
||||||
- type: mummy
|
- type: mummy
|
||||||
position: [10, 7]
|
position: [10, 7]
|
||||||
- type: mummy
|
- type: mummy
|
||||||
position: [7, 9]
|
position: [7, 9]
|
||||||
|
|
||||||
- type: hole
|
|
||||||
position: [11, 5]
|
|
||||||
- type: hole
|
- type: hole
|
||||||
position: [4, 7]
|
position: [4, 7]
|
||||||
- type: hole
|
- type: hole
|
||||||
@@ -150,3 +143,5 @@ entities:
|
|||||||
position: [15, 11]
|
position: [15, 11]
|
||||||
- type: hole
|
- type: hole
|
||||||
position: [15, 5]
|
position: [15, 5]
|
||||||
|
- type: hole
|
||||||
|
position: [6, 5]
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <filesystem>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "core/input/key_config.hpp"
|
#include "core/input/key_config.hpp"
|
||||||
@@ -223,16 +224,31 @@ void Editor::ensureEditableEntities() {
|
|||||||
const auto& sp = tmpl["sprite"];
|
const auto& sp = tmpl["sprite"];
|
||||||
if (!sp.contains("path") || !sp.contains("size")) { continue; }
|
if (!sp.contains("path") || !sp.contains("size")) { continue; }
|
||||||
|
|
||||||
const auto SPRITE_PATH = "data/entities/" + name + "/" + sp["path"].get_value<std::string>();
|
// 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<std::string>();
|
||||||
|
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"];
|
const auto SIZE = sp["size"];
|
||||||
if (!SIZE.is_sequence() || SIZE.size() < 2) { continue; }
|
if (!SIZE.is_sequence() || SIZE.size() < 2) { continue; }
|
||||||
const int FRAME_W = SIZE[0].get_value<int>();
|
const int FRAME_W = SIZE[0].get_value<int>();
|
||||||
const int FRAME_H = SIZE[1].get_value<int>();
|
const int FRAME_H = SIZE[1].get_value<int>();
|
||||||
|
|
||||||
auto surface = cache.getSurface(SPRITE_PATH);
|
std::shared_ptr<Surface> surface;
|
||||||
if (surface == nullptr) {
|
try {
|
||||||
cache.loadSurface(SPRITE_PATH, SPRITE_PATH);
|
surface = cache.getSurface(KEY);
|
||||||
surface = cache.getSurface(SPRITE_PATH);
|
} catch (const std::exception&) {
|
||||||
|
try {
|
||||||
|
cache.loadSurface(KEY, full);
|
||||||
|
surface = cache.getSurface(KEY);
|
||||||
|
} catch (const std::exception&) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (surface == nullptr) { continue; }
|
if (surface == nullptr) { continue; }
|
||||||
|
|
||||||
@@ -269,8 +285,15 @@ namespace {
|
|||||||
s.sarc_row = (static_cast<int>(LOGICAL.y) - Map::origin_y) / Map::pitch_y;
|
s.sarc_row = (static_cast<int>(LOGICAL.y) - Map::origin_y) / Map::pitch_y;
|
||||||
}
|
}
|
||||||
} else if (s.type != "door") {
|
} 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) {
|
if (Map::tile_size > 0) {
|
||||||
const auto R = e->getPixelRect();
|
const auto R = e->getCollisionRect();
|
||||||
s.col = (static_cast<int>(R.x) - Map::tilemap_origin_x) / Map::tile_size;
|
s.col = (static_cast<int>(R.x) - Map::tilemap_origin_x) / Map::tile_size;
|
||||||
s.row = (static_cast<int>(R.y) - Map::tilemap_origin_y) / Map::tile_size;
|
s.row = (static_cast<int>(R.y) - Map::tilemap_origin_y) / Map::tile_size;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user