[olympic/studio,nostalgia] Change Editor item name to item path, make

TileSheetEditorImGui inherit from Editor
This commit is contained in:
2023-12-13 23:15:53 -06:00
parent 960889749d
commit 819e93bb1c
11 changed files with 29 additions and 54 deletions

View File

@@ -18,7 +18,7 @@ namespace nostalgia::core {
PaletteEditorImGui::PaletteEditorImGui(turbine::Context &ctx, ox::CRStringView path):
Editor(path),
m_ctx(ctx),
m_pal(*keel::readObj<Palette>(keelCtx(m_ctx), ox::FileAddress(itemName())).unwrapThrow()) {
m_pal(*keel::readObj<Palette>(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<studio::StudioContext>(m_ctx);
return sctx->project->writeObj(itemName(), m_pal);
return sctx->project->writeObj(itemPath(), m_pal);
}
}

View File

@@ -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;

View File

@@ -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<ox::String> 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;

View File

@@ -29,12 +29,13 @@ const Palette TileSheetEditorModel::s_defaultPalette = {
.colors = ox::Vector<Color16>(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<TileSheet>(keelCtx(m_ctx), m_path).unwrapThrow()),
// ignore failure to load palette
m_pal(readObj<Palette>(keelCtx(m_ctx), m_img.defaultPalette).value) {
m_pal(readObj<Palette>(keelCtx(m_ctx), m_img.defaultPalette).value),
m_undoStack(undoStack) {
m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated);
m_undoStack.changeTriggered.connect(this, &TileSheetEditorModel::markUpdatedCmdId);
}

View File

@@ -29,7 +29,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
TileSheet m_img;
TileSheet::SubSheetIdx m_activeSubsSheetIdx;
keel::AssetRef<Palette> 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;

View File

@@ -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());

View File

@@ -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;