continue amb els ambits
This commit is contained in:
@@ -18,9 +18,9 @@
|
||||
#include "core/resources/resource_list.hpp" // Para Resource::List
|
||||
#include "core/resources/resource_types.hpp" // Para RoomResource
|
||||
#include "game/editor/editor_statusbar.hpp" // Para EditorStatusBar
|
||||
#include "game/game_control.hpp" // Para GameControl
|
||||
#include "game/editor/room_saver.hpp" // Para RoomSaver
|
||||
#include "game/entities/player.hpp" // Para Player
|
||||
#include "game/game_control.hpp" // Para GameControl
|
||||
#include "game/gameplay/enemy_manager.hpp" // Para EnemyManager
|
||||
#include "game/gameplay/item_manager.hpp" // Para ItemManager
|
||||
#include "game/gameplay/room.hpp" // Para Room
|
||||
@@ -69,12 +69,18 @@ void MapEditor::loadSettings() {
|
||||
if (yaml.contains("grid")) { settings_.grid = yaml["grid"].get_value<bool>(); }
|
||||
if (yaml.contains("show_render_info")) { settings_.show_render_info = yaml["show_render_info"].get_value<bool>(); }
|
||||
if (yaml.contains("minimap_bg")) {
|
||||
if (yaml["minimap_bg"].is_string()) { settings_.minimap_bg = yaml["minimap_bg"].get_value<std::string>(); }
|
||||
else if (yaml["minimap_bg"].is_integer()) { settings_.minimap_bg = std::to_string(yaml["minimap_bg"].get_value<int>()); }
|
||||
if (yaml["minimap_bg"].is_string()) {
|
||||
settings_.minimap_bg = yaml["minimap_bg"].get_value<std::string>();
|
||||
} else if (yaml["minimap_bg"].is_integer()) {
|
||||
settings_.minimap_bg = std::to_string(yaml["minimap_bg"].get_value<int>());
|
||||
}
|
||||
}
|
||||
if (yaml.contains("minimap_conn")) {
|
||||
if (yaml["minimap_conn"].is_string()) { settings_.minimap_conn = yaml["minimap_conn"].get_value<std::string>(); }
|
||||
else if (yaml["minimap_conn"].is_integer()) { settings_.minimap_conn = std::to_string(yaml["minimap_conn"].get_value<int>()); }
|
||||
if (yaml["minimap_conn"].is_string()) {
|
||||
settings_.minimap_conn = yaml["minimap_conn"].get_value<std::string>();
|
||||
} else if (yaml["minimap_conn"].is_integer()) {
|
||||
settings_.minimap_conn = std::to_string(yaml["minimap_conn"].get_value<int>());
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
// Fichero corrupto o vacío, usar defaults
|
||||
@@ -116,8 +122,9 @@ auto MapEditor::showGrid(bool show) -> std::string {
|
||||
|
||||
// Parsea un color por nombre o índice numérico
|
||||
static auto parseColor(const std::string& value) -> Uint8 {
|
||||
try { return static_cast<Uint8>(std::stoi(value)); }
|
||||
catch (...) { return stringToColor(value); }
|
||||
try {
|
||||
return static_cast<Uint8>(std::stoi(value));
|
||||
} catch (...) { return stringToColor(value); }
|
||||
}
|
||||
|
||||
void MapEditor::toggleMiniMap() {
|
||||
@@ -243,7 +250,7 @@ void MapEditor::exit() {
|
||||
// Restaurar prompt y scope de la consola
|
||||
selected_enemy_ = -1;
|
||||
Console::get()->setPrompt("> ");
|
||||
Console::get()->setScope("");
|
||||
Console::get()->setScope("debug");
|
||||
drag_ = {};
|
||||
statusbar_.reset();
|
||||
room_.reset();
|
||||
@@ -421,14 +428,13 @@ void MapEditor::handleEvent(const SDL_Event& event) {
|
||||
// Tile bajo el cursor como tile actual del picker
|
||||
int tile_index = mouse_tile_y_ * 32 + mouse_tile_x_;
|
||||
int current = (tile_index >= 0 && tile_index < static_cast<int>(room_data_.tile_map.size()))
|
||||
? room_data_.tile_map[tile_index]
|
||||
: -1;
|
||||
? room_data_.tile_map[tile_index]
|
||||
: -1;
|
||||
|
||||
tile_picker_.on_select = [this](int tile) {
|
||||
brush_tile_ = tile;
|
||||
};
|
||||
tile_picker_.open(room_->getTileSetFile(), current,
|
||||
stringToColor(room_data_.bg_color));
|
||||
tile_picker_.open(room_->getTileSetFile(), current, stringToColor(room_data_.bg_color));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1178,19 +1184,36 @@ auto MapEditor::setRoomProperty(const std::string& property, const std::string&
|
||||
// Dirección opuesta para la conexión recíproca
|
||||
std::string opposite;
|
||||
std::string* our_field = nullptr;
|
||||
if (property == "UP") { opposite = "lower_room"; our_field = &room_data_.upper_room; }
|
||||
if (property == "DOWN") { opposite = "upper_room"; our_field = &room_data_.lower_room; }
|
||||
if (property == "LEFT") { opposite = "right_room"; our_field = &room_data_.left_room; }
|
||||
if (property == "RIGHT") { opposite = "left_room"; our_field = &room_data_.right_room; }
|
||||
if (property == "UP") {
|
||||
opposite = "lower_room";
|
||||
our_field = &room_data_.upper_room;
|
||||
}
|
||||
if (property == "DOWN") {
|
||||
opposite = "upper_room";
|
||||
our_field = &room_data_.lower_room;
|
||||
}
|
||||
if (property == "LEFT") {
|
||||
opposite = "right_room";
|
||||
our_field = &room_data_.left_room;
|
||||
}
|
||||
if (property == "RIGHT") {
|
||||
opposite = "left_room";
|
||||
our_field = &room_data_.right_room;
|
||||
}
|
||||
|
||||
// Si había una conexión anterior, romper la recíproca de la otra room
|
||||
if (our_field != nullptr && *our_field != "0" && !our_field->empty()) {
|
||||
auto old_other = Resource::Cache::get()->getRoom(*our_field);
|
||||
if (old_other) {
|
||||
if (opposite == "upper_room") { old_other->upper_room = "0"; }
|
||||
else if (opposite == "lower_room") { old_other->lower_room = "0"; }
|
||||
else if (opposite == "left_room") { old_other->left_room = "0"; }
|
||||
else if (opposite == "right_room") { old_other->right_room = "0"; }
|
||||
if (opposite == "upper_room") {
|
||||
old_other->upper_room = "0";
|
||||
} else if (opposite == "lower_room") {
|
||||
old_other->lower_room = "0";
|
||||
} else if (opposite == "left_room") {
|
||||
old_other->left_room = "0";
|
||||
} else if (opposite == "right_room") {
|
||||
old_other->right_room = "0";
|
||||
}
|
||||
// Guardar la otra room
|
||||
std::string other_path = Resource::List::get()->get(*our_field);
|
||||
if (!other_path.empty()) {
|
||||
@@ -1207,10 +1230,15 @@ auto MapEditor::setRoomProperty(const std::string& property, const std::string&
|
||||
if (connection != "0") {
|
||||
auto other = Resource::Cache::get()->getRoom(connection);
|
||||
if (other) {
|
||||
if (opposite == "upper_room") { other->upper_room = room_path_; }
|
||||
else if (opposite == "lower_room") { other->lower_room = room_path_; }
|
||||
else if (opposite == "left_room") { other->left_room = room_path_; }
|
||||
else if (opposite == "right_room") { other->right_room = room_path_; }
|
||||
if (opposite == "upper_room") {
|
||||
other->upper_room = room_path_;
|
||||
} else if (opposite == "lower_room") {
|
||||
other->lower_room = room_path_;
|
||||
} else if (opposite == "left_room") {
|
||||
other->left_room = room_path_;
|
||||
} else if (opposite == "right_room") {
|
||||
other->right_room = room_path_;
|
||||
}
|
||||
std::string other_path = Resource::List::get()->get(connection);
|
||||
if (!other_path.empty()) {
|
||||
auto other_yaml = RoomSaver::loadYAML(other_path);
|
||||
@@ -1306,10 +1334,15 @@ auto MapEditor::createNewRoom(const std::string& direction) -> std::string {
|
||||
// Comprobar que no hay ya una room en esa dirección
|
||||
if (!direction.empty()) {
|
||||
std::string* existing = nullptr;
|
||||
if (direction == "UP") { existing = &room_data_.upper_room; }
|
||||
else if (direction == "DOWN") { existing = &room_data_.lower_room; }
|
||||
else if (direction == "LEFT") { existing = &room_data_.left_room; }
|
||||
else if (direction == "RIGHT") { existing = &room_data_.right_room; }
|
||||
if (direction == "UP") {
|
||||
existing = &room_data_.upper_room;
|
||||
} else if (direction == "DOWN") {
|
||||
existing = &room_data_.lower_room;
|
||||
} else if (direction == "LEFT") {
|
||||
existing = &room_data_.left_room;
|
||||
} else if (direction == "RIGHT") {
|
||||
existing = &room_data_.right_room;
|
||||
}
|
||||
if (existing != nullptr && *existing != "0" && !existing->empty()) {
|
||||
return "Already connected " + toLower(direction) + ": " + *existing;
|
||||
}
|
||||
@@ -1319,8 +1352,9 @@ auto MapEditor::createNewRoom(const std::string& direction) -> std::string {
|
||||
auto& rooms = Resource::Cache::get()->getRooms();
|
||||
std::set<int> used;
|
||||
for (const auto& r : rooms) {
|
||||
try { used.insert(std::stoi(r.name.substr(0, r.name.find('.')))); }
|
||||
catch (...) {}
|
||||
try {
|
||||
used.insert(std::stoi(r.name.substr(0, r.name.find('.'))));
|
||||
} catch (...) {}
|
||||
}
|
||||
int new_num = 1;
|
||||
while (used.contains(new_num)) { ++new_num; }
|
||||
@@ -1351,10 +1385,15 @@ auto MapEditor::createNewRoom(const std::string& direction) -> std::string {
|
||||
new_room.tile_map.resize(32 * 16, -1);
|
||||
|
||||
// Conexión recíproca: la nueva room conecta de vuelta a la actual
|
||||
if (direction == "UP") { new_room.lower_room = room_path_; }
|
||||
else if (direction == "DOWN") { new_room.upper_room = room_path_; }
|
||||
else if (direction == "LEFT") { new_room.right_room = room_path_; }
|
||||
else if (direction == "RIGHT") { new_room.left_room = room_path_; }
|
||||
if (direction == "UP") {
|
||||
new_room.lower_room = room_path_;
|
||||
} else if (direction == "DOWN") {
|
||||
new_room.upper_room = room_path_;
|
||||
} else if (direction == "LEFT") {
|
||||
new_room.right_room = room_path_;
|
||||
} else if (direction == "RIGHT") {
|
||||
new_room.left_room = room_path_;
|
||||
}
|
||||
|
||||
// Conexiones del YAML
|
||||
auto connStr = [](const std::string& c) -> std::string { return (c == "0") ? "null" : c; };
|
||||
@@ -1400,10 +1439,15 @@ auto MapEditor::createNewRoom(const std::string& direction) -> std::string {
|
||||
addRoomToAssetsYaml(new_name);
|
||||
|
||||
// Conectar la room actual con la nueva (recíproco: ya hecho arriba para la nueva)
|
||||
if (direction == "UP") { room_data_.upper_room = new_name; }
|
||||
else if (direction == "DOWN") { room_data_.lower_room = new_name; }
|
||||
else if (direction == "LEFT") { room_data_.left_room = new_name; }
|
||||
else if (direction == "RIGHT") { room_data_.right_room = new_name; }
|
||||
if (direction == "UP") {
|
||||
room_data_.upper_room = new_name;
|
||||
} else if (direction == "DOWN") {
|
||||
room_data_.lower_room = new_name;
|
||||
} else if (direction == "LEFT") {
|
||||
room_data_.left_room = new_name;
|
||||
} else if (direction == "RIGHT") {
|
||||
room_data_.right_room = new_name;
|
||||
}
|
||||
|
||||
if (!direction.empty()) { autosave(); }
|
||||
|
||||
@@ -1425,15 +1469,23 @@ auto MapEditor::deleteRoom() -> std::string {
|
||||
|
||||
// Buscar una room vecina a la que navegar después de borrar
|
||||
std::string target = "0";
|
||||
if (room_data_.upper_room != "0" && !room_data_.upper_room.empty()) { target = room_data_.upper_room; }
|
||||
else if (room_data_.lower_room != "0" && !room_data_.lower_room.empty()) { target = room_data_.lower_room; }
|
||||
else if (room_data_.left_room != "0" && !room_data_.left_room.empty()) { target = room_data_.left_room; }
|
||||
else if (room_data_.right_room != "0" && !room_data_.right_room.empty()) { target = room_data_.right_room; }
|
||||
if (room_data_.upper_room != "0" && !room_data_.upper_room.empty()) {
|
||||
target = room_data_.upper_room;
|
||||
} else if (room_data_.lower_room != "0" && !room_data_.lower_room.empty()) {
|
||||
target = room_data_.lower_room;
|
||||
} else if (room_data_.left_room != "0" && !room_data_.left_room.empty()) {
|
||||
target = room_data_.left_room;
|
||||
} else if (room_data_.right_room != "0" && !room_data_.right_room.empty()) {
|
||||
target = room_data_.right_room;
|
||||
}
|
||||
|
||||
if (target == "0") {
|
||||
// Buscar la primera room que no sea esta
|
||||
for (const auto& r : Resource::Cache::get()->getRooms()) {
|
||||
if (r.name != deleted_name) { target = r.name; break; }
|
||||
if (r.name != deleted_name) {
|
||||
target = r.name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (target == "0") { return "Cannot delete: no other room to navigate to"; }
|
||||
@@ -1443,10 +1495,15 @@ auto MapEditor::deleteRoom() -> std::string {
|
||||
if (neighbor == "0" || neighbor.empty()) { return; }
|
||||
auto other = Resource::Cache::get()->getRoom(neighbor);
|
||||
if (!other) { return; }
|
||||
if (field_name == "upper_room") { other->upper_room = "0"; }
|
||||
else if (field_name == "lower_room") { other->lower_room = "0"; }
|
||||
else if (field_name == "left_room") { other->left_room = "0"; }
|
||||
else if (field_name == "right_room") { other->right_room = "0"; }
|
||||
if (field_name == "upper_room") {
|
||||
other->upper_room = "0";
|
||||
} else if (field_name == "lower_room") {
|
||||
other->lower_room = "0";
|
||||
} else if (field_name == "left_room") {
|
||||
other->left_room = "0";
|
||||
} else if (field_name == "right_room") {
|
||||
other->right_room = "0";
|
||||
}
|
||||
// Guardar la otra room
|
||||
std::string other_path = Resource::List::get()->get(neighbor);
|
||||
if (!other_path.empty()) {
|
||||
@@ -1474,8 +1531,7 @@ auto MapEditor::deleteRoom() -> std::string {
|
||||
// Quitar del cache
|
||||
auto& cache_rooms = Resource::Cache::get()->getRooms();
|
||||
cache_rooms.erase(
|
||||
std::remove_if(cache_rooms.begin(), cache_rooms.end(),
|
||||
[&](const RoomResource& r) { return r.name == deleted_name; }),
|
||||
std::remove_if(cache_rooms.begin(), cache_rooms.end(), [&](const RoomResource& r) { return r.name == deleted_name; }),
|
||||
cache_rooms.end());
|
||||
|
||||
// Quitar de assets.yaml
|
||||
|
||||
Reference in New Issue
Block a user