editar les propietats de la habitacio
This commit is contained in:
@@ -121,15 +121,21 @@ auto MapEditor::revert() -> std::string {
|
||||
}
|
||||
RoomSaver::saveYAML(file_path_, yaml_, room_data_);
|
||||
|
||||
// Resetear los sprites vivos a las posiciones originales
|
||||
// Resetear enemigos a posiciones originales
|
||||
room_->resetEnemyPositions(room_data_.enemies);
|
||||
|
||||
// Resetear items (recargar posiciones)
|
||||
// Resetear items (posiciones y colores)
|
||||
auto* item_mgr = room_->getItemManager();
|
||||
for (int i = 0; i < item_mgr->getCount() && i < static_cast<int>(room_data_.items.size()); ++i) {
|
||||
item_mgr->getItem(i)->setPosition(room_data_.items[i].x, room_data_.items[i].y);
|
||||
}
|
||||
room_->setItemColors(room_data_.item_color1, room_data_.item_color2);
|
||||
|
||||
// Refrescar visuales de la habitación
|
||||
room_->setBgColor(room_data_.bg_color);
|
||||
Screen::get()->setBorderColor(stringToColor(room_data_.border_color));
|
||||
|
||||
selected_enemy_ = -1;
|
||||
return "Reverted to original";
|
||||
}
|
||||
|
||||
@@ -568,6 +574,18 @@ void MapEditor::updateStatusBarInfo() {
|
||||
if (e.flip) { sel_detail += " flip"; }
|
||||
if (e.mirror) { sel_detail += " mirror"; }
|
||||
}
|
||||
// Info de la habitación (cuando no hay nada seleccionado)
|
||||
else {
|
||||
// Conexiones compactas
|
||||
auto conn = [](const std::string& r) -> std::string {
|
||||
if (r == "0" || r.empty()) { return "-"; }
|
||||
return r.substr(0, r.find('.'));
|
||||
};
|
||||
sel_info = "bg:" + room_data_.bg_color + " brd:" + room_data_.border_color;
|
||||
sel_detail = "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:" + room_data_.item_color1 + "/" + room_data_.item_color2;
|
||||
}
|
||||
|
||||
statusbar_->setSelectionInfo(sel_info);
|
||||
statusbar_->setSelectionDetail(sel_detail);
|
||||
@@ -576,7 +594,7 @@ void MapEditor::updateStatusBarInfo() {
|
||||
if (selected_enemy_ >= 0) {
|
||||
Console::get()->setPrompt("enemy " + std::to_string(selected_enemy_) + "> ");
|
||||
} else {
|
||||
Console::get()->setPrompt("> ");
|
||||
Console::get()->setPrompt("room> ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -765,4 +783,83 @@ auto MapEditor::duplicateEnemy() -> std::string {
|
||||
return "Duplicated as enemy " + std::to_string(selected_enemy_);
|
||||
}
|
||||
|
||||
// Modifica una propiedad de la habitación
|
||||
auto MapEditor::setRoomProperty(const std::string& property, const std::string& value) -> std::string {
|
||||
if (!active_) { return "Editor not active"; }
|
||||
|
||||
std::string val = toLower(value);
|
||||
|
||||
if (property == "BGCOLOR") {
|
||||
room_data_.bg_color = val;
|
||||
room_->setBgColor(val);
|
||||
autosave();
|
||||
return "bgcolor: " + val;
|
||||
}
|
||||
|
||||
if (property == "BORDER") {
|
||||
room_data_.border_color = val;
|
||||
Screen::get()->setBorderColor(stringToColor(val));
|
||||
autosave();
|
||||
return "border: " + val;
|
||||
}
|
||||
|
||||
if (property == "ITEMCOLOR1") {
|
||||
room_data_.item_color1 = val;
|
||||
room_->setItemColors(room_data_.item_color1, room_data_.item_color2);
|
||||
autosave();
|
||||
return "itemcolor1: " + val;
|
||||
}
|
||||
|
||||
if (property == "ITEMCOLOR2") {
|
||||
room_data_.item_color2 = val;
|
||||
room_->setItemColors(room_data_.item_color1, room_data_.item_color2);
|
||||
autosave();
|
||||
return "itemcolor2: " + val;
|
||||
}
|
||||
|
||||
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"; }
|
||||
autosave();
|
||||
return "conveyor: " + val;
|
||||
}
|
||||
|
||||
if (property == "TILESET") {
|
||||
std::string tileset = val;
|
||||
if (tileset.find('.') == std::string::npos) { tileset += ".gif"; }
|
||||
room_data_.tile_set_file = tileset;
|
||||
autosave();
|
||||
return "tileset: " + tileset;
|
||||
}
|
||||
|
||||
// Conexiones: UP, DOWN, LEFT, RIGHT
|
||||
if (property == "UP" || property == "DOWN" || property == "LEFT" || property == "RIGHT") {
|
||||
std::string connection = "0";
|
||||
if (val != "0" && val != "null" && val != "none") {
|
||||
// Convertir número a fichero: "6" → "06.yaml"
|
||||
try {
|
||||
int num = std::stoi(val);
|
||||
char buf[16];
|
||||
std::snprintf(buf, sizeof(buf), "%02d.yaml", num);
|
||||
connection = buf;
|
||||
} catch (...) {
|
||||
// Si no es número, asumir que es un nombre de fichero
|
||||
connection = val;
|
||||
if (connection.find('.') == std::string::npos) { connection += ".yaml"; }
|
||||
}
|
||||
}
|
||||
|
||||
if (property == "UP") { room_data_.upper_room = connection; }
|
||||
else if (property == "DOWN") { room_data_.lower_room = connection; }
|
||||
else if (property == "LEFT") { room_data_.left_room = connection; }
|
||||
else { room_data_.right_room = connection; }
|
||||
|
||||
autosave();
|
||||
return toLower(property) + ": " + connection;
|
||||
}
|
||||
|
||||
return "Unknown property: " + property + " (use: bgcolor, border, itemcolor1, itemcolor2, conveyor, tileset, up, down, left, right)";
|
||||
}
|
||||
|
||||
#endif // _DEBUG
|
||||
|
||||
Reference in New Issue
Block a user