From 124c7029bda328e9ddc208b00e53a2e6452f2ede Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 20 Jan 2024 15:40:08 -0600 Subject: [PATCH] [olympic/studio] Change Studio modules to pass StudioContext instead of turbine::Context --- .../src/studio/paletteeditor/paletteeditor-imgui.cpp | 4 ++-- .../src/studio/paletteeditor/paletteeditor-imgui.hpp | 2 +- src/nostalgia/modules/core/src/studio/studiomodule.cpp | 4 ++-- .../src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp | 4 ++-- .../src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp | 2 +- .../modules/scene/src/studio/sceneeditor-imgui.cpp | 4 ++-- .../modules/scene/src/studio/sceneeditor-imgui.hpp | 2 +- src/nostalgia/modules/scene/src/studio/studiomodule.cpp | 4 ++-- src/olympic/studio/applib/src/main.cpp | 2 +- src/olympic/studio/applib/src/studioapp.cpp | 9 +++++---- src/olympic/studio/applib/src/studioapp.hpp | 3 ++- src/olympic/studio/modlib/include/studio/module.hpp | 6 +++--- src/olympic/studio/modlib/src/module.cpp | 4 ++-- 13 files changed, 26 insertions(+), 24 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 7bdd1974..baf95e27 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp @@ -15,9 +15,9 @@ namespace nostalgia::core { -PaletteEditorImGui::PaletteEditorImGui(turbine::Context &ctx, ox::CRStringView path): +PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &ctx, ox::CRStringView path): Editor(path), - m_ctx(ctx), + m_ctx(ctx.tctx), m_pal(*keel::readObj(keelCtx(m_ctx), ox::FileAddress(itemPath())).unwrapThrow()) { undoStack()->changeTriggered.connect(this, &PaletteEditorImGui::handleCommand); } 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 20c84dc4..a683bdc0 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp @@ -20,7 +20,7 @@ class PaletteEditorImGui: public studio::Editor { size_t m_page = 0; public: - PaletteEditorImGui(turbine::Context &ctx, ox::CRStringView path); + PaletteEditorImGui(studio::StudioContext &ctx, ox::CRStringView path); void keyStateChanged(turbine::Key key, bool down) override; diff --git a/src/nostalgia/modules/core/src/studio/studiomodule.cpp b/src/nostalgia/modules/core/src/studio/studiomodule.cpp index 6f3d8b70..10c76100 100644 --- a/src/nostalgia/modules/core/src/studio/studiomodule.cpp +++ b/src/nostalgia/modules/core/src/studio/studiomodule.cpp @@ -12,14 +12,14 @@ namespace nostalgia::core { class StudioModule: public studio::Module { - ox::Vector editors(turbine::Context &ctx) const noexcept final { + ox::Vector editors(studio::StudioContext &ctx) const noexcept final { return { studio::editorMaker(ctx, FileExt_ng), studio::editorMaker(ctx, FileExt_npal), }; } - ox::Vector> itemMakers(turbine::Context&) const noexcept final { + ox::Vector> itemMakers(studio::StudioContext&) const noexcept final { ox::Vector> out; out.emplace_back(ox::make>("Tile Sheet", "TileSheets", FileExt_ng)); out.emplace_back(ox::make>("Palette", "Palettes", FileExt_npal)); 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 22d4dc40..1abaec74 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp @@ -75,9 +75,9 @@ static ox::Error toPngFile( 8))); } -TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context &ctx, ox::CRStringView path): +TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &ctx, ox::CRStringView path): Editor(path), - m_ctx(ctx), + m_ctx(ctx.tctx), m_view(m_ctx, path, *undoStack()), m_model(m_view.model()) { oxIgnoreError(setPaletteSelection()); 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 70b3eda5..26d0c4df 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp @@ -73,7 +73,7 @@ class TileSheetEditorImGui: public studio::Editor { Tool m_tool = Tool::Draw; public: - TileSheetEditorImGui(turbine::Context &ctx, ox::CRStringView path); + TileSheetEditorImGui(studio::StudioContext &ctx, ox::CRStringView path); ~TileSheetEditorImGui() 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 1b494fe8..83dd413d 100644 --- a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp +++ b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp @@ -10,9 +10,9 @@ namespace nostalgia::scene { -SceneEditorImGui::SceneEditorImGui(turbine::Context &ctx, ox::StringView path): +SceneEditorImGui::SceneEditorImGui(studio::StudioContext &ctx, ox::StringView path): Editor(path), - m_ctx(ctx), + m_ctx(ctx.tctx), m_editor(m_ctx, path), m_view(m_ctx, m_editor.scene()) { setRequiresConstantRefresh(false); diff --git a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp index 016805f0..0508f424 100644 --- a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp +++ b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp @@ -21,7 +21,7 @@ class SceneEditorImGui: public studio::Editor { SceneEditorView m_view; public: - SceneEditorImGui(turbine::Context &ctx, ox::StringView path); + SceneEditorImGui(studio::StudioContext &ctx, ox::StringView path); void draw(turbine::Context&) noexcept final; diff --git a/src/nostalgia/modules/scene/src/studio/studiomodule.cpp b/src/nostalgia/modules/scene/src/studio/studiomodule.cpp index b1eedf60..eb840adf 100644 --- a/src/nostalgia/modules/scene/src/studio/studiomodule.cpp +++ b/src/nostalgia/modules/scene/src/studio/studiomodule.cpp @@ -12,12 +12,12 @@ constexpr ox::StringLiteral FileExt_nscn("nscn"); class StudioModule: public studio::Module { public: - ox::Vector editors(turbine::Context &ctx) const noexcept override { + ox::Vector editors(studio::StudioContext &ctx) const noexcept override { return { studio::editorMaker(ctx, FileExt_nscn), }; } - ox::Vector> itemMakers(turbine::Context&) const noexcept override { + ox::Vector> itemMakers(studio::StudioContext&) const noexcept override { ox::Vector> out; return out; } diff --git a/src/olympic/studio/applib/src/main.cpp b/src/olympic/studio/applib/src/main.cpp index 135186ac..fd4bb60b 100644 --- a/src/olympic/studio/applib/src/main.cpp +++ b/src/olympic/studio/applib/src/main.cpp @@ -50,7 +50,7 @@ static ox::Error runApp( turbine::setConstantRefresh(*ctx, false); studio::StudioContext studioCtx(*ctx); turbine::setApplicationData(*ctx, &studioCtx); - StudioUI ui(*ctx, projectDataDir); + StudioUI ui(studioCtx, projectDataDir); studioCtx.ui = &ui; StudioUIDrawer drawer(ui); turbine::gl::addDrawer(*ctx, &drawer); diff --git a/src/olympic/studio/applib/src/studioapp.cpp b/src/olympic/studio/applib/src/studioapp.cpp index e5e139b9..c97b0771 100644 --- a/src/olympic/studio/applib/src/studioapp.cpp +++ b/src/olympic/studio/applib/src/studioapp.cpp @@ -40,8 +40,9 @@ oxModelBegin(StudioConfig) oxModelFieldRename(show_project_explorer, showProjectExplorer) oxModelEnd() -StudioUI::StudioUI(turbine::Context &ctx, ox::StringView projectDataDir) noexcept: - m_ctx(ctx), +StudioUI::StudioUI(studio::StudioContext &ctx, ox::StringView projectDataDir) noexcept: + m_sctx(ctx), + m_ctx(ctx.tctx), m_projectDataDir(projectDataDir), m_projectExplorer(m_ctx), m_newProject(ox::String(projectDataDir)), @@ -288,10 +289,10 @@ void StudioUI::loadEditorMaker(studio::EditorMaker const&editorMaker) noexcept { } void StudioUI::loadModule(studio::Module const*mod) noexcept { - for (auto const&editorMaker : mod->editors(m_ctx)) { + for (auto const&editorMaker : mod->editors(m_sctx)) { loadEditorMaker(editorMaker); } - for (auto &im : mod->itemMakers(m_ctx)) { + for (auto &im : mod->itemMakers(m_sctx)) { m_newMenu.addItemMaker(std::move(im)); } } diff --git a/src/olympic/studio/applib/src/studioapp.hpp b/src/olympic/studio/applib/src/studioapp.hpp index 556f036e..25d3c740 100644 --- a/src/olympic/studio/applib/src/studioapp.hpp +++ b/src/olympic/studio/applib/src/studioapp.hpp @@ -24,6 +24,7 @@ class StudioUI: public ox::SignalHandler { friend class StudioUIDrawer; private: + studio::StudioContext &m_sctx; turbine::Context &m_ctx; ox::String m_projectDataDir; ox::UPtr m_project; @@ -47,7 +48,7 @@ class StudioUI: public ox::SignalHandler { bool m_showProjectExplorer = true; public: - explicit StudioUI(turbine::Context &ctx, ox::StringView projectDataDir) noexcept; + explicit StudioUI(studio::StudioContext &ctx, ox::StringView projectDataDir) noexcept; void update() noexcept; diff --git a/src/olympic/studio/modlib/include/studio/module.hpp b/src/olympic/studio/modlib/include/studio/module.hpp index 775b18d3..778bf520 100644 --- a/src/olympic/studio/modlib/include/studio/module.hpp +++ b/src/olympic/studio/modlib/include/studio/module.hpp @@ -27,15 +27,15 @@ class Module { public: virtual ~Module() noexcept = default; - virtual ox::Vector editors(turbine::Context &ctx) const; + virtual ox::Vector editors(studio::StudioContext &ctx) const; - virtual ox::Vector> itemMakers(turbine::Context&) const; + virtual ox::Vector> itemMakers(studio::StudioContext&) const; }; template [[nodiscard]] -studio::EditorMaker editorMaker(turbine::Context &ctx, ox::CRStringView ext) noexcept { +studio::EditorMaker editorMaker(studio::StudioContext &ctx, ox::CRStringView ext) noexcept { return { {ox::String(ext)}, [&ctx](ox::CRStringView path) -> ox::Result { diff --git a/src/olympic/studio/modlib/src/module.cpp b/src/olympic/studio/modlib/src/module.cpp index be292c7d..c26acbd5 100644 --- a/src/olympic/studio/modlib/src/module.cpp +++ b/src/olympic/studio/modlib/src/module.cpp @@ -6,11 +6,11 @@ namespace studio { -ox::Vector Module::editors(turbine::Context&) const { +ox::Vector Module::editors(studio::StudioContext&) const { return {}; } -ox::Vector> Module::itemMakers(turbine::Context&) const { +ox::Vector> Module::itemMakers(studio::StudioContext&) const { return {}; }