diff --git a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp index 7d2159e3..4d9529c7 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp @@ -16,18 +16,9 @@ namespace nostalgia::core { PaletteEditorImGui::PaletteEditorImGui(turbine::Context &ctx, ox::CRStringView path): + Editor(path), m_ctx(ctx), - m_itemPath(path), - m_itemName(m_itemPath.substr(std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset() + 1)), - m_pal(*keel::readObj(keelCtx(m_ctx), ox::FileAddress(m_itemPath.c_str())).unwrapThrow()) { -} - -ox::CStringView PaletteEditorImGui::itemName() const noexcept { - return m_itemPath; -} - -ox::CStringView PaletteEditorImGui::itemDisplayName() const noexcept { - return m_itemName; + m_pal(*keel::readObj(keelCtx(m_ctx), ox::FileAddress(itemName())).unwrapThrow()) { } void PaletteEditorImGui::draw(turbine::Context&) noexcept { @@ -140,7 +131,7 @@ void PaletteEditorImGui::draw(turbine::Context&) noexcept { ox::Error PaletteEditorImGui::saveItem() noexcept { const auto sctx = applicationData(m_ctx); - return sctx->project->writeObj(m_itemPath, m_pal); + return sctx->project->writeObj(itemName(), m_pal); } } diff --git a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp index 0d069e80..ebe1c1ab 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp @@ -15,21 +15,12 @@ class PaletteEditorImGui: public studio::Editor { private: turbine::Context &m_ctx; - ox::String m_itemPath; - ox::String m_itemName; Palette m_pal; std::size_t m_selectedRow = 0; public: PaletteEditorImGui(turbine::Context &ctx, ox::CRStringView path); - /** - * Returns the name of item being edited. - */ - ox::CStringView itemName() const noexcept final; - - ox::CStringView itemDisplayName() const noexcept final; - void draw(turbine::Context&) noexcept final; protected: diff --git a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp index ccebd13f..be6a165c 100644 --- a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp +++ b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp @@ -11,23 +11,13 @@ namespace nostalgia::scene { SceneEditorImGui::SceneEditorImGui(turbine::Context &ctx, ox::StringView path): + Editor(path), m_ctx(ctx), - m_itemPath(path), - m_editor(m_ctx, m_itemPath), + m_editor(m_ctx, path), m_view(m_ctx, m_editor.scene()) { - const auto lastSlash = std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset(); - m_itemName = m_itemPath.substr(lastSlash + 1); setRequiresConstantRefresh(false); } -ox::CStringView SceneEditorImGui::itemName() const noexcept { - return m_itemPath; -} - -ox::CStringView SceneEditorImGui::itemDisplayName() const noexcept { - return m_itemName; -} - void SceneEditorImGui::draw(turbine::Context&) noexcept { auto const paneSize = ImGui::GetContentRegionAvail(); m_view.draw(ox::Size{static_cast(paneSize.x), static_cast(paneSize.y)}); @@ -59,8 +49,8 @@ void SceneEditorImGui::onActivated() noexcept { ox::Error SceneEditorImGui::saveItem() noexcept { const auto sctx = applicationData(m_ctx); - oxReturnError(sctx->project->writeObj(m_itemPath, m_editor.scene())); - oxReturnError(keelCtx(m_ctx).assetManager.setAsset(m_itemPath, m_editor.scene())); + oxReturnError(sctx->project->writeObj(itemName(), m_editor.scene())); + oxReturnError(keelCtx(m_ctx).assetManager.setAsset(itemName(), m_editor.scene())); return {}; } diff --git a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp index f4d173a4..69f1f7ca 100644 --- a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp +++ b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp @@ -17,21 +17,12 @@ class SceneEditorImGui: public studio::Editor { private: turbine::Context &m_ctx; - ox::String m_itemName; - ox::String m_itemPath; SceneEditor m_editor; SceneEditorView m_view; public: SceneEditorImGui(turbine::Context &ctx, ox::StringView path); - /** - * Returns the name of item being edited. - */ - ox::CStringView itemName() const noexcept final; - - ox::CStringView itemDisplayName() const noexcept final; - void draw(turbine::Context&) noexcept final; void onActivated() noexcept override; diff --git a/src/olympic/studio/applib/src/clawviewer.cpp b/src/olympic/studio/applib/src/clawviewer.cpp index 9fce4ca5..ab0a38c3 100644 --- a/src/olympic/studio/applib/src/clawviewer.cpp +++ b/src/olympic/studio/applib/src/clawviewer.cpp @@ -9,19 +9,10 @@ namespace studio { ClawEditor::ClawEditor(ox::CRStringView path, ox::ModelObject obj) noexcept: - m_itemName(path), - m_itemDisplayName(pathToItemName(path)), + Editor(path), m_obj(std::move(obj)) { } -ox::CStringView ClawEditor::itemName() const noexcept { - return m_itemName; -} - -ox::CStringView ClawEditor::itemDisplayName() const noexcept { - return m_itemDisplayName; -} - void ClawEditor::draw(turbine::Context&) noexcept { //const auto paneSize = ImGui::GetContentRegionAvail(); ImGui::BeginChild("PaletteEditor"); diff --git a/src/olympic/studio/applib/src/clawviewer.hpp b/src/olympic/studio/applib/src/clawviewer.hpp index 93a3812b..70561857 100644 --- a/src/olympic/studio/applib/src/clawviewer.hpp +++ b/src/olympic/studio/applib/src/clawviewer.hpp @@ -14,19 +14,10 @@ namespace studio { class ClawEditor: public studio::Editor { private: using ObjPath = ox::Vector; - ox::String m_itemName; - ox::String m_itemDisplayName; ox::ModelObject m_obj; public: ClawEditor(ox::CRStringView path, ox::ModelObject obj) noexcept; - /** - * Returns the name of item being edited. - */ - ox::CStringView itemName() const noexcept final; - - ox::CStringView itemDisplayName() const noexcept final; - void draw(turbine::Context&) noexcept final; private: diff --git a/src/olympic/studio/modlib/include/studio/editor.hpp b/src/olympic/studio/modlib/include/studio/editor.hpp index f49433ce..4185c7a8 100644 --- a/src/olympic/studio/modlib/include/studio/editor.hpp +++ b/src/olympic/studio/modlib/include/studio/editor.hpp @@ -120,13 +120,19 @@ class BaseEditor: public Widget { class Editor: public studio::BaseEditor { private: studio::UndoStack m_undoStack; + ox::String m_itemPath; + ox::String m_itemName; public: - Editor() noexcept; + Editor(ox::StringView itemPath) noexcept; - UndoStack *undoStack() noexcept final { - return &m_undoStack; - } + [[nodiscard]] + ox::CStringView itemName() const noexcept final; + + [[nodiscard]] + ox::CStringView itemDisplayName() const noexcept final; + + UndoStack *undoStack() noexcept final; private: ox::Error markUnsavedChanges(const UndoCommand*) noexcept; diff --git a/src/olympic/studio/modlib/src/editor.cpp b/src/olympic/studio/modlib/src/editor.cpp index 2aa3f690..b3f7149c 100644 --- a/src/olympic/studio/modlib/src/editor.cpp +++ b/src/olympic/studio/modlib/src/editor.cpp @@ -112,13 +112,29 @@ void BaseEditor::setRequiresConstantRefresh(bool value) noexcept { } -Editor::Editor() noexcept { +Editor::Editor(ox::StringView itemPath) noexcept: + m_itemPath(itemPath), + m_itemName(m_itemPath.substr(std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset() + 1)) { m_undoStack.changeTriggered.connect(this, &Editor::markUnsavedChanges); } -ox::Error Editor::markUnsavedChanges(const UndoCommand*) noexcept { +[[nodiscard]] +ox::CStringView Editor::itemName() const noexcept { + return m_itemPath; +} + +[[nodiscard]] +ox::CStringView Editor::itemDisplayName() const noexcept { + return m_itemName; +} + +UndoStack *Editor::undoStack() noexcept { + return &m_undoStack; +} + +ox::Error Editor::markUnsavedChanges(UndoCommand const*) noexcept { setUnsavedChanges(true); - return OxError(0); + return {}; } }