From 2b107d9cd789a53d130c2add39629d91c3c80abe Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 12 Oct 2025 22:40:23 -0400 Subject: [PATCH] feat(palette): integrate PaletteManager for centralized color management in DungeonEditorV2 --- src/app/editor/dungeon/dungeon_editor_v2.cc | 25 ++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/app/editor/dungeon/dungeon_editor_v2.cc b/src/app/editor/dungeon/dungeon_editor_v2.cc index e6792ae6..7dd7cab4 100644 --- a/src/app/editor/dungeon/dungeon_editor_v2.cc +++ b/src/app/editor/dungeon/dungeon_editor_v2.cc @@ -5,6 +5,7 @@ #include "absl/strings/str_format.h" #include "app/gfx/arena.h" +#include "app/gfx/palette_manager.h" #include "app/gfx/snes_palette.h" #include "zelda3/dungeon/room.h" #include "app/gui/icons.h" @@ -149,13 +150,18 @@ absl::Status DungeonEditorV2::Load() { // NOW initialize emulator preview with loaded ROM object_emulator_preview_.Initialize(renderer_, rom_); + // Initialize centralized PaletteManager with ROM data + // This MUST be done before initializing palette_editor_ + gfx::PaletteManager::Get().Initialize(rom_); + // Initialize palette editor with loaded ROM palette_editor_.Initialize(rom_); - + // Initialize unified object editor card object_editor_card_ = std::make_unique(renderer_, rom_, &canvas_viewer_); - + // Wire palette changes to trigger room re-renders + // PaletteManager now tracks all modifications globally palette_editor_.SetOnPaletteChanged([this](int /*palette_id*/) { // Re-render all active rooms when palette changes for (int i = 0; i < active_rooms_.Size; i++) { @@ -201,12 +207,25 @@ absl::Status DungeonEditorV2::Save() { return absl::FailedPreconditionError("ROM not loaded"); } + // Save palette changes first (if any) + if (gfx::PaletteManager::Get().HasUnsavedChanges()) { + auto status = gfx::PaletteManager::Get().SaveAllToRom(); + if (!status.ok()) { + LOG_ERROR("DungeonEditorV2", "Failed to save palette changes: %s", + status.message().data()); + return status; + } + LOG_INFO("DungeonEditorV2", "Saved %zu modified colors to ROM", + gfx::PaletteManager::Get().GetModifiedColorCount()); + } + // Save all rooms (SaveObjects will handle which ones need saving) for (auto& room : rooms_) { auto status = room.SaveObjects(); if (!status.ok()) { // Log error but continue with other rooms - LOG_ERROR("DungeonEditorV2", "Failed to save room: %s", status.message().data()); + LOG_ERROR("DungeonEditorV2", "Failed to save room: %s", + status.message().data()); } }