llevat soport per a colors amb nom
This commit is contained in:
@@ -10,14 +10,13 @@
|
||||
#include "core/rendering/text.hpp" // Para Text
|
||||
#include "core/resources/resource_cache.hpp" // Para Resource::Cache
|
||||
#include "game/options.hpp" // Para Options::game
|
||||
#include "utils/defines.hpp" // Para Tile::SIZE
|
||||
#include "utils/utils.hpp" // Para stringToColor, toLower
|
||||
#include "utils/utils.hpp" // Para toLower
|
||||
|
||||
// Constructor
|
||||
EditorStatusBar::EditorStatusBar(std::string room_number)
|
||||
: room_number_(std::move(room_number)) {
|
||||
const float SURFACE_WIDTH = Options::game.width;
|
||||
constexpr float SURFACE_HEIGHT = 6.0F * Tile::SIZE; // 48 pixels, igual que el scoreboard
|
||||
constexpr float SURFACE_HEIGHT = 24.0F; // 3 líneas de 8px
|
||||
|
||||
surface_ = std::make_shared<Surface>(SURFACE_WIDTH, SURFACE_HEIGHT);
|
||||
surface_dest_ = {.x = 0, .y = Options::game.height - SURFACE_HEIGHT, .w = SURFACE_WIDTH, .h = SURFACE_HEIGHT};
|
||||
@@ -48,16 +47,26 @@ void EditorStatusBar::fillTexture() {
|
||||
auto previous_renderer = Screen::get()->getRendererSurface();
|
||||
Screen::get()->setRendererSurface(surface_);
|
||||
|
||||
surface_->clear(stringToColor("black"));
|
||||
surface_->clear(0);
|
||||
|
||||
auto text = Resource::Cache::get()->getText("8bithud");
|
||||
const Uint8 LABEL_COLOR = stringToColor("bright_cyan");
|
||||
const Uint8 VALUE_COLOR = stringToColor("white");
|
||||
const Uint8 DETAIL_COLOR = stringToColor("bright_yellow");
|
||||
const Uint8 LABEL_COLOR = 11;
|
||||
const Uint8 VALUE_COLOR = 14;
|
||||
const Uint8 DETAIL_COLOR = 13;
|
||||
const Uint8 COORD_COLOR = 9;
|
||||
const int RIGHT_X = static_cast<int>(Options::game.width) - LEFT_X;
|
||||
|
||||
// Línea 1: Número de la habitación
|
||||
// Línea 1: Room number (izq) + line4 extra (centro) + tile coords + line5 drag info (der)
|
||||
text->writeColored(LEFT_X, LINE1_Y, toLower(room_number_), LABEL_COLOR);
|
||||
|
||||
// Tile coords + drag info a la derecha
|
||||
const std::string TILE_X_STR = (mouse_tile_x_ < 10 ? "0" : "") + std::to_string(mouse_tile_x_);
|
||||
const std::string TILE_Y_STR = (mouse_tile_y_ < 10 ? "0" : "") + std::to_string(mouse_tile_y_);
|
||||
std::string right_part = TILE_X_STR + "," + TILE_Y_STR;
|
||||
if (!line5_.empty()) { right_part += " " + line5_; }
|
||||
if (!line4_.empty()) { right_part = toLower(line4_) + " " + right_part; }
|
||||
text->writeColored(RIGHT_X - text->length(right_part), LINE1_Y, right_part, COORD_COLOR);
|
||||
|
||||
// Línea 2: Propiedades de room o info de enemigo
|
||||
if (!line2_.empty()) {
|
||||
text->writeColored(LEFT_X, LINE2_Y, toLower(line2_), DETAIL_COLOR);
|
||||
@@ -68,20 +77,6 @@ void EditorStatusBar::fillTexture() {
|
||||
text->writeColored(LEFT_X, LINE3_Y, toLower(line3_), VALUE_COLOR);
|
||||
}
|
||||
|
||||
// Línea 4: Extra
|
||||
if (!line4_.empty()) {
|
||||
text->writeColored(LEFT_X, LINE4_Y, toLower(line4_), DETAIL_COLOR);
|
||||
}
|
||||
|
||||
// Línea 5: Tile coords + drag info
|
||||
const std::string TILE_X_STR = (mouse_tile_x_ < 10 ? "0" : "") + std::to_string(mouse_tile_x_);
|
||||
const std::string TILE_Y_STR = (mouse_tile_y_ < 10 ? "0" : "") + std::to_string(mouse_tile_y_);
|
||||
std::string line5 = "tile:" + TILE_X_STR + "," + TILE_Y_STR;
|
||||
if (!line5_.empty()) {
|
||||
line5 += " " + line5_;
|
||||
}
|
||||
text->writeColored(LEFT_X, LINE5_Y, toLower(line5), stringToColor("bright_green"));
|
||||
|
||||
Screen::get()->setRendererSurface(previous_renderer);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,13 +25,11 @@ class EditorStatusBar {
|
||||
private:
|
||||
void fillTexture(); // Dibuja los elementos en la surface
|
||||
|
||||
// Constantes de posición (en pixels dentro de la surface de 256x48)
|
||||
// Font 8bithud lowercase = 6px alto → 5 líneas con 8px de separación
|
||||
static constexpr int LINE1_Y = 2; // Nombre de la habitación
|
||||
static constexpr int LINE2_Y = 10; // Propiedades de room / enemy info
|
||||
static constexpr int LINE3_Y = 18; // Conexiones+items / enemy detail
|
||||
static constexpr int LINE4_Y = 26; // Extra
|
||||
static constexpr int LINE5_Y = 34; // Tile coords + drag info
|
||||
// Constantes de posición (en pixels dentro de la surface de 256x24)
|
||||
// Font 8bithud lowercase = 6px alto → 3 líneas con 8px de separación
|
||||
static constexpr int LINE1_Y = 1; // Room number + tile coords + extra
|
||||
static constexpr int LINE2_Y = 9; // Propiedades de room / enemy info
|
||||
static constexpr int LINE3_Y = 17; // Conexiones+items / enemy detail
|
||||
static constexpr int LEFT_X = 4; // Margen izquierdo
|
||||
|
||||
// Objetos
|
||||
@@ -44,8 +42,8 @@ class EditorStatusBar {
|
||||
int mouse_tile_y_{0}; // Coordenada Y del ratón en tiles
|
||||
std::string line2_; // Contenido de la línea 2
|
||||
std::string line3_; // Contenido de la línea 3
|
||||
std::string line4_; // Contenido de la línea 4
|
||||
std::string line5_; // Contenido de la línea 5
|
||||
std::string line4_; // Contenido de la línea 4 (mostrado en la línea 1 a la derecha)
|
||||
std::string line5_; // Contenido de la línea 5 (mostrado en la línea 1 al centro)
|
||||
};
|
||||
|
||||
#endif // _DEBUG
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "game/options.hpp" // Para Options
|
||||
#include "game/ui/console.hpp" // Para Console
|
||||
#include "utils/defines.hpp" // Para Tile::SIZE, PlayArea
|
||||
#include "utils/utils.hpp" // Para stringToColor
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
// Singleton
|
||||
MapEditor* MapEditor::instance_ = nullptr;
|
||||
@@ -70,17 +70,17 @@ 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_integer()) {
|
||||
settings_.minimap_bg = static_cast<Uint8>(yaml["minimap_bg"].get_value<int>());
|
||||
} else if (yaml["minimap_bg"].is_string()) {
|
||||
settings_.minimap_bg = static_cast<Uint8>(safeStoi(yaml["minimap_bg"].get_value<std::string>(), 2));
|
||||
}
|
||||
}
|
||||
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_integer()) {
|
||||
settings_.minimap_conn = static_cast<Uint8>(yaml["minimap_conn"].get_value<int>());
|
||||
} else if (yaml["minimap_conn"].is_string()) {
|
||||
settings_.minimap_conn = static_cast<Uint8>(safeStoi(yaml["minimap_conn"].get_value<std::string>(), 14));
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
@@ -99,8 +99,8 @@ void MapEditor::saveSettings() const {
|
||||
file << "# Map Editor Settings\n";
|
||||
file << "grid: " << (settings_.grid ? "true" : "false") << "\n";
|
||||
file << "show_render_info: " << (settings_.show_render_info ? "true" : "false") << "\n";
|
||||
file << "minimap_bg: " << settings_.minimap_bg << "\n";
|
||||
file << "minimap_conn: " << settings_.minimap_conn << "\n";
|
||||
file << "minimap_bg: " << static_cast<int>(settings_.minimap_bg) << "\n";
|
||||
file << "minimap_conn: " << static_cast<int>(settings_.minimap_conn) << "\n";
|
||||
file.close();
|
||||
}
|
||||
|
||||
@@ -121,16 +121,14 @@ auto MapEditor::showGrid(bool show) -> std::string {
|
||||
return show ? "Grid ON" : "Grid OFF";
|
||||
}
|
||||
|
||||
// Parsea un color por nombre o índice numérico
|
||||
// Parsea un color como índice numérico
|
||||
static auto parseColor(const std::string& value) -> Uint8 {
|
||||
try {
|
||||
return static_cast<Uint8>(std::stoi(value));
|
||||
} catch (...) { return stringToColor(value); }
|
||||
return static_cast<Uint8>(safeStoi(value, 0));
|
||||
}
|
||||
|
||||
void MapEditor::toggleMiniMap() {
|
||||
if (!mini_map_) {
|
||||
mini_map_ = std::make_unique<MiniMap>(parseColor(settings_.minimap_bg), parseColor(settings_.minimap_conn));
|
||||
mini_map_ = std::make_unique<MiniMap>(settings_.minimap_bg, settings_.minimap_conn);
|
||||
mini_map_->on_navigate = [this](const std::string& room_name) {
|
||||
mini_map_visible_ = false;
|
||||
reenter_ = true;
|
||||
@@ -143,7 +141,7 @@ void MapEditor::toggleMiniMap() {
|
||||
mini_map_visible_ = !mini_map_visible_;
|
||||
if (mini_map_visible_) {
|
||||
// Reconstruir el minimapa (pueden haber cambiado rooms, conexiones, tiles)
|
||||
mini_map_ = std::make_unique<MiniMap>(parseColor(settings_.minimap_bg), parseColor(settings_.minimap_conn));
|
||||
mini_map_ = std::make_unique<MiniMap>(settings_.minimap_bg, settings_.minimap_conn);
|
||||
mini_map_->on_navigate = [this](const std::string& room_name) {
|
||||
mini_map_visible_ = false;
|
||||
reenter_ = true;
|
||||
@@ -157,21 +155,21 @@ void MapEditor::toggleMiniMap() {
|
||||
}
|
||||
|
||||
auto MapEditor::setMiniMapBg(const std::string& color) -> std::string {
|
||||
settings_.minimap_bg = toLower(color);
|
||||
settings_.minimap_bg = static_cast<Uint8>(safeStoi(color, 2));
|
||||
saveSettings();
|
||||
if (mini_map_) {
|
||||
mini_map_->rebuild(parseColor(settings_.minimap_bg), parseColor(settings_.minimap_conn));
|
||||
mini_map_->rebuild(settings_.minimap_bg, settings_.minimap_conn);
|
||||
}
|
||||
return "minimap bg: " + settings_.minimap_bg;
|
||||
return "minimap bg: " + std::to_string(settings_.minimap_bg);
|
||||
}
|
||||
|
||||
auto MapEditor::setMiniMapConn(const std::string& color) -> std::string {
|
||||
settings_.minimap_conn = toLower(color);
|
||||
settings_.minimap_conn = static_cast<Uint8>(safeStoi(color, 14));
|
||||
saveSettings();
|
||||
if (mini_map_) {
|
||||
mini_map_->rebuild(parseColor(settings_.minimap_bg), parseColor(settings_.minimap_conn));
|
||||
mini_map_->rebuild(settings_.minimap_bg, settings_.minimap_conn);
|
||||
}
|
||||
return "minimap conn: " + settings_.minimap_conn;
|
||||
return "minimap conn: " + std::to_string(settings_.minimap_conn);
|
||||
}
|
||||
|
||||
// Entra en modo editor
|
||||
@@ -286,7 +284,7 @@ auto MapEditor::revert() -> std::string {
|
||||
|
||||
// Refrescar visuales de la habitación
|
||||
room_->setBgColor(room_data_.bg_color);
|
||||
Screen::get()->setBorderColor(stringToColor(room_data_.border_color));
|
||||
Screen::get()->setBorderColor(room_data_.border_color);
|
||||
|
||||
// Restaurar el tilemap completo
|
||||
for (int i = 0; i < static_cast<int>(room_data_.tile_map.size()); ++i) {
|
||||
@@ -435,7 +433,7 @@ void MapEditor::handleEvent(const SDL_Event& event) { // NOLINT(readability-fun
|
||||
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, room_data_.bg_color);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -692,7 +690,7 @@ void MapEditor::renderSelectionHighlight() {
|
||||
.y = enemy_rect.y - 1,
|
||||
.w = enemy_rect.w + 2,
|
||||
.h = enemy_rect.h + 2};
|
||||
game_surface->drawRectBorder(&border, stringToColor("bright_green"));
|
||||
game_surface->drawRectBorder(&border, 9);
|
||||
}
|
||||
|
||||
// Highlight del item seleccionado (persistente, color bright_green)
|
||||
@@ -703,13 +701,13 @@ void MapEditor::renderSelectionHighlight() {
|
||||
.y = item_rect.y - 1,
|
||||
.w = item_rect.w + 2,
|
||||
.h = item_rect.h + 2};
|
||||
game_surface->drawRectBorder(&border, stringToColor("bright_green"));
|
||||
game_surface->drawRectBorder(&border, 9);
|
||||
}
|
||||
|
||||
// Highlight del drag activo (temporal, color bright_white)
|
||||
if (drag_.target == DragTarget::NONE || !drag_.moved) { return; }
|
||||
|
||||
const Uint8 DRAG_COLOR = stringToColor("bright_white");
|
||||
const Uint8 DRAG_COLOR = 15;
|
||||
SDL_FRect highlight_rect{};
|
||||
|
||||
switch (drag_.target) {
|
||||
@@ -757,9 +755,9 @@ void MapEditor::renderEnemyBoundaries() {
|
||||
auto game_surface = Screen::get()->getRendererSurface();
|
||||
if (!game_surface) { return; }
|
||||
|
||||
const Uint8 COLOR_BOUND1 = stringToColor("bright_cyan");
|
||||
const Uint8 COLOR_BOUND2 = stringToColor("bright_yellow");
|
||||
const Uint8 COLOR_ROUTE = stringToColor("bright_white");
|
||||
const Uint8 COLOR_BOUND1 = 11;
|
||||
const Uint8 COLOR_BOUND2 = 13;
|
||||
const Uint8 COLOR_ROUTE = 15;
|
||||
|
||||
for (int i = 0; i < static_cast<int>(room_data_.enemies.size()); ++i) {
|
||||
const auto& enemy = room_data_.enemies[i];
|
||||
@@ -878,7 +876,7 @@ void MapEditor::updateStatusBarInfo() { // NOLINT(readability-function-cognitiv
|
||||
auto dot = anim.rfind('.');
|
||||
if (dot != std::string::npos) { anim = anim.substr(0, dot); }
|
||||
|
||||
line2 = "enemy " + std::to_string(selected_enemy_) + ": " + anim + " " + e.color;
|
||||
line2 = "enemy " + std::to_string(selected_enemy_) + ": " + anim + " c:" + std::to_string(e.color);
|
||||
line3 = "vx:" + std::to_string(static_cast<int>(e.vx)) +
|
||||
" vy:" + std::to_string(static_cast<int>(e.vy));
|
||||
if (e.flip) { line3 += " flip"; }
|
||||
@@ -898,10 +896,10 @@ void MapEditor::updateStatusBarInfo() { // NOLINT(readability-function-cognitiv
|
||||
conv = "right";
|
||||
}
|
||||
|
||||
line2 = "bg:" + room_data_.bg_color + " brd:" + room_data_.border_color + " conv:" + conv;
|
||||
line2 = "bg:" + std::to_string(room_data_.bg_color) + " brd:" + std::to_string(room_data_.border_color) + " conv:" + conv;
|
||||
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:" + room_data_.item_color1 + "/" + room_data_.item_color2;
|
||||
" itm:" + std::to_string(room_data_.item_color1) + "/" + std::to_string(room_data_.item_color2);
|
||||
}
|
||||
|
||||
// Línea 4: brush activo
|
||||
@@ -971,10 +969,10 @@ auto MapEditor::setEnemyProperty(const std::string& property, const std::string&
|
||||
}
|
||||
|
||||
if (property == "COLOR") {
|
||||
std::string color = toLower(value);
|
||||
auto color = static_cast<Uint8>(safeStoi(value, 14));
|
||||
|
||||
// Intentar recrear el enemigo con el nuevo color
|
||||
std::string old_color = enemy.color;
|
||||
Uint8 old_color = enemy.color;
|
||||
enemy.color = color;
|
||||
try {
|
||||
auto* enemy_mgr = room_->getEnemyManager();
|
||||
@@ -985,7 +983,7 @@ auto MapEditor::setEnemyProperty(const std::string& property, const std::string&
|
||||
}
|
||||
|
||||
autosave();
|
||||
return "color: " + color;
|
||||
return "color: " + std::to_string(color);
|
||||
}
|
||||
|
||||
if (property == "VX") {
|
||||
@@ -1063,7 +1061,7 @@ auto MapEditor::addEnemy() -> std::string {
|
||||
new_enemy.y1 = static_cast<int>(CENTER_Y);
|
||||
new_enemy.x2 = static_cast<int>(CENTER_X + ROUTE_HALF);
|
||||
new_enemy.y2 = static_cast<int>(CENTER_Y);
|
||||
new_enemy.color = "white";
|
||||
new_enemy.color = 14;
|
||||
new_enemy.flip = true;
|
||||
new_enemy.frame = -1;
|
||||
|
||||
@@ -1131,35 +1129,35 @@ auto MapEditor::setRoomProperty(const std::string& property, const std::string&
|
||||
std::string val = toLower(value);
|
||||
|
||||
if (property == "BGCOLOR") {
|
||||
val = colorToString(stringToColor(val)); // Normaliza a nombre canónico (acepta nombres e índices)
|
||||
room_data_.bg_color = val;
|
||||
room_->setBgColor(val);
|
||||
auto color = static_cast<Uint8>(safeStoi(val, 0));
|
||||
room_data_.bg_color = color;
|
||||
room_->setBgColor(color);
|
||||
autosave();
|
||||
return "bgcolor: " + val;
|
||||
return "bgcolor: " + std::to_string(color);
|
||||
}
|
||||
|
||||
if (property == "BORDER") {
|
||||
val = colorToString(stringToColor(val));
|
||||
room_data_.border_color = val;
|
||||
Screen::get()->setBorderColor(stringToColor(val));
|
||||
auto color = static_cast<Uint8>(safeStoi(val, 0));
|
||||
room_data_.border_color = color;
|
||||
Screen::get()->setBorderColor(color);
|
||||
autosave();
|
||||
return "border: " + val;
|
||||
return "border: " + std::to_string(color);
|
||||
}
|
||||
|
||||
if (property == "ITEMCOLOR1") {
|
||||
val = colorToString(stringToColor(val));
|
||||
room_data_.item_color1 = val;
|
||||
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: " + val;
|
||||
return "itemcolor1: " + std::to_string(color);
|
||||
}
|
||||
|
||||
if (property == "ITEMCOLOR2") {
|
||||
val = colorToString(stringToColor(val));
|
||||
room_data_.item_color2 = val;
|
||||
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: " + val;
|
||||
return "itemcolor2: " + std::to_string(color);
|
||||
}
|
||||
|
||||
if (property == "CONVEYOR") {
|
||||
@@ -1320,11 +1318,11 @@ auto MapEditor::createNewRoom(const std::string& direction) -> std::string { //
|
||||
// Crear Room::Data por defecto con conexión recíproca
|
||||
Room::Data new_room;
|
||||
new_room.number = std::string(name_buf).substr(0, std::string(name_buf).find('.'));
|
||||
new_room.bg_color = "black";
|
||||
new_room.border_color = "magenta";
|
||||
new_room.bg_color = 0;
|
||||
new_room.border_color = 6;
|
||||
new_room.tile_set_file = "standard.gif";
|
||||
new_room.item_color1 = "bright_cyan";
|
||||
new_room.item_color2 = "yellow";
|
||||
new_room.item_color1 = 11;
|
||||
new_room.item_color2 = 12;
|
||||
new_room.upper_room = "0";
|
||||
new_room.lower_room = "0";
|
||||
new_room.left_room = "0";
|
||||
@@ -1531,9 +1529,7 @@ void MapEditor::openTilePicker(const std::string& tileset_name, int current_tile
|
||||
autosave();
|
||||
};
|
||||
// Pasar color de fondo de la habitación + color de sustitución del item
|
||||
int bg = stringToColor(room_data_.bg_color);
|
||||
int item_color = stringToColor(room_data_.item_color1);
|
||||
tile_picker_.open(tileset_name, current_tile, bg, 1, item_color);
|
||||
tile_picker_.open(tileset_name, current_tile, room_data_.bg_color, 1, room_data_.item_color1);
|
||||
}
|
||||
|
||||
// Crea un nuevo item con valores por defecto, centrado en la habitación
|
||||
@@ -1546,8 +1542,8 @@ auto MapEditor::addItem() -> std::string {
|
||||
new_item.x = PlayArea::CENTER_X;
|
||||
new_item.y = PlayArea::CENTER_Y;
|
||||
new_item.counter = 0;
|
||||
new_item.color1 = stringToColor(room_data_.item_color1);
|
||||
new_item.color2 = stringToColor(room_data_.item_color2);
|
||||
new_item.color1 = room_data_.item_color1;
|
||||
new_item.color2 = room_data_.item_color2;
|
||||
|
||||
room_data_.items.push_back(new_item);
|
||||
room_->getItemManager()->addItem(std::make_shared<Item>(new_item));
|
||||
@@ -1600,7 +1596,7 @@ auto MapEditor::duplicateItem() -> std::string {
|
||||
// Elige un color de grid que contraste con el fondo
|
||||
// Empieza con bright_black (1), si coincide con el bg en la paleta activa, sube índices
|
||||
static auto pickGridColor(Uint8 bg, const std::shared_ptr<Surface>& surface) -> Uint8 {
|
||||
auto grid = static_cast<Uint8>(PaletteColor::BRIGHT_BLACK);
|
||||
Uint8 grid = 1;
|
||||
Uint32 bg_argb = surface->getPaletteColor(bg);
|
||||
|
||||
// Si bright_black es igual al bg, buscar el siguiente color distinto
|
||||
@@ -1616,7 +1612,7 @@ void MapEditor::renderGrid() const {
|
||||
auto game_surface = Screen::get()->getRendererSurface();
|
||||
if (!game_surface) { return; }
|
||||
|
||||
const Uint8 COLOR = pickGridColor(stringToColor(room_data_.bg_color), game_surface);
|
||||
const Uint8 COLOR = pickGridColor(room_data_.bg_color, game_surface);
|
||||
|
||||
// Líneas verticales (cada 8 pixels)
|
||||
for (int x = Tile::SIZE; x < PlayArea::WIDTH; x += Tile::SIZE) {
|
||||
|
||||
@@ -74,8 +74,8 @@ class MapEditor {
|
||||
struct Settings {
|
||||
bool grid{false};
|
||||
bool show_render_info{false};
|
||||
std::string minimap_bg{"blue"};
|
||||
std::string minimap_conn{"white"};
|
||||
Uint8 minimap_bg{2};
|
||||
Uint8 minimap_conn{14};
|
||||
};
|
||||
Settings settings_;
|
||||
void loadSettings();
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "core/resources/resource_cache.hpp" // Para Resource::Cache
|
||||
#include "game/gameplay/room.hpp" // Para Room::Data
|
||||
#include "utils/defines.hpp" // Para Tile::SIZE, PlayArea
|
||||
#include "utils/utils.hpp" // Para stringToColor
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
// Constructor: construye todo el minimapa
|
||||
MiniMap::MiniMap(Uint8 bg_color, Uint8 conn_color)
|
||||
@@ -129,6 +129,7 @@ void MiniMap::layoutRooms() {
|
||||
for (const auto& [neighbor_name, dx, dy] : neighbors) {
|
||||
if (neighbor_name == "0" || neighbor_name.empty()) { continue; }
|
||||
if (visited.contains(neighbor_name)) { continue; }
|
||||
if (!room_map.contains(neighbor_name)) { continue; } // Room no existe en cache
|
||||
|
||||
GridPos neighbor_pos = {.x = pos.x + dx, .y = pos.y + dy};
|
||||
auto nkey = std::make_pair(neighbor_pos.x, neighbor_pos.y);
|
||||
@@ -169,14 +170,19 @@ void MiniMap::buildRoomSurfaces() {
|
||||
|
||||
// Genera la mini-surface de una room: 1 pixel por tile, color predominante
|
||||
auto MiniMap::getRoomMiniSurface(const std::string& room_name) -> std::shared_ptr<Surface> {
|
||||
auto room_data = Resource::Cache::get()->getRoom(room_name);
|
||||
std::shared_ptr<Room::Data> room_data;
|
||||
try {
|
||||
room_data = Resource::Cache::get()->getRoom(room_name);
|
||||
} catch (...) {
|
||||
return nullptr; // Room no existe en cache
|
||||
}
|
||||
if (!room_data) { return nullptr; }
|
||||
|
||||
auto surface = std::make_shared<Surface>(ROOM_W, ROOM_H);
|
||||
|
||||
auto prev = Screen::get()->getRendererSurface();
|
||||
Screen::get()->setRendererSurface(surface);
|
||||
surface->clear(stringToColor(room_data->bg_color));
|
||||
surface->clear(room_data->bg_color);
|
||||
|
||||
const auto& tile_map = room_data->tile_map;
|
||||
for (int y = 0; y < ROOM_H; ++y) {
|
||||
@@ -318,7 +324,7 @@ void MiniMap::render(const std::string& current_room) {
|
||||
auto cur_h = static_cast<float>(CELL_H + 2);
|
||||
if (cur_x >= 0 && cur_y >= 0 && cur_x + cur_w <= PlayArea::WIDTH && cur_y + cur_h <= PlayArea::HEIGHT) {
|
||||
SDL_FRect highlight = {.x = cur_x, .y = cur_y, .w = cur_w, .h = cur_h};
|
||||
game_surface->drawRectBorder(&highlight, stringToColor("bright_white"));
|
||||
game_surface->drawRectBorder(&highlight, 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,8 +43,8 @@ auto RoomSaver::buildYAML(const fkyaml::node& original_yaml, const Room::Data& r
|
||||
// --- Sección room ---
|
||||
out << "room:\n";
|
||||
|
||||
out << " bgColor: " << room_data.bg_color << "\n";
|
||||
out << " border: " << room_data.border_color << "\n";
|
||||
out << " bgColor: " << static_cast<int>(room_data.bg_color) << "\n";
|
||||
out << " border: " << static_cast<int>(room_data.border_color) << "\n";
|
||||
out << " tileSetFile: " << room_data.tile_set_file << "\n";
|
||||
|
||||
// Conexiones
|
||||
@@ -59,31 +59,29 @@ auto RoomSaver::buildYAML(const fkyaml::node& original_yaml, const Room::Data& r
|
||||
// Colores de items
|
||||
out << "\n";
|
||||
out << " # Colores de los objetos\n";
|
||||
out << " itemColor1: " << (room_data.item_color1.empty() ? "yellow" : room_data.item_color1) << "\n";
|
||||
out << " itemColor2: " << (room_data.item_color2.empty() ? "magenta" : room_data.item_color2) << "\n";
|
||||
out << " itemColor1: " << static_cast<int>(room_data.item_color1) << "\n";
|
||||
out << " itemColor2: " << static_cast<int>(room_data.item_color2) << "\n";
|
||||
|
||||
// Conveyor belt
|
||||
out << "\n";
|
||||
out << " # Dirección de la cinta transportadora: left, none, right\n";
|
||||
out << " conveyorBelt: " << conveyorBeltToString(room_data.conveyor_belt_direction) << "\n";
|
||||
|
||||
// --- Tilemap (16 filas × 32 columnas, formato flow) ---
|
||||
// --- Tilemap (MAP_HEIGHT filas × MAP_WIDTH columnas, formato flow) ---
|
||||
out << "\n";
|
||||
out << "# Tilemap: 16 filas × 32 columnas (256×192 píxeles @ 8px/tile)\n";
|
||||
out << "# Tilemap: " << Map::HEIGHT << " filas x " << Map::WIDTH << " columnas @ " << Tile::SIZE << "px/tile\n";
|
||||
out << "# Índices de tiles (-1 = vacío)\n";
|
||||
out << "tilemap:\n";
|
||||
constexpr int MAP_WIDTH = 32;
|
||||
constexpr int MAP_HEIGHT = 16;
|
||||
for (int row = 0; row < MAP_HEIGHT; ++row) {
|
||||
for (int row = 0; row < Map::HEIGHT; ++row) {
|
||||
out << " - [";
|
||||
for (int col = 0; col < MAP_WIDTH; ++col) {
|
||||
int index = (row * MAP_WIDTH) + col;
|
||||
for (int col = 0; col < Map::WIDTH; ++col) {
|
||||
int index = (row * Map::WIDTH) + col;
|
||||
if (index < static_cast<int>(room_data.tile_map.size())) {
|
||||
out << room_data.tile_map[index];
|
||||
} else {
|
||||
out << -1;
|
||||
}
|
||||
if (col < MAP_WIDTH - 1) { out << ", "; }
|
||||
if (col < Map::WIDTH - 1) { out << ", "; }
|
||||
}
|
||||
out << "]\n";
|
||||
}
|
||||
@@ -110,8 +108,8 @@ auto RoomSaver::buildYAML(const fkyaml::node& original_yaml, const Room::Data& r
|
||||
out << " position1: {x: " << b1_x << ", y: " << b1_y << "}\n";
|
||||
out << " position2: {x: " << b2_x << ", y: " << b2_y << "}\n";
|
||||
|
||||
if (!enemy.color.empty() && enemy.color != "white") {
|
||||
out << " color: " << enemy.color << "\n";
|
||||
if (enemy.color != 14) {
|
||||
out << " color: " << static_cast<int>(enemy.color) << "\n";
|
||||
}
|
||||
if (enemy.flip) { out << " flip: true\n"; }
|
||||
if (enemy.mirror) { out << " mirror: true\n"; }
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "core/rendering/surface.hpp" // Para Surface
|
||||
#include "core/resources/resource_cache.hpp" // Para Resource::Cache
|
||||
#include "utils/defines.hpp" // Para Tile::SIZE, PlayArea
|
||||
#include "utils/utils.hpp" // Para stringToColor
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
// Margen del borde alrededor del tileset (en pixels)
|
||||
static constexpr int BORDER_PAD = 3;
|
||||
@@ -51,14 +51,14 @@ void TilePicker::open(const std::string& tileset_name, int current_tile, int bg_
|
||||
auto prev = Screen::get()->getRendererSurface();
|
||||
Screen::get()->setRendererSurface(frame_surface_);
|
||||
|
||||
Uint8 fill_color = (bg_color >= 0) ? static_cast<Uint8>(bg_color) : stringToColor("black");
|
||||
Uint8 fill_color = (bg_color >= 0) ? static_cast<Uint8>(bg_color) : 0;
|
||||
frame_surface_->clear(fill_color);
|
||||
|
||||
// Borde doble
|
||||
SDL_FRect outer = {.x = 0, .y = 0, .w = static_cast<float>(frame_w), .h = static_cast<float>(frame_h)};
|
||||
frame_surface_->drawRectBorder(&outer, stringToColor("bright_white"));
|
||||
frame_surface_->drawRectBorder(&outer, 15);
|
||||
SDL_FRect inner = {.x = 1, .y = 1, .w = static_cast<float>(frame_w - 2), .h = static_cast<float>(frame_h - 2)};
|
||||
frame_surface_->drawRectBorder(&inner, stringToColor("white"));
|
||||
frame_surface_->drawRectBorder(&inner, 14);
|
||||
|
||||
// Renderizar cada tile individualmente
|
||||
constexpr auto TS = static_cast<float>(Tile::SIZE);
|
||||
@@ -153,7 +153,7 @@ void TilePicker::render() {
|
||||
float hy = tileset_screen_y + static_cast<float>(row * out_cell);
|
||||
if (hy >= 0 && hy + TS <= visible_height_) {
|
||||
SDL_FRect highlight = {.x = hx, .y = hy, .w = TS, .h = TS};
|
||||
game_surface->drawRectBorder(&highlight, stringToColor("bright_white"));
|
||||
game_surface->drawRectBorder(&highlight, 15);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ void TilePicker::render() {
|
||||
float cy = tileset_screen_y + static_cast<float>(row * out_cell);
|
||||
if (cy >= 0 && cy + TS <= visible_height_) {
|
||||
SDL_FRect cur_rect = {.x = cx, .y = cy, .w = TS, .h = TS};
|
||||
game_surface->drawRectBorder(&cur_rect, stringToColor("bright_green"));
|
||||
game_surface->drawRectBorder(&cur_rect, 9);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user