feat(editor): mode editor mínim amb toggle, border blau i mutex amb pausa
This commit is contained in:
1 parent
329bf692e6
commit
a612a8255f
9 files changed
+232
-30
No files matched your search
@@ -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
|
||||
Reference in new issue
Block a user