From a4f0c7cdb515f13b33d0ad5c9a7ebda97ea34186 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 23 Mar 2024 14:52:30 -0500 Subject: [PATCH] [nostalgia/core/studio] Remove applicationData usages --- .../paletteeditor/paletteeditor-imgui.cpp | 14 +++++------ .../paletteeditor/paletteeditor-imgui.hpp | 5 ++-- .../tilesheeteditor/tilesheeteditor-imgui.cpp | 23 +++++++++--------- .../tilesheeteditor/tilesheeteditor-imgui.hpp | 5 ++-- .../tilesheeteditor/tilesheeteditormodel.cpp | 24 +++++++++---------- .../tilesheeteditor/tilesheeteditormodel.hpp | 5 ++-- .../tilesheeteditor/tilesheeteditorview.cpp | 4 ++-- .../tilesheeteditor/tilesheeteditorview.hpp | 2 +- 8 files changed, 42 insertions(+), 40 deletions(-) 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 baf95e27..832d3545 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp @@ -15,10 +15,11 @@ namespace nostalgia::core { -PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &ctx, ox::CRStringView path): +PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::CRStringView path): Editor(path), - m_ctx(ctx.tctx), - m_pal(*keel::readObj(keelCtx(m_ctx), ox::FileAddress(itemPath())).unwrapThrow()) { + m_sctx(sctx), + m_tctx(sctx.tctx), + m_pal(*keel::readObj(keelCtx(m_tctx), ox::FileAddress(itemPath())).unwrapThrow()) { undoStack()->changeTriggered.connect(this, &PaletteEditorImGui::handleCommand); } @@ -27,12 +28,12 @@ void PaletteEditorImGui::keyStateChanged(turbine::Key key, bool down) { return; } if (key >= turbine::Key::Num_1 && key <= turbine::Key::Num_9) { - if (turbine::buttonDown(m_ctx, turbine::Key::Mod_Alt)) { + if (turbine::buttonDown(m_tctx, turbine::Key::Mod_Alt)) { m_page = ox::min( static_cast(key - turbine::Key::Num_1), m_pal.pages.size() - 1); } } else if (key == turbine::Key::Num_0) { - if (turbine::buttonDown(m_ctx, turbine::Key::Mod_Alt)) { + if (turbine::buttonDown(m_tctx, turbine::Key::Mod_Alt)) { m_selectedColorRow = ox::min( static_cast(key - turbine::Key::Num_1 + 9), m_pal.pages.size() - 1); @@ -57,8 +58,7 @@ void PaletteEditorImGui::draw(turbine::Context&) noexcept { } ox::Error PaletteEditorImGui::saveItem() noexcept { - const auto sctx = applicationData(m_ctx); - return sctx->project->writeObj(itemPath(), m_pal); + return m_sctx.project->writeObj(itemPath(), m_pal); } void PaletteEditorImGui::drawColumn(ox::CStringView txt) noexcept { 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 a683bdc0..8f022467 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp @@ -14,13 +14,14 @@ namespace nostalgia::core { class PaletteEditorImGui: public studio::Editor { private: - turbine::Context &m_ctx; + studio::StudioContext &m_sctx; + turbine::Context &m_tctx; Palette m_pal; size_t m_selectedColorRow = 0; size_t m_page = 0; public: - PaletteEditorImGui(studio::StudioContext &ctx, ox::CRStringView path); + PaletteEditorImGui(studio::StudioContext &sctx, ox::CRStringView path); void keyStateChanged(turbine::Key key, bool down) override; 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 1abaec74..faabe8a0 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp @@ -75,10 +75,11 @@ static ox::Error toPngFile( 8))); } -TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &ctx, ox::CRStringView path): +TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::CRStringView path): Editor(path), - m_ctx(ctx.tctx), - m_view(m_ctx, path, *undoStack()), + m_sctx(sctx), + m_tctx(m_sctx.tctx), + m_view(m_sctx, path, *undoStack()), m_model(m_view.model()) { oxIgnoreError(setPaletteSelection()); // connect signal/slots @@ -134,7 +135,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) { setPasteEnabled(false); m_model.clearSelection(); } else if (key >= turbine::Key::Num_1 && key <= turbine::Key::Num_9) { - if (turbine::buttonDown(m_ctx, turbine::Key::Mod_Alt)) { + if (turbine::buttonDown(m_tctx, turbine::Key::Mod_Alt)) { auto const idx = ox::min( static_cast(key - turbine::Key::Num_1), m_model.pal().pages.size() - 1); m_model.setPalettePage(idx); @@ -143,7 +144,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) { m_view.setPalIdx(idx); } } else if (key == turbine::Key::Num_0) { - if (turbine::buttonDown(m_ctx, turbine::Key::Mod_Alt)) { + if (turbine::buttonDown(m_tctx, turbine::Key::Mod_Alt)) { auto const idx = ox::min( static_cast(key - turbine::Key::Num_1 + 9), m_model.pal().pages.size() - 1); m_model.setPalettePage(idx); @@ -235,8 +236,8 @@ void TileSheetEditorImGui::draw(turbine::Context&) noexcept { ImGui::EndChild(); } ImGui::EndChild(); - m_subsheetEditor.draw(m_ctx); - m_exportMenu.draw(m_ctx); + m_subsheetEditor.draw(m_tctx); + m_exportMenu.draw(m_tctx); } void TileSheetEditorImGui::drawSubsheetSelector( @@ -359,7 +360,7 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept { auto const wheelh = io.MouseWheelH; if (wheel != 0) { const auto zoomMod = ox::defines::OS == ox::OS::Darwin ? - io.KeySuper : turbine::buttonDown(m_ctx, turbine::Key::Mod_Ctrl); + io.KeySuper : turbine::buttonDown(m_tctx, turbine::Key::Mod_Ctrl); m_view.scrollV(fbSize, wheel, zoomMod); } if (wheelh != 0) { @@ -399,8 +400,7 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept { } void TileSheetEditorImGui::drawPaletteSelector() noexcept { - auto &sctx = *applicationData(m_ctx); - auto const&files = sctx.project->fileList(core::FileExt_npal); + auto const&files = m_sctx.project->fileList(core::FileExt_npal); auto const comboWidthSub = 62; ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - comboWidthSub); if (ig::ComboBox("Palette", files, m_selectedPaletteIdx)) { @@ -465,8 +465,7 @@ ox::Error TileSheetEditorImGui::updateActiveSubsheet(ox::StringView const&name, ox::Error TileSheetEditorImGui::setPaletteSelection() noexcept { auto const&palPath = m_model.palPath(); - auto &sctx = *applicationData(m_ctx); - auto const&palList = sctx.project->fileList(core::FileExt_npal); + auto const&palList = m_sctx.project->fileList(core::FileExt_npal); for (std::size_t i = 0; auto const&pal : palList) { if (palPath == pal) { m_selectedPaletteIdx = i; 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 26d0c4df..529bba9a 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp @@ -61,7 +61,8 @@ class TileSheetEditorImGui: public studio::Editor { inline bool isOpen() const noexcept { return m_show; } }; std::size_t m_selectedPaletteIdx = 0; - turbine::Context &m_ctx; + studio::StudioContext &m_sctx; + turbine::Context &m_tctx; ox::Vector m_paletteList; SubSheetEditor m_subsheetEditor; ExportMenu m_exportMenu; @@ -73,7 +74,7 @@ class TileSheetEditorImGui: public studio::Editor { Tool m_tool = Tool::Draw; public: - TileSheetEditorImGui(studio::StudioContext &ctx, ox::CRStringView path); + TileSheetEditorImGui(studio::StudioContext &sctx, ox::CRStringView path); ~TileSheetEditorImGui() override = default; diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp index 7694efa9..d5348252 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp @@ -41,12 +41,13 @@ static void normalizeSubsheets(TileSheet::SubSheet &ss) noexcept { } } -TileSheetEditorModel::TileSheetEditorModel(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack): - m_ctx(ctx), +TileSheetEditorModel::TileSheetEditorModel(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack): + m_sctx(sctx), + m_tctx(m_sctx.tctx), m_path(path), - m_img(*readObj(keelCtx(m_ctx), m_path).unwrapThrow()), + m_img(*readObj(keelCtx(m_tctx), m_path).unwrapThrow()), // ignore failure to load palette - m_pal(readObj(keelCtx(m_ctx), m_img.defaultPalette).value), + m_pal(readObj(keelCtx(m_tctx), m_img.defaultPalette).value), m_undoStack(undoStack) { normalizeSubsheets(m_img.subsheet); m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated); @@ -70,7 +71,7 @@ void TileSheetEditorModel::cut() { } const auto pt1 = m_selectionOrigin == ox::Point(-1, -1) ? ox::Point(0, 0) : m_selectionOrigin; const auto pt2 = ox::Point(s.columns * TileWidth, s.rows * TileHeight); - turbine::setClipboardObject(m_ctx, std::move(cb)); + turbine::setClipboardObject(m_tctx, std::move(cb)); pushCommand(ox::make(CommandId::Cut, m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb)); } @@ -87,11 +88,11 @@ void TileSheetEditorModel::copy() { cb->addPixel(pt, c); } } - turbine::setClipboardObject(m_ctx, std::move(cb)); + turbine::setClipboardObject(m_tctx, std::move(cb)); } void TileSheetEditorModel::paste() { - auto [cb, err] = turbine::getClipboardObject(m_ctx); + auto [cb, err] = turbine::getClipboardObject(m_tctx); if (err) { oxLogError(err); oxErrf("Could not read clipboard: {}", toStr(err)); @@ -111,7 +112,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept { constexpr ox::StringView uuidPrefix = "uuid://"; if (ox::beginsWith(path, uuidPrefix)) { auto uuid = ox::StringView(path.data() + uuidPrefix.bytes(), path.bytes() - uuidPrefix.bytes()); - auto out = keelCtx(m_ctx).uuidToPath.at(uuid); + auto out = keelCtx(m_tctx).uuidToPath.at(uuid); if (out.error) { return {}; } @@ -122,7 +123,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept { } ox::Error TileSheetEditorModel::setPalette(ox::StringView path) noexcept { - oxRequire(uuid, keelCtx(m_ctx).pathToUuid.at(path)); + oxRequire(uuid, keelCtx(m_tctx).pathToUuid.at(path)); pushCommand(ox::make(activeSubSheetIdx(), m_img, uuid->toString())); return {}; } @@ -239,7 +240,7 @@ ox::Error TileSheetEditorModel::markUpdatedCmdId(studio::UndoCommand const*cmd) m_updated = true; const auto cmdId = cmd->commandId(); if (static_cast(cmdId) == CommandId::PaletteChange) { - oxReturnError(readObj(keelCtx(m_ctx), m_img.defaultPalette).moveTo(m_pal)); + oxReturnError(readObj(keelCtx(m_tctx), m_img.defaultPalette).moveTo(m_pal)); m_palettePage = ox::min(m_pal->pages.size(), 0); paletteChanged.emit(); } @@ -261,8 +262,7 @@ void TileSheetEditorModel::ackUpdate() noexcept { } ox::Error TileSheetEditorModel::saveFile() noexcept { - const auto sctx = applicationData(m_ctx); - return sctx->project->writeObj(m_path, m_img, ox::ClawFormat::Metal); + return m_sctx.project->writeObj(m_path, m_img, ox::ClawFormat::Metal); } bool TileSheetEditorModel::pixelSelected(std::size_t idx) const noexcept { diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.hpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.hpp index 361d2006..f4fe90e5 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.hpp @@ -24,7 +24,8 @@ class TileSheetEditorModel: public ox::SignalHandler { private: static Palette const s_defaultPalette; - turbine::Context &m_ctx; + studio::StudioContext &m_sctx; + turbine::Context &m_tctx; ox::String m_path; TileSheet m_img; TileSheet::SubSheetIdx m_activeSubsSheetIdx; @@ -38,7 +39,7 @@ class TileSheetEditorModel: public ox::SignalHandler { ox::Bounds m_selectionBounds = {{-1, -1}, {-1, -1}}; public: - TileSheetEditorModel(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack); + TileSheetEditorModel(studio::StudioContext &sctx, 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 b9f4ec8e..ec618a5f 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, studio::UndoStack &undoStack): - m_model(ctx, path, undoStack), +TileSheetEditorView::TileSheetEditorView(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack): + m_model(sctx, 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 52ef3028..d421237d 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, studio::UndoStack &undoStack); + TileSheetEditorView(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack); ~TileSheetEditorView() override = default;