feat(entities): integració del sistema d'entitats al GameScene
This commit is contained in:
1 parent
96b71b0f65
commit
7191a08618
16 files changed
+683
-15
No files matched your search
@@ -38,6 +38,7 @@
|
||||
#include "game/entities/entity_loader.hpp"
|
||||
#include "game/entities/entity_manager.hpp"
|
||||
#include "game/entities/event_bus.hpp"
|
||||
#include "game/map/map.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -259,6 +260,62 @@ namespace {
|
||||
REQUIRE(!torch.interactable());
|
||||
}
|
||||
|
||||
void testLoadFromLevel() {
|
||||
std::cout << "[T9] pyramid level load (globals + spawns + tile math + bus)\n";
|
||||
// 1) Map::loadFrom carrega les tres globals noves (tile_size, origen).
|
||||
Map::loadFrom("data/maps/pyramid.yaml");
|
||||
REQUIRE(Map::tile_size == 16);
|
||||
REQUIRE(Map::tilemap_origin_x == -8);
|
||||
REQUIRE(Map::tilemap_origin_y == 0);
|
||||
|
||||
// 2) El pyramid.yaml conté 5 spawns amb els tipus esperats.
|
||||
const auto SPAWNS = EntityLoader::readSpawns("data/maps/pyramid.yaml");
|
||||
REQUIRE(SPAWNS.size() == 5);
|
||||
int torches = 0;
|
||||
int sarcs = 0;
|
||||
int doors = 0;
|
||||
int mummies = 0;
|
||||
for (const auto& s : SPAWNS) {
|
||||
const auto T = s["type"].get_value<std::string>();
|
||||
if (T == "torch") { ++torches; }
|
||||
else if (T == "sarcophagus") { ++sarcs; }
|
||||
else if (T == "door") { ++doors; }
|
||||
else if (T == "mummy") { ++mummies; }
|
||||
}
|
||||
REQUIRE(torches == 1);
|
||||
REQUIRE(sarcs == 2);
|
||||
REQUIRE(doors == 1);
|
||||
REQUIRE(mummies == 1);
|
||||
|
||||
// 3) La conversió sarc-grid (0,0) → tile anchor (3,4) (i.e. la
|
||||
// fórmula que usa loadFromLevel). Sarc rect = (40, 64, 48, 16).
|
||||
const auto RECT = Map::getSarcRect(0, 0);
|
||||
REQUIRE(static_cast<int>(RECT.x) == 40);
|
||||
REQUIRE(static_cast<int>(RECT.y) == 64);
|
||||
const int ANCHOR_COL = (static_cast<int>(RECT.x) - Map::tilemap_origin_x) / Map::tile_size;
|
||||
const int ANCHOR_ROW = (static_cast<int>(RECT.y) - Map::tilemap_origin_y) / Map::tile_size;
|
||||
REQUIRE(ANCHOR_COL == 3);
|
||||
REQUIRE(ANCHOR_ROW == 4);
|
||||
|
||||
// 4) Fan-out del bus: un sarcòfag ancorat a (3,4) mida 3×1 rep via
|
||||
// on_tile_entered una visita sobre el seu perímetre → state canvia.
|
||||
EntityManager manager;
|
||||
auto sarc = std::make_unique<Sarcophagus>(EntityLoader::loadTemplate("sarcophagus"));
|
||||
sarc->place(3, 4, {});
|
||||
Sarcophagus* sarc_raw = manager.addSarcophagus(std::move(sarc));
|
||||
REQUIRE(sarc_raw->getPerimeterSize() == 8);
|
||||
// Les 8 tiles del perímetre: N (3..5,3), S (3..5,5), O (2,4), E (6,4).
|
||||
const std::pair<int, int> PERIM[] = {
|
||||
{3, 3}, {4, 3}, {5, 3},
|
||||
{3, 5}, {4, 5}, {5, 5},
|
||||
{2, 4}, {6, 4},
|
||||
};
|
||||
for (const auto& [c, r] : PERIM) {
|
||||
manager.getBus().publish("on_tile_entered", TilePos{.col = c, .row = r});
|
||||
}
|
||||
REQUIRE(sarc_raw->getState() == Sarcophagus::State::OPENING);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
auto main() -> int {
|
||||
@@ -272,6 +329,7 @@ auto main() -> int {
|
||||
testAnimationComponent();
|
||||
testAllTemplatesLoad();
|
||||
testDecorationFlags();
|
||||
testLoadFromLevel();
|
||||
|
||||
if (g_failures == 0) {
|
||||
std::cout << "ALL OK\n";
|
||||
|
||||
Reference in new issue
Block a user