eliminar entrades legacy del fitxer de mapa

This commit is contained in:
2026-04-10 18:51:14 +02:00
parent 8ebf7894f2
commit 6743562292
20 changed files with 133 additions and 318 deletions

View File

@@ -11,7 +11,6 @@
#include <iostream> // Para cout
#include <set> // Para set
#include "external/fkyaml_node.hpp" // Para fkyaml::node (loadSettings)
#include "core/input/mouse.hpp" // Para Mouse
#include "core/rendering/render_info.hpp" // Para RenderInfo
#include "core/rendering/screen.hpp" // Para Screen
@@ -19,8 +18,8 @@
#include "core/resources/resource_cache.hpp" // Para Resource::Cache
#include "core/resources/resource_list.hpp" // Para Resource::List
#include "core/resources/resource_types.hpp" // Para RoomResource
#include "external/fkyaml_node.hpp" // Para fkyaml::node (loadSettings)
#include "game/editor/editor_statusbar.hpp" // Para EditorStatusBar
#include "game/gameplay/room_format.hpp" // Para RoomFormat
#include "game/entities/player.hpp" // Para Player
#include "game/game_control.hpp" // Para GameControl
#include "game/gameplay/door_manager.hpp" // Para DoorManager
@@ -29,6 +28,7 @@
#include "game/gameplay/key_manager.hpp" // Para KeyManager
#include "game/gameplay/platform_manager.hpp" // Para PlatformManager
#include "game/gameplay/room.hpp" // Para Room
#include "game/gameplay/room_format.hpp" // Para RoomFormat
#include "game/gameplay/zone.hpp" // Para Zone::Data
#include "game/gameplay/zone_manager.hpp" // Para ZoneManager
#include "game/options.hpp" // Para Options
@@ -294,10 +294,7 @@ auto MapEditor::revert() -> std::string {
auto* item_mgr = room_->getItemManager();
item_mgr->clear();
for (const auto& i : room_data_.items) {
Item::Data item_copy = i;
item_copy.color1 = room_data_.item_color1;
item_copy.color2 = room_data_.item_color2;
item_mgr->addItem(std::make_shared<Item>(item_copy));
item_mgr->addItem(std::make_shared<Item>(i));
}
auto* platform_mgr = room_->getPlatformManager();
@@ -306,8 +303,6 @@ auto MapEditor::revert() -> std::string {
platform_mgr->addPlatform(std::make_shared<MovingPlatform>(p));
}
room_->setItemColors(room_data_.item_color1, room_data_.item_color2);
// Restaurar el tilemap completo
for (int i = 0; i < static_cast<int>(room_data_.tile_map.size()); ++i) {
room_->setTile(i, room_data_.tile_map[i]);
@@ -1266,7 +1261,9 @@ void MapEditor::updateStatusBarInfo() { // NOLINT(readability-function-cognitiv
const auto& it = room_data_.items[selection_.index];
line2 = "item " + std::to_string(selection_.index) + ": tile=" + std::to_string(it.tile) +
" counter=" + std::to_string(it.counter);
line3 = "tileset: " + it.tile_set_file;
std::string c1_marker = it.color1_overridden ? "*" : "";
std::string c2_marker = it.color2_overridden ? "*" : "";
line3 = "col:" + std::to_string(it.color1) + c1_marker + "/" + std::to_string(it.color2) + c2_marker;
}
break;
@@ -1305,19 +1302,11 @@ void MapEditor::updateStatusBarInfo() { // NOLINT(readability-function-cognitiv
case EntityType::NONE: {
// Propiedades de la habitación
std::string conv = "none";
if (room_data_.conveyor_belt_direction < 0) {
conv = "left";
} else if (room_data_.conveyor_belt_direction > 0) {
conv = "right";
}
std::string ts_marker = room_data_.tile_set_overridden ? " (ts*)" : "";
std::string mu_marker = room_data_.music_overridden ? " (mu*)" : "";
line2 = "zone:" + room_data_.zone + ts_marker + mu_marker + " conv:" + conv;
line2 = "zone:" + room_data_.zone + ts_marker + mu_marker;
line3 = "u:" + conn(room_data_.upper_room) + " d:" + conn(room_data_.lower_room) +
" l:" + conn(room_data_.left_room) + " r:" + conn(room_data_.right_room) +
" itm:" + std::to_string(room_data_.item_color1) + "/" + std::to_string(room_data_.item_color2);
" l:" + conn(room_data_.left_room) + " r:" + conn(room_data_.right_room);
break;
}
}
@@ -1349,7 +1338,7 @@ auto MapEditor::getSetCompletions() const -> std::vector<std::string> {
case EntityType::ENEMY:
return {"ANIMATION", "VX", "VY", "FLIP", "MIRROR"};
case EntityType::ITEM:
return {"TILE", "COUNTER"};
return {"TILE", "COUNTER", "COLOR1", "COLOR2"};
case EntityType::PLATFORM:
return {"ANIMATION", "SPEED", "LOOP", "EASING"};
case EntityType::KEY:
@@ -1357,7 +1346,7 @@ auto MapEditor::getSetCompletions() const -> std::vector<std::string> {
case EntityType::DOOR:
return {"ID", "ANIMATION"};
default:
return {"ZONE", "ITEMCOLOR1", "ITEMCOLOR2", "CONVEYOR", "TILESET", "MUSIC", "UP", "DOWN", "LEFT", "RIGHT"};
return {"ZONE", "TILESET", "MUSIC", "UP", "DOWN", "LEFT", "RIGHT"};
}
}
@@ -1534,36 +1523,6 @@ auto MapEditor::setRoomProperty(const std::string& property, const std::string&
std::string val = toLower(value);
if (property == "ITEMCOLOR1") {
auto color = static_cast<Uint8>(safeStoi(val, 0));
room_data_.item_color1 = color;
room_->setItemColors(room_data_.item_color1, room_data_.item_color2);
autosave();
return "itemcolor1: " + std::to_string(color);
}
if (property == "ITEMCOLOR2") {
auto color = static_cast<Uint8>(safeStoi(val, 0));
room_data_.item_color2 = color;
room_->setItemColors(room_data_.item_color1, room_data_.item_color2);
autosave();
return "itemcolor2: " + std::to_string(color);
}
if (property == "CONVEYOR") {
if (val == "left") {
room_data_.conveyor_belt_direction = -1;
} else if (val == "right") {
room_data_.conveyor_belt_direction = 1;
} else {
room_data_.conveyor_belt_direction = 0;
val = "none";
}
room_->setConveyorBeltDirection(room_data_.conveyor_belt_direction);
autosave();
return "conveyor: " + val;
}
if (property == "ZONE") {
const Zone::Data* zone = ZoneManager::get()->getZone(val);
if (zone == nullptr) { return "Unknown zone: " + val; }
@@ -1830,10 +1789,15 @@ auto MapEditor::createNewRoom(const std::string& direction) -> std::string { //
// Sincronizar con Resource::Cache::rooms_ (datos crudos)
auto cached = Resource::Cache::get()->getRoom(room_path_);
if (cached) {
if (direction == "UP") { cached->upper_room = new_name; }
else if (direction == "DOWN") { cached->lower_room = new_name; }
else if (direction == "LEFT") { cached->left_room = new_name; }
else if (direction == "RIGHT") { cached->right_room = new_name; }
if (direction == "UP") {
cached->upper_room = new_name;
} else if (direction == "DOWN") {
cached->lower_room = new_name;
} else if (direction == "LEFT") {
cached->left_room = new_name;
} else if (direction == "RIGHT") {
cached->right_room = new_name;
}
}
}
@@ -1949,7 +1913,45 @@ auto MapEditor::setItemProperty(const std::string& property, const std::string&
return "counter: " + std::to_string(item.counter);
}
return "Unknown property: " + property + " (use: tile, counter)";
if (property == "COLOR1") {
// "reset" / "none" limpia el override y vuelve al default
const std::string LOWER = toLower(value);
if (LOWER == "reset" || LOWER == "none") {
item.color1 = Item::DEFAULT_COLOR1;
item.color1_overridden = false;
// Recrear el sprite vivo con los colores nuevos
room_->getItemManager()->getItem(selection_.index) = std::make_shared<Item>(item);
autosave();
return "color1: (default)";
}
try {
item.color1 = static_cast<Uint8>(std::stoi(value));
} catch (...) { return "Invalid value: " + value; }
item.color1_overridden = true;
room_->getItemManager()->getItem(selection_.index) = std::make_shared<Item>(item);
autosave();
return "color1: " + std::to_string(item.color1);
}
if (property == "COLOR2") {
const std::string LOWER = toLower(value);
if (LOWER == "reset" || LOWER == "none") {
item.color2 = Item::DEFAULT_COLOR2;
item.color2_overridden = false;
room_->getItemManager()->getItem(selection_.index) = std::make_shared<Item>(item);
autosave();
return "color2: (default)";
}
try {
item.color2 = static_cast<Uint8>(std::stoi(value));
} catch (...) { return "Invalid value: " + value; }
item.color2_overridden = true;
room_->getItemManager()->getItem(selection_.index) = std::make_shared<Item>(item);
autosave();
return "color2: " + std::to_string(item.color2);
}
return "Unknown property: " + property + " (use: tile, counter, color1, color2)";
}
// Abre el tile picker para seleccionar un tile
@@ -1965,8 +1967,11 @@ void MapEditor::openTilePicker(const std::string& tileset_name, int current_tile
room_->getItemManager()->getItem(selection_.index)->setTile(tile);
autosave();
};
// Pasar color de fondo de la habitación + color de sustitución del item
tile_picker_.open(tileset_name, current_tile, room_data_.bg_color, 1, room_data_.item_color1);
// Pasar color de fondo de la habitación + color del item seleccionado para previsualizarlo
Uint8 preview_color = hasSelectedItem()
? room_data_.items[selection_.index].color1
: Item::DEFAULT_COLOR1;
tile_picker_.open(tileset_name, current_tile, room_data_.bg_color, 1, preview_color);
}
// Crea un nuevo item con valores por defecto, centrado en la habitación
@@ -1979,8 +1984,7 @@ auto MapEditor::addItem() -> std::string {
new_item.x = PlayArea::CENTER_X;
new_item.y = PlayArea::CENTER_Y;
new_item.counter = 0;
new_item.color1 = room_data_.item_color1;
new_item.color2 = room_data_.item_color2;
// Los colores quedan en sus defaults (Item::DEFAULT_COLOR1/2)
room_data_.items.push_back(new_item);
room_->getItemManager()->addItem(std::make_shared<Item>(new_item));