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 4d9529c7..0e4e57c0 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp @@ -18,7 +18,7 @@ namespace nostalgia::core { PaletteEditorImGui::PaletteEditorImGui(turbine::Context &ctx, ox::CRStringView path): Editor(path), m_ctx(ctx), - m_pal(*keel::readObj(keelCtx(m_ctx), ox::FileAddress(itemName())).unwrapThrow()) { + m_pal(*keel::readObj(keelCtx(m_ctx), ox::FileAddress(itemPath())).unwrapThrow()) { } void PaletteEditorImGui::draw(turbine::Context&) noexcept { @@ -131,7 +131,7 @@ void PaletteEditorImGui::draw(turbine::Context&) noexcept { ox::Error PaletteEditorImGui::saveItem() noexcept { const auto sctx = applicationData(m_ctx); - return sctx->project->writeObj(itemName(), m_pal); + return sctx->project->writeObj(itemPath(), m_pal); } } diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp index 244872c6..d30b19b0 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp @@ -42,11 +42,9 @@ ox::Error toPngFile( } TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context &ctx, ox::CRStringView path): + Editor(path), m_ctx(ctx), - m_itemPath(path), - m_tileSheetEditor(m_ctx, m_itemPath) { - const auto lastSlash = ox::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset(); - m_itemName = m_itemPath.substr(lastSlash + 1); + m_tileSheetEditor(m_ctx, path, *undoStack()) { oxIgnoreError(setPaletteSelection()); // connect signal/slots undoStack()->changeTriggered.connect(this, &TileSheetEditorImGui::markUnsavedChanges); @@ -54,14 +52,6 @@ TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context &ctx, ox::CRStringVi model()->paletteChanged.connect(this, &TileSheetEditorImGui::setPaletteSelection); } -ox::CStringView TileSheetEditorImGui::itemName() const noexcept { - return m_itemPath; -} - -ox::CStringView TileSheetEditorImGui::itemDisplayName() const noexcept { - return m_itemName; -} - void TileSheetEditorImGui::exportFile() { exportSubhseetToPng(); } @@ -231,10 +221,6 @@ void TileSheetEditorImGui::drawSubsheetSelector(TileSheet::SubSheet *subsheet, T } } -studio::UndoStack *TileSheetEditorImGui::undoStack() noexcept { - return model()->undoStack(); -} - [[nodiscard]] ox::Vec2 TileSheetEditorImGui::clickPos(ImVec2 const&winPos, ox::Vec2 clickPos) noexcept { clickPos.x -= winPos.x + 10; diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp index 59bae5e4..e9451dcc 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp @@ -23,7 +23,7 @@ enum class Tool { Select, }; -class TileSheetEditorImGui: public studio::BaseEditor { +class TileSheetEditorImGui: public studio::Editor { private: class SubSheetEditor { @@ -46,8 +46,6 @@ class TileSheetEditorImGui: public studio::BaseEditor { turbine::Context &m_ctx; ox::Vector m_paletteList; SubSheetEditor m_subsheetEditor; - ox::String m_itemPath; - ox::String m_itemName; glutils::FrameBuffer m_framebuffer; TileSheetEditorView m_tileSheetEditor; float m_palViewWidth = 300; @@ -59,10 +57,6 @@ class TileSheetEditorImGui: public studio::BaseEditor { ~TileSheetEditorImGui() override = default; - ox::CStringView itemName() const noexcept override; - - ox::CStringView itemDisplayName() const noexcept override; - void exportFile() override; void cut() override; @@ -77,8 +71,6 @@ class TileSheetEditorImGui: public studio::BaseEditor { void drawSubsheetSelector(TileSheet::SubSheet*, TileSheet::SubSheetIdx *path); - studio::UndoStack *undoStack() noexcept final; - [[nodiscard]] static ox::Vec2 clickPos(ImVec2 const&winPos, ox::Vec2 clickPos) noexcept; diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp index d9b0daa5..6a47e5bc 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp @@ -29,12 +29,13 @@ const Palette TileSheetEditorModel::s_defaultPalette = { .colors = ox::Vector(128), }; -TileSheetEditorModel::TileSheetEditorModel(turbine::Context &ctx, ox::StringView path): +TileSheetEditorModel::TileSheetEditorModel(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack): m_ctx(ctx), m_path(path), m_img(*readObj(keelCtx(m_ctx), m_path).unwrapThrow()), // ignore failure to load palette - m_pal(readObj(keelCtx(m_ctx), m_img.defaultPalette).value) { + m_pal(readObj(keelCtx(m_ctx), m_img.defaultPalette).value), + m_undoStack(undoStack) { m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated); m_undoStack.changeTriggered.connect(this, &TileSheetEditorModel::markUpdatedCmdId); } diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.hpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.hpp index 69643a01..a3763bbc 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.hpp @@ -29,7 +29,7 @@ class TileSheetEditorModel: public ox::SignalHandler { TileSheet m_img; TileSheet::SubSheetIdx m_activeSubsSheetIdx; keel::AssetRef m_pal; - studio::UndoStack m_undoStack; + studio::UndoStack &m_undoStack; class DrawCommand *m_ongoingDrawCommand = nullptr; bool m_updated = false; bool m_selectionOngoing = false; @@ -37,7 +37,7 @@ class TileSheetEditorModel: public ox::SignalHandler { ox::Bounds m_selectionBounds = {{-1, -1}, {-1, -1}}; public: - TileSheetEditorModel(turbine::Context &ctx, ox::StringView path); + TileSheetEditorModel(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack); ~TileSheetEditorModel() override = default; diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.cpp index 65724a94..f1117c3d 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.cpp @@ -11,8 +11,8 @@ namespace nostalgia::core { -TileSheetEditorView::TileSheetEditorView(turbine::Context &ctx, ox::StringView path): - m_model(ctx, path), +TileSheetEditorView::TileSheetEditorView(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack): + m_model(ctx, path, undoStack), m_pixelsDrawer(&m_model) { // build shaders oxThrowError(m_pixelsDrawer.buildShader()); diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.hpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.hpp index 4de3fb6c..1642f58e 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.hpp @@ -50,7 +50,7 @@ class TileSheetEditorView: public ox::SignalHandler { std::size_t m_palIdx = 0; public: - TileSheetEditorView(turbine::Context &ctx, ox::StringView path); + TileSheetEditorView(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack); ~TileSheetEditorView() override = default; diff --git a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp index be6a165c..4d33fba6 100644 --- a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp +++ b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp @@ -49,8 +49,8 @@ void SceneEditorImGui::onActivated() noexcept { ox::Error SceneEditorImGui::saveItem() noexcept { const auto sctx = applicationData(m_ctx); - oxReturnError(sctx->project->writeObj(itemName(), m_editor.scene())); - oxReturnError(keelCtx(m_ctx).assetManager.setAsset(itemName(), m_editor.scene())); + oxReturnError(sctx->project->writeObj(itemPath(), m_editor.scene())); + oxReturnError(keelCtx(m_ctx).assetManager.setAsset(itemPath(), m_editor.scene())); return {}; } diff --git a/src/olympic/studio/applib/src/studioapp.cpp b/src/olympic/studio/applib/src/studioapp.cpp index f1aac408..e37ade3c 100644 --- a/src/olympic/studio/applib/src/studioapp.cpp +++ b/src/olympic/studio/applib/src/studioapp.cpp @@ -224,7 +224,7 @@ void StudioUI::drawTabs() noexcept { if (m_activeEditor != e.get()) { m_activeEditor = e.get(); studio::editConfig(keelCtx(m_ctx), [&](StudioConfig *config) { - config->activeTabItemName = m_activeEditor->itemName(); + config->activeTabItemName = m_activeEditor->itemPath(); }); } if (m_activeEditorUpdatePending == e.get()) { @@ -326,7 +326,7 @@ ox::Error StudioUI::openFile(ox::CRStringView path) noexcept { ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab) noexcept { if (m_openFiles.contains(path)) { for (auto &e : m_editors) { - if (makeActiveTab && e->itemName() == path) { + if (makeActiveTab && e->itemPath() == path) { m_activeEditor = e.get(); m_activeEditorUpdatePending = e.get(); break; diff --git a/src/olympic/studio/modlib/include/studio/editor.hpp b/src/olympic/studio/modlib/include/studio/editor.hpp index 4185c7a8..6d8702d6 100644 --- a/src/olympic/studio/modlib/include/studio/editor.hpp +++ b/src/olympic/studio/modlib/include/studio/editor.hpp @@ -32,7 +32,7 @@ class BaseEditor: public Widget { * Returns the name of item being edited. */ [[nodiscard]] - virtual ox::CStringView itemName() const noexcept = 0; + virtual ox::CStringView itemPath() const noexcept = 0; [[nodiscard]] virtual ox::CStringView itemDisplayName() const noexcept; @@ -98,11 +98,7 @@ class BaseEditor: public Widget { * Returns the undo stack holding changes to the item being edited. */ [[nodiscard]] - virtual UndoStack *undoStack() noexcept { - return nullptr; - } - - static ox::StringView pathToItemName(ox::CRStringView path) noexcept; + virtual UndoStack *undoStack() noexcept; void setRequiresConstantRefresh(bool value) noexcept; @@ -127,15 +123,16 @@ class Editor: public studio::BaseEditor { Editor(ox::StringView itemPath) noexcept; [[nodiscard]] - ox::CStringView itemName() const noexcept final; + ox::CStringView itemPath() const noexcept final; [[nodiscard]] ox::CStringView itemDisplayName() const noexcept final; + [[nodiscard]] UndoStack *undoStack() noexcept final; private: - ox::Error markUnsavedChanges(const UndoCommand*) noexcept; + ox::Error markUnsavedChanges(UndoCommand const*) noexcept; }; diff --git a/src/olympic/studio/modlib/src/editor.cpp b/src/olympic/studio/modlib/src/editor.cpp index b3f7149c..fc777c0f 100644 --- a/src/olympic/studio/modlib/src/editor.cpp +++ b/src/olympic/studio/modlib/src/editor.cpp @@ -11,7 +11,7 @@ namespace studio { ox::CStringView BaseEditor::itemDisplayName() const noexcept { - return itemName(); + return itemPath(); } void BaseEditor::cut() { @@ -37,7 +37,7 @@ bool BaseEditor::requiresConstantRefresh() const noexcept { } void BaseEditor::close() const { - this->closed.emit(itemName()); + this->closed.emit(itemPath()); } void BaseEditor::save() noexcept { @@ -46,9 +46,9 @@ void BaseEditor::save() noexcept { setUnsavedChanges(false); } else { if constexpr(ox::defines::Debug) { - oxErrorf("Could not save file {}: {} ({}:{})", itemName(), toStr(err), err.file, err.line); + oxErrorf("Could not save file {}: {} ({}:{})", itemPath(), toStr(err), err.file, err.line); } else { - oxErrorf("Could not save file {}: {}", itemName(), toStr(err)); + oxErrorf("Could not save file {}: {}", itemPath(), toStr(err)); } } } @@ -102,9 +102,8 @@ ox::Error BaseEditor::saveItem() noexcept { return OxError(0); } -ox::StringView BaseEditor::pathToItemName(ox::CRStringView path) noexcept { - const auto lastSlash = std::find(path.rbegin(), path.rend(), '/').offset(); - return substr(path, lastSlash + 1); +UndoStack *BaseEditor::undoStack() noexcept { + return nullptr; } void BaseEditor::setRequiresConstantRefresh(bool value) noexcept { @@ -119,7 +118,7 @@ Editor::Editor(ox::StringView itemPath) noexcept: } [[nodiscard]] -ox::CStringView Editor::itemName() const noexcept { +ox::CStringView Editor::itemPath() const noexcept { return m_itemPath; }