[olympic,nostalgia] Move item name/path studio::Editor
This commit is contained in:
parent
d056323679
commit
1b93b2038f
@ -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<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;
|
||||
m_pal(*keel::readObj<Palette>(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<studio::StudioContext>(m_ctx);
|
||||
return sctx->project->writeObj(m_itemPath, m_pal);
|
||||
return sctx->project->writeObj(itemName(), m_pal);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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<int>(paneSize.x), static_cast<int>(paneSize.y)});
|
||||
@ -59,8 +49,8 @@ void SceneEditorImGui::onActivated() noexcept {
|
||||
|
||||
ox::Error SceneEditorImGui::saveItem() noexcept {
|
||||
const auto sctx = applicationData<studio::StudioContext>(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 {};
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
|
@ -14,19 +14,10 @@ namespace studio {
|
||||
class ClawEditor: public studio::Editor {
|
||||
private:
|
||||
using ObjPath = ox::Vector<ox::StringView, 8>;
|
||||
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:
|
||||
|
@ -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;
|
||||
|
@ -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 {};
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user