110 lines
3.6 KiB
C++
110 lines
3.6 KiB
C++
#pragma once
|
|
|
|
#ifdef _DEBUG
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <memory> // Para shared_ptr, unique_ptr
|
|
#include <string> // Para string
|
|
|
|
#include "external/fkyaml_node.hpp" // Para fkyaml::node
|
|
#include "game/entities/enemy.hpp" // Para Enemy::Data
|
|
#include "game/entities/item.hpp" // Para Item::Data
|
|
#include "game/entities/player.hpp" // Para Player::SpawnData
|
|
#include "game/gameplay/room.hpp" // Para Room::Data
|
|
#include "game/gameplay/scoreboard.hpp" // Para Scoreboard::Data
|
|
#include "game/options.hpp" // Para Options::Cheat
|
|
|
|
class EditorStatusBar;
|
|
|
|
class MapEditor {
|
|
public:
|
|
static void init(); // [SINGLETON] Crea el objeto
|
|
static void destroy(); // [SINGLETON] Destruye el objeto
|
|
static auto get() -> MapEditor*; // [SINGLETON] Obtiene el objeto
|
|
|
|
void enter(std::shared_ptr<Room> room, std::shared_ptr<Player> player, const std::string& room_path, std::shared_ptr<Scoreboard::Data> scoreboard_data);
|
|
void exit();
|
|
[[nodiscard]] auto isActive() const -> bool { return active_; }
|
|
|
|
void update(float delta_time);
|
|
void render();
|
|
void handleEvent(const SDL_Event& event);
|
|
auto revert() -> std::string;
|
|
|
|
// Comandos para enemigos (llamados desde console_commands)
|
|
auto setEnemyProperty(const std::string& property, const std::string& value) -> std::string;
|
|
auto addEnemy() -> std::string;
|
|
auto deleteEnemy() -> std::string;
|
|
auto duplicateEnemy() -> std::string;
|
|
[[nodiscard]] auto hasSelectedEnemy() const -> bool;
|
|
|
|
// Comandos para propiedades de la habitación
|
|
auto setRoomProperty(const std::string& property, const std::string& value) -> std::string;
|
|
|
|
private:
|
|
static MapEditor* instance_; // [SINGLETON] Objeto privado
|
|
|
|
MapEditor(); // Constructor
|
|
~MapEditor(); // Destructor
|
|
|
|
// Tipos para drag & drop y selección
|
|
enum class DragTarget { NONE, PLAYER, ENEMY_INITIAL, ENEMY_BOUND1, ENEMY_BOUND2, ITEM };
|
|
|
|
struct DragState {
|
|
DragTarget target{DragTarget::NONE};
|
|
int index{-1};
|
|
float offset_x{0.0F};
|
|
float offset_y{0.0F};
|
|
float snap_x{0.0F};
|
|
float snap_y{0.0F};
|
|
bool moved{false}; // true si el ratón se movió durante el drag
|
|
};
|
|
|
|
// Métodos internos
|
|
void updateMousePosition();
|
|
void renderEnemyBoundaries();
|
|
void renderBoundaryMarker(float x, float y, Uint8 color);
|
|
void renderSelectionHighlight();
|
|
void handleMouseDown(float game_x, float game_y);
|
|
void handleMouseUp();
|
|
void updateDrag();
|
|
void autosave();
|
|
void updateStatusBarInfo();
|
|
static auto snapToGrid(float value) -> float;
|
|
static auto pointInRect(float px, float py, const SDL_FRect& rect) -> bool;
|
|
|
|
// Estado del editor
|
|
bool active_{false};
|
|
DragState drag_;
|
|
int selected_enemy_{-1}; // Índice del enemigo seleccionado (-1 = ninguno)
|
|
|
|
// Datos de la habitación
|
|
Room::Data room_data_;
|
|
std::string room_path_;
|
|
std::string file_path_;
|
|
|
|
// YAML: nodo original (para campos que no se editan: name_ca, etc.)
|
|
fkyaml::node yaml_;
|
|
fkyaml::node yaml_backup_;
|
|
|
|
// Referencias a objetos vivos
|
|
std::shared_ptr<Room> room_;
|
|
std::shared_ptr<Player> player_;
|
|
std::shared_ptr<Scoreboard::Data> scoreboard_data_;
|
|
|
|
// Barra de estado del editor
|
|
std::unique_ptr<EditorStatusBar> statusbar_;
|
|
|
|
// Estado del ratón
|
|
float mouse_game_x_{0.0F};
|
|
float mouse_game_y_{0.0F};
|
|
int mouse_tile_x_{0};
|
|
int mouse_tile_y_{0};
|
|
|
|
// Estado previo de invencibilidad
|
|
Options::Cheat::State invincible_before_editor_{Options::Cheat::State::DISABLED};
|
|
};
|
|
|
|
#endif // _DEBUG
|