refactor(editor): improve session management in EditorManager

- Refactored session management methods in EditorManager to enhance clarity and maintainability.
- Adjusted context handling for session switching and duplication, ensuring proper session IDs are set.
- Updated the editor dependencies to use IRenderer instead of Renderer, aligning with the new graphics interface.

Benefits:
- Streamlines session management logic, leading to a more organized codebase.
- Improves compatibility with future graphics enhancements by adopting the IRenderer interface.
This commit is contained in:
scawful
2025-10-15 09:39:38 -04:00
parent 931a6c0747
commit 107475196c
2 changed files with 32 additions and 22 deletions

View File

@@ -20,7 +20,7 @@ namespace yaze {
// Forward declarations
class Rom;
namespace gfx {
class Renderer;
class IRenderer;
}
/**
@@ -72,10 +72,9 @@ struct EditorDependencies {
ShortcutManager* shortcut_manager = nullptr;
UserSettings* user_settings = nullptr;
size_t session_id = 0;
// Optional dependencies for specialized editors
gfx::Renderer* renderer = nullptr; // For emulator, dungeon editor
void* custom_data = nullptr; // Type-erased for editor-specific needs
gfx::IRenderer* renderer = nullptr;
void* custom_data = nullptr;
};
struct EditorContext {

View File

@@ -2232,9 +2232,9 @@ void EditorManager::CreateNewSession() {
// Wire editor contexts for new session
if (!sessions_.empty()) {
RomSession& session = sessions_.back();
session.editors.set_user_settings(&user_settings_);
for (auto* editor : session.editors.active_editors_) {
editor->set_context(&context_);
session.editors.set_user_settings(&user_settings_);
for (auto* editor : session.editors.active_editors_) {
editor->set_context(&context_);
}
}
}
@@ -2265,9 +2265,9 @@ void EditorManager::DuplicateCurrentSession() {
// Wire editor contexts for duplicated session
if (!sessions_.empty()) {
RomSession& session = sessions_.back();
for (auto* editor : session.editors.active_editors_) {
editor->set_context(&context_);
}
for (auto* editor : session.editors.active_editors_) {
editor->set_context(&context_);
}
}
}
}
@@ -2282,7 +2282,10 @@ void EditorManager::CloseCurrentSession() {
if (active_index < sessions_.size()) {
current_rom_ = &sessions_[active_index].rom;
current_editor_set_ = &sessions_[active_index].editors;
context_.session_id = active_index;
#ifdef YAZE_ENABLE_TESTING
test::TestManager::Get().SetCurrentRom(current_rom_);
#endif
}
}
}
@@ -2298,29 +2301,37 @@ void EditorManager::RemoveSession(size_t index) {
if (active_index < sessions_.size()) {
current_rom_ = &sessions_[active_index].rom;
current_editor_set_ = &sessions_[active_index].editors;
context_.session_id = active_index;
#ifdef YAZE_ENABLE_TESTING
test::TestManager::Get().SetCurrentRom(current_rom_);
#endif
}
}
}
}
void EditorManager::SwitchToSession(size_t index) {
if (session_coordinator_) {
session_coordinator_->SwitchToSession(index);
// Update current pointers after session switch
if (index < sessions_.size()) {
if (!session_coordinator_) {
return;
}
session_coordinator_->SwitchToSession(index);
if (index >= sessions_.size()) {
return;
}
auto& session = sessions_[index];
current_rom_ = &session.rom;
current_editor_set_ = &session.editors;
// Update test manager with current ROM for ROM-dependent tests
util::logf("EditorManager: Setting ROM in TestManager - %p ('%s')",
(void*)current_rom_,
current_rom_ ? current_rom_->title().c_str() : "null");
test::TestManager::Get().SetCurrentRom(current_rom_);
}
if (context_.session_id != index) {
context_.session_id = index;
}
#ifdef YAZE_ENABLE_TESTING
test::TestManager::Get().SetCurrentRom(current_rom_);
#endif
}
size_t EditorManager::GetCurrentSessionIndex() const {