feat(editor): mode editor mínim amb toggle, border blau i mutex amb pausa

This commit is contained in:
JailDesigner committed 2026-04-23 12:09:04 +02:00
1 parent 329bf692e6
commit a612a8255f
9 files changed
+232 -30

No files matched your search

+59
View File
@@ -0,0 +1,59 @@
#include "game/editor/editor.hpp"
#ifdef _DEBUG
#include <SDL3/SDL.h>
#include "core/locale/locale.hpp"
#include "core/rendering/notification_presets.hpp"
#include "core/rendering/screen.hpp"
#include "game/map/tilemap.hpp"
#include "utils/defaults.hpp"
#include "utils/defines.hpp"
void Editor::enter() {
if (active_) { return; }
active_ = true;
Notification::notify(Locale::get().text("input.editor_on"));
}
// cppcheck-suppress constParameterReference
// Tilemap& mutable per simetria amb `toggle()` i per futures
// invalidacions de caches d'edició, encara que `save()` sigui const.
void Editor::exit(Tilemap& tilemap) {
if (!active_) { return; }
active_ = false;
const bool SAVED = tilemap.save(Defaults::Editor::SAVE_PATH);
Notification::notify(Locale::get().text(SAVED ? "input.editor_off" : "input.editor_save_error"));
}
void Editor::toggle(Tilemap& tilemap) {
if (active_) {
exit(tilemap);
} else {
enter();
}
}
// cppcheck-suppress constParameterReference
// Tilemap& mutable: al pas següent `setTileAt()` (no const) el muta.
void Editor::update(int /*delta_ms*/, Tilemap& tilemap) {
if (!active_) { return; }
cursor_col_ = -1;
cursor_row_ = -1;
(void)tilemap; // TODO: brush + click + picker al pas següent.
}
void Editor::render(const Tilemap& /*tilemap*/) const {
if (!active_) { return; }
auto& screen = Screen::get();
constexpr int W = GameCanvas::WIDTH;
constexpr int H = GameCanvas::HEIGHT;
constexpr auto ARGB = Defaults::Editor::BORDER_ARGB;
screen.fillRect(0, 0, W, 1, ARGB); // top
screen.fillRect(0, H - 1, W, 1, ARGB); // bottom
screen.fillRect(0, 0, 1, H, ARGB); // left
screen.fillRect(W - 1, 0, 1, H, ARGB); // right
}
#endif // _DEBUG
+56
View File
@@ -0,0 +1,56 @@
#pragma once
#ifdef _DEBUG
class Tilemap;
// Mode editor modal del GameScene. Només disponible en Debug — en Release
// aquesta classe no existeix (el .cpp es compila a un object buit i cap
// codi del joc final en fa referència).
//
// L'editor NO gestiona la tecla de toggle pròpia (`editor_toggle`): això
// ho fa GameScene per poder decidir la coexistència amb la pausa F11
// (mútuament excloents). L'editor s'encarrega de:
// - Estat propi (actiu/no actiu, brush, picker obert).
// - Input del ratolí i tecles internes (`T`, `ESC`).
// - Render del border blau + brush preview + picker.
// - Persistència del tilemap al YAML del repo en sortir.
//
// GameScene, quan `active()` és true, salta el tick de jugadors/entitats
// i no els pinta; el tilemap sí es pinta perquè és el que s'està editant.
class Editor {
public:
// Entra al mode editor: notifica i marca `active=true`. La congelació
// d'entitats / jugador la gestiona GameScene consultant `active()`.
void enter();
// Surt del mode editor: persisteix el tilemap al YAML (writer surgical)
// i notifica. Si la persistència falla, emet la notificació d'error.
void exit(Tilemap& tilemap);
// Helper: enter() si no actiu, exit() si actiu. Útil des de GameScene
// quan detecta la tecla de toggle.
void toggle(Tilemap& tilemap);
[[nodiscard]] auto active() const -> bool { return active_; }
// Processa input propi (brush, picker). No-op si no actiu.
void update(int delta_ms, Tilemap& tilemap);
// Pinta el border blau i, més endavant, brush preview + picker.
// No-op si no actiu.
void render(const Tilemap& tilemap) const;
private:
bool active_{false};
// Estat de l'edició (brush + cursor + picker). Es poblen al pas
// següent; els declarem ara perquè `update()` pugui mutar-los i les
// signatures queden estables entre hitos.
int brush_{-1}; // Índex de tile al tileset; -1 = sense brush.
int cursor_col_{-1}; // Cel·la sota el cursor (-1 = fora).
int cursor_row_{-1};
bool picker_open_{false};
};
#endif // _DEBUG