refactor de l'editor
This commit is contained in:
@@ -10,15 +10,28 @@
|
||||
#include "external/fkyaml_node.hpp" // Para fkyaml::node
|
||||
#include "game/editor/mini_map.hpp" // Para MiniMap
|
||||
#include "game/editor/tile_picker.hpp" // Para TilePicker
|
||||
#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
|
||||
#include "game/entities/enemy.hpp" // Para Enemy::Data
|
||||
#include "game/entities/item.hpp" // Para Item::Data
|
||||
#include "game/entities/moving_platform.hpp" // Para MovingPlatform::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;
|
||||
|
||||
// Tipo de entidad editable en el editor
|
||||
enum class EntityType { NONE, ENEMY, ITEM, PLATFORM };
|
||||
|
||||
// Seleccion unificada: una sola entidad seleccionada a la vez
|
||||
struct Selection {
|
||||
EntityType type{EntityType::NONE};
|
||||
int index{-1};
|
||||
void clear() { type = EntityType::NONE; index = -1; }
|
||||
[[nodiscard]] auto isNone() const -> bool { return type == EntityType::NONE; }
|
||||
[[nodiscard]] auto is(EntityType t) const -> bool { return type == t && index >= 0; }
|
||||
};
|
||||
|
||||
class MapEditor {
|
||||
public:
|
||||
static void init(); // [SINGLETON] Crea el objeto
|
||||
@@ -39,7 +52,7 @@ class MapEditor {
|
||||
auto addEnemy() -> std::string;
|
||||
auto deleteEnemy() -> std::string;
|
||||
auto duplicateEnemy() -> std::string;
|
||||
[[nodiscard]] auto hasSelectedEnemy() const -> bool;
|
||||
[[nodiscard]] auto hasSelectedEnemy() const -> bool { return selection_.is(EntityType::ENEMY); }
|
||||
[[nodiscard]] auto getSetCompletions() const -> std::vector<std::string>;
|
||||
|
||||
// Comandos para propiedades de la habitación
|
||||
@@ -62,9 +75,19 @@ class MapEditor {
|
||||
auto addItem() -> std::string;
|
||||
auto deleteItem() -> std::string;
|
||||
auto duplicateItem() -> std::string;
|
||||
[[nodiscard]] auto hasSelectedItem() const -> bool;
|
||||
[[nodiscard]] auto hasSelectedItem() const -> bool { return selection_.is(EntityType::ITEM); }
|
||||
void openTilePicker(const std::string& tileset_name, int current_tile);
|
||||
|
||||
// Comandos para plataformas
|
||||
auto setPlatformProperty(const std::string& property, const std::string& value) -> std::string;
|
||||
auto addPlatform() -> std::string;
|
||||
auto deletePlatform() -> std::string;
|
||||
auto duplicatePlatform() -> std::string;
|
||||
[[nodiscard]] auto hasSelectedPlatform() const -> bool { return selection_.is(EntityType::PLATFORM); }
|
||||
|
||||
// Seleccion unificada
|
||||
[[nodiscard]] auto getSelectionType() const -> EntityType { return selection_.type; }
|
||||
|
||||
private:
|
||||
static MapEditor* instance_; // NOLINT(readability-identifier-naming) [SINGLETON] Objeto privado
|
||||
|
||||
@@ -82,16 +105,16 @@ class MapEditor {
|
||||
void loadSettings();
|
||||
void saveSettings() const;
|
||||
|
||||
// Tipos para drag & drop y selección
|
||||
// Tipos para drag & drop
|
||||
enum class DragTarget { NONE,
|
||||
PLAYER,
|
||||
ENEMY_INITIAL,
|
||||
ENEMY_BOUND1,
|
||||
ENEMY_BOUND2,
|
||||
ITEM };
|
||||
ENTITY_INITIAL,
|
||||
ENTITY_BOUND1,
|
||||
ENTITY_BOUND2 };
|
||||
|
||||
struct DragState {
|
||||
DragTarget target{DragTarget::NONE};
|
||||
EntityType entity_type{EntityType::NONE};
|
||||
int index{-1};
|
||||
float offset_x{0.0F};
|
||||
float offset_y{0.0F};
|
||||
@@ -102,23 +125,34 @@ class MapEditor {
|
||||
|
||||
// Métodos internos
|
||||
void updateMousePosition();
|
||||
void renderEnemyBoundaries();
|
||||
void renderEntityBoundaries();
|
||||
static void renderBoundaryMarker(float x, float y, Uint8 color);
|
||||
void renderSelectionHighlight();
|
||||
void renderGrid() const;
|
||||
void handleMouseDown(float game_x, float game_y);
|
||||
void handleMouseUp();
|
||||
void updateDrag();
|
||||
auto commitEntityDrag() -> bool;
|
||||
void moveEntityVisual();
|
||||
void autosave();
|
||||
void updateStatusBarInfo();
|
||||
static auto snapToGrid(float value) -> float;
|
||||
static auto pointInRect(float px, float py, const SDL_FRect& rect) -> bool;
|
||||
|
||||
// Entity helpers: acceso abstracto a datos de entidad por tipo
|
||||
struct BoundaryData { int x1, y1, x2, y2; };
|
||||
auto entityCount(EntityType type) const -> int;
|
||||
auto entityRect(EntityType type, int index) -> SDL_FRect;
|
||||
static auto entityHasBoundaries(EntityType type) -> bool;
|
||||
auto entityBoundaries(EntityType type, int index) const -> BoundaryData;
|
||||
auto entityPosition(EntityType type, int index) const -> std::pair<float, float>;
|
||||
auto entityDataCount(EntityType type) const -> int;
|
||||
static auto entityLabel(EntityType type) -> const char*;
|
||||
|
||||
// Estado del editor
|
||||
bool active_{false};
|
||||
DragState drag_;
|
||||
int selected_enemy_{-1}; // Índice del enemigo seleccionado (-1 = ninguno)
|
||||
int selected_item_{-1}; // Índice del item seleccionado (-1 = ninguno)
|
||||
Selection selection_; // Entidad seleccionada (unificada: enemy, item o platform)
|
||||
static constexpr int NO_BRUSH = -2; // Sin brush activo
|
||||
static constexpr int ERASER_BRUSH = -1; // Brush borrador (pinta tile vacío = -1)
|
||||
int brush_tile_{NO_BRUSH}; // Tile activo para pintar
|
||||
|
||||
Reference in New Issue
Block a user