[olympic,nostalgia] Move item name/path studio::Editor

This commit is contained in:
Gary Talent 2023-12-12 23:06:14 -06:00
parent d056323679
commit 1b93b2038f
8 changed files with 37 additions and 70 deletions

View File

@ -16,18 +16,9 @@
namespace nostalgia::core { namespace nostalgia::core {
PaletteEditorImGui::PaletteEditorImGui(turbine::Context &ctx, ox::CRStringView path): PaletteEditorImGui::PaletteEditorImGui(turbine::Context &ctx, ox::CRStringView path):
Editor(path),
m_ctx(ctx), m_ctx(ctx),
m_itemPath(path), m_pal(*keel::readObj<Palette>(keelCtx(m_ctx), ox::FileAddress(itemName())).unwrapThrow()) {
m_itemName(m_itemPath.substr(std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset() + 1)),
m_pal(*keel::readObj<Palette>(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;
} }
void PaletteEditorImGui::draw(turbine::Context&) noexcept { void PaletteEditorImGui::draw(turbine::Context&) noexcept {
@ -140,7 +131,7 @@ void PaletteEditorImGui::draw(turbine::Context&) noexcept {
ox::Error PaletteEditorImGui::saveItem() noexcept { ox::Error PaletteEditorImGui::saveItem() noexcept {
const auto sctx = applicationData<studio::StudioContext>(m_ctx); const auto sctx = applicationData<studio::StudioContext>(m_ctx);
return sctx->project->writeObj(m_itemPath, m_pal); return sctx->project->writeObj(itemName(), m_pal);
} }
} }

View File

@ -15,21 +15,12 @@ class PaletteEditorImGui: public studio::Editor {
private: private:
turbine::Context &m_ctx; turbine::Context &m_ctx;
ox::String m_itemPath;
ox::String m_itemName;
Palette m_pal; Palette m_pal;
std::size_t m_selectedRow = 0; std::size_t m_selectedRow = 0;
public: public:
PaletteEditorImGui(turbine::Context &ctx, ox::CRStringView path); 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; void draw(turbine::Context&) noexcept final;
protected: protected:

View File

@ -11,23 +11,13 @@
namespace nostalgia::scene { namespace nostalgia::scene {
SceneEditorImGui::SceneEditorImGui(turbine::Context &ctx, ox::StringView path): SceneEditorImGui::SceneEditorImGui(turbine::Context &ctx, ox::StringView path):
Editor(path),
m_ctx(ctx), m_ctx(ctx),
m_itemPath(path), m_editor(m_ctx, path),
m_editor(m_ctx, m_itemPath),
m_view(m_ctx, m_editor.scene()) { 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); 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 { void SceneEditorImGui::draw(turbine::Context&) noexcept {
auto const paneSize = ImGui::GetContentRegionAvail(); auto const paneSize = ImGui::GetContentRegionAvail();
m_view.draw(ox::Size{static_cast<int>(paneSize.x), static_cast<int>(paneSize.y)}); m_view.draw(ox::Size{static_cast<int>(paneSize.x), static_cast<int>(paneSize.y)});
@ -59,8 +49,8 @@ void SceneEditorImGui::onActivated() noexcept {
ox::Error SceneEditorImGui::saveItem() noexcept { ox::Error SceneEditorImGui::saveItem() noexcept {
const auto sctx = applicationData<studio::StudioContext>(m_ctx); const auto sctx = applicationData<studio::StudioContext>(m_ctx);
oxReturnError(sctx->project->writeObj(m_itemPath, m_editor.scene())); oxReturnError(sctx->project->writeObj(itemName(), m_editor.scene()));
oxReturnError(keelCtx(m_ctx).assetManager.setAsset(m_itemPath, m_editor.scene())); oxReturnError(keelCtx(m_ctx).assetManager.setAsset(itemName(), m_editor.scene()));
return {}; return {};
} }

View File

@ -17,21 +17,12 @@ class SceneEditorImGui: public studio::Editor {
private: private:
turbine::Context &m_ctx; turbine::Context &m_ctx;
ox::String m_itemName;
ox::String m_itemPath;
SceneEditor m_editor; SceneEditor m_editor;
SceneEditorView m_view; SceneEditorView m_view;
public: public:
SceneEditorImGui(turbine::Context &ctx, ox::StringView path); 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 draw(turbine::Context&) noexcept final;
void onActivated() noexcept override; void onActivated() noexcept override;

View File

@ -9,19 +9,10 @@
namespace studio { namespace studio {
ClawEditor::ClawEditor(ox::CRStringView path, ox::ModelObject obj) noexcept: ClawEditor::ClawEditor(ox::CRStringView path, ox::ModelObject obj) noexcept:
m_itemName(path), Editor(path),
m_itemDisplayName(pathToItemName(path)),
m_obj(std::move(obj)) { 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 { void ClawEditor::draw(turbine::Context&) noexcept {
//const auto paneSize = ImGui::GetContentRegionAvail(); //const auto paneSize = ImGui::GetContentRegionAvail();
ImGui::BeginChild("PaletteEditor"); ImGui::BeginChild("PaletteEditor");

View File

@ -14,19 +14,10 @@ namespace studio {
class ClawEditor: public studio::Editor { class ClawEditor: public studio::Editor {
private: private:
using ObjPath = ox::Vector<ox::StringView, 8>; using ObjPath = ox::Vector<ox::StringView, 8>;
ox::String m_itemName;
ox::String m_itemDisplayName;
ox::ModelObject m_obj; ox::ModelObject m_obj;
public: public:
ClawEditor(ox::CRStringView path, ox::ModelObject obj) noexcept; 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; void draw(turbine::Context&) noexcept final;
private: private:

View File

@ -120,13 +120,19 @@ class BaseEditor: public Widget {
class Editor: public studio::BaseEditor { class Editor: public studio::BaseEditor {
private: private:
studio::UndoStack m_undoStack; studio::UndoStack m_undoStack;
ox::String m_itemPath;
ox::String m_itemName;
public: public:
Editor() noexcept; Editor(ox::StringView itemPath) noexcept;
UndoStack *undoStack() noexcept final { [[nodiscard]]
return &m_undoStack; ox::CStringView itemName() const noexcept final;
}
[[nodiscard]]
ox::CStringView itemDisplayName() const noexcept final;
UndoStack *undoStack() noexcept final;
private: private:
ox::Error markUnsavedChanges(const UndoCommand*) noexcept; ox::Error markUnsavedChanges(const UndoCommand*) noexcept;

View File

@ -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); 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); setUnsavedChanges(true);
return OxError(0); return {};
} }
} }