[nostalgia/studio] Get save working

This commit is contained in:
2022-02-19 01:45:37 -06:00
parent 5b7dacd51f
commit 56ec063658
12 changed files with 73 additions and 27 deletions
@@ -61,6 +61,12 @@ studio::UndoStack *TileSheetEditorImGui::undoStack() noexcept {
}
void TileSheetEditorImGui::saveItem() {
const auto err = m_tileSheetEditor.model()->saveFile();
if (!err) {
this->setUnsavedChanges(false);
} else {
oxErrorf("Could not save file {}: {}", m_itemPath, toStr(err));
}
}
void TileSheetEditorImGui::drawTileSheet(const geo::Vec2 &fbSize) noexcept {
@@ -76,6 +76,16 @@ class TileSheetEditor {
[[nodiscard]]
constexpr const Palette &pal() const noexcept;
[[nodiscard]]
constexpr auto *model() noexcept {
return &m_model;
}
[[nodiscard]]
constexpr auto *model() const noexcept {
return &m_model;
}
constexpr auto setPalIdx(auto palIdx) noexcept {
m_palIdx = palIdx;
}
@@ -2,6 +2,8 @@
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <ox/claw/write.hpp>
#include <nostalgia/core/media.hpp>
#include "tilesheeteditormodel.hpp"
@@ -9,6 +11,8 @@
namespace nostalgia::core {
TileSheetEditorModel::TileSheetEditorModel(Context *ctx, const ox::String &path) {
m_ctx = ctx;
m_path = path;
oxRequireT(img, readObj<TileSheet>(ctx, path.c_str()));
m_img = *img;
oxThrowError(readObj<Palette>(ctx, m_img.defaultPalette).moveTo(&m_pal));
@@ -46,6 +50,12 @@ void TileSheetEditorModel::ackUpdate() noexcept {
m_updated = false;
}
ox::Error TileSheetEditorModel::saveFile() noexcept {
oxRequire(buff, ox::writeClaw(&m_img));
oxReturnError(m_ctx->rom->write(m_path.c_str(), buff.data(), buff.size()));
return m_ctx->assetManager.setAsset(m_path, m_img).error;
}
void TileSheetEditorModel::getFillPixels(bool *pixels, const geo::Point &pt, int oldColor) const noexcept {
const auto tileIdx = [this](const geo::Point &pt) noexcept {
return ptToIdx(pt, img().columns()) / PixelsPerTile;
@@ -119,6 +119,8 @@ class TileSheetEditorModel {
studio::UndoStack m_undoStack;
DrawCommand *m_ongoingDrawCommand = nullptr;
bool m_updated = false;
Context *m_ctx = nullptr;
ox::String m_path;
public:
TileSheetEditorModel(Context *ctx, const ox::String &path);
@@ -149,6 +151,8 @@ class TileSheetEditorModel {
void ackUpdate() noexcept;
ox::Error saveFile() noexcept;
constexpr studio::UndoStack *undoStack() noexcept {
return &m_undoStack;
}