feat(players): suport del segon jugador amb events amb player_id

This commit is contained in:
JailDesigner committed 2026-04-24 14:33:52 +02:00
1 parent 74dad71cc2
commit 4e9d5df872
21 files changed
+309 -49

No files matched your search

+10 -3
View File
@@ -60,8 +60,11 @@ PaintLayer::PaintLayer(const Tilemap& tilemap, EventBus* bus)
// (sòl transitable) via `Map::isPaintable` i, si aplica, marquem
// i re-publiquem `tile_painted` amb només la posició.
on_tile_sub_ = bus_->subscribe("on_tile_entered", [this](const Event& ev) {
// Re-propaguem el `player_id` de qui ha trepitjat la cel·la, perquè
// `tile_painted` (que consumeixen els sarcòfags i el HUD futur)
// sàpiga quin jugador ha pintat.
const auto* paint = std::get_if<PaintedTile>(&ev.payload);
if (paint != nullptr) { tryPaint(paint->col, paint->row, paint->tile_index); }
if (paint != nullptr) { tryPaint(paint->col, paint->row, paint->tile_index, ev.player_id); }
});
}
@@ -79,7 +82,7 @@ auto PaintLayer::isPainted(int col, int row) const -> bool {
return painted_[static_cast<std::size_t>(row)][static_cast<std::size_t>(col)] >= 0;
}
auto PaintLayer::tryPaint(int col, int row, int tile_index) -> bool {
auto PaintLayer::tryPaint(int col, int row, int tile_index, int player_id) -> bool {
if (col < 0 || col >= cols_ || row < 0 || row >= rows_) { return false; }
if (tile_index < 0) { return false; }
if (painted_[static_cast<std::size_t>(row)][static_cast<std::size_t>(col)] >= 0) {
@@ -92,7 +95,11 @@ auto PaintLayer::tryPaint(int col, int row, int tile_index) -> bool {
blitPaintTile(col, row, tile_index);
if (bus_ != nullptr) {
bus_->publish("tile_painted", TilePos{.col = col, .row = row});
bus_->publish(Event{
.name = "tile_painted",
.payload = TilePos{.col = col, .row = row},
.player_id = player_id,
});
}
return true;
}
+1 -1
View File
@@ -44,7 +44,7 @@ class PaintLayer {
// Intent de pintat directe (exposat per a tests i actors que pinten
// sense passar pel bus). Retorna true si el tile és pintable i no
// estava ja pintat; en aquest cas, publica `tile_painted`.
auto tryPaint(int col, int row, int tile_index) -> bool;
auto tryPaint(int col, int row, int tile_index, int player_id = -1) -> bool;
[[nodiscard]] auto isPainted(int col, int row) const -> bool;