[nostalgia/gfx/studio/tilesheeteditor] Rework system for tracking current palette path
All checks were successful
Build / build (push) Successful in 3m29s
All checks were successful
Build / build (push) Successful in 3m29s
This commit is contained in:
parent
cfa91d3d39
commit
f840240aac
@ -70,8 +70,8 @@ static ox::Error toPngFile(
|
|||||||
ox::Vector<uint32_t> &&pixels,
|
ox::Vector<uint32_t> &&pixels,
|
||||||
Palette const&pal,
|
Palette const&pal,
|
||||||
size_t page,
|
size_t page,
|
||||||
unsigned width,
|
unsigned const width,
|
||||||
unsigned height) noexcept {
|
unsigned const height) noexcept {
|
||||||
for (auto &c : pixels) {
|
for (auto &c : pixels) {
|
||||||
c = color32(color(pal, page, c)) | static_cast<Color32>(0XFF << 24);
|
c = color32(color(pal, page, c)) | static_cast<Color32>(0XFF << 24);
|
||||||
}
|
}
|
||||||
@ -96,7 +96,6 @@ TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::Stri
|
|||||||
// connect signal/slots
|
// connect signal/slots
|
||||||
m_subsheetEditor.inputSubmitted.connect(this, &TileSheetEditorImGui::updateActiveSubsheet);
|
m_subsheetEditor.inputSubmitted.connect(this, &TileSheetEditorImGui::updateActiveSubsheet);
|
||||||
m_exportMenu.inputSubmitted.connect(this, &TileSheetEditorImGui::exportSubhseetToPng);
|
m_exportMenu.inputSubmitted.connect(this, &TileSheetEditorImGui::exportSubhseetToPng);
|
||||||
m_model.paletteChanged.connect(this, &TileSheetEditorImGui::setPaletteSelection);
|
|
||||||
// load config
|
// load config
|
||||||
auto const&config = studio::readConfig<TileSheetEditorConfig>(
|
auto const&config = studio::readConfig<TileSheetEditorConfig>(
|
||||||
keelCtx(m_sctx), itemPath());
|
keelCtx(m_sctx), itemPath());
|
||||||
@ -125,7 +124,7 @@ bool TileSheetEditorImGui::acceptsClipboardPayload() const noexcept {
|
|||||||
return m_model.acceptsClipboardPayload();
|
return m_model.acceptsClipboardPayload();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) {
|
void TileSheetEditorImGui::keyStateChanged(turbine::Key const key, bool const down) {
|
||||||
if (!down) {
|
if (!down) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -526,14 +525,11 @@ void TileSheetEditorImGui::drawPaletteMenu() noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error TileSheetEditorImGui::updateActiveSubsheet(ox::StringView const&name, int cols, int rows) noexcept {
|
ox::Error TileSheetEditorImGui::updateActiveSubsheet(
|
||||||
|
ox::StringView const&name, int const cols, int const rows) noexcept {
|
||||||
return m_model.updateSubsheet(m_model.activeSubSheetIdx(), name, cols, rows);
|
return m_model.updateSubsheet(m_model.activeSubSheetIdx(), name, cols, rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error TileSheetEditorImGui::setPaletteSelection() noexcept {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
void TileSheetEditorImGui::setActiveSubsheet(TileSheet::SubSheetIdx path) noexcept {
|
void TileSheetEditorImGui::setActiveSubsheet(TileSheet::SubSheetIdx path) noexcept {
|
||||||
m_model.setActiveSubsheet(path);
|
m_model.setActiveSubsheet(path);
|
||||||
studio::editConfig<TileSheetEditorConfig>(keelCtx(m_sctx), itemPath(),
|
studio::editConfig<TileSheetEditorConfig>(keelCtx(m_sctx), itemPath(),
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ox/model/def.hpp>
|
|
||||||
#include <ox/std/vec.hpp>
|
#include <ox/std/vec.hpp>
|
||||||
|
|
||||||
#include <glutils/glutils.hpp>
|
#include <glutils/glutils.hpp>
|
||||||
@ -29,7 +28,7 @@ class TileSheetEditorImGui: public studio::Editor {
|
|||||||
public:
|
public:
|
||||||
ox::Signal<ox::Error(ox::StringViewCR name, int cols, int rows)> inputSubmitted;
|
ox::Signal<ox::Error(ox::StringViewCR name, int cols, int rows)> inputSubmitted;
|
||||||
void show(ox::StringViewCR name, int cols, int rows) noexcept;
|
void show(ox::StringViewCR name, int cols, int rows) noexcept;
|
||||||
void draw(turbine::Context &sctx) noexcept;
|
void draw(turbine::Context &tctx) noexcept;
|
||||||
void close() noexcept;
|
void close() noexcept;
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr bool isOpen() const noexcept { return m_show; }
|
constexpr bool isOpen() const noexcept { return m_show; }
|
||||||
@ -41,7 +40,7 @@ class TileSheetEditorImGui: public studio::Editor {
|
|||||||
public:
|
public:
|
||||||
ox::Signal<ox::Error(int scale)> inputSubmitted;
|
ox::Signal<ox::Error(int scale)> inputSubmitted;
|
||||||
void show() noexcept;
|
void show() noexcept;
|
||||||
void draw(turbine::Context &sctx) noexcept;
|
void draw(turbine::Context &tctx) noexcept;
|
||||||
void close() noexcept;
|
void close() noexcept;
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr bool isOpen() const noexcept { return m_show; }
|
constexpr bool isOpen() const noexcept { return m_show; }
|
||||||
@ -99,8 +98,6 @@ class TileSheetEditorImGui: public studio::Editor {
|
|||||||
|
|
||||||
ox::Error updateActiveSubsheet(ox::StringView const&name, int cols, int rows) noexcept;
|
ox::Error updateActiveSubsheet(ox::StringView const&name, int cols, int rows) noexcept;
|
||||||
|
|
||||||
ox::Error setPaletteSelection() noexcept;
|
|
||||||
|
|
||||||
// slots
|
// slots
|
||||||
private:
|
private:
|
||||||
void setActiveSubsheet(TileSheet::SubSheetIdx path) noexcept;
|
void setActiveSubsheet(TileSheet::SubSheetIdx path) noexcept;
|
||||||
|
@ -42,17 +42,19 @@ Palette const TileSheetEditorModel::s_defaultPalette = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TileSheetEditorModel::TileSheetEditorModel(
|
TileSheetEditorModel::TileSheetEditorModel(
|
||||||
studio::StudioContext &sctx, ox::StringViewCR path, studio::UndoStack &undoStack):
|
studio::StudioContext &sctx, ox::StringParam path, studio::UndoStack &undoStack):
|
||||||
m_sctx(sctx),
|
m_sctx(sctx),
|
||||||
m_tctx(m_sctx.tctx),
|
m_tctx(m_sctx.tctx),
|
||||||
m_path(path),
|
m_path(std::move(path)),
|
||||||
m_img(*readObj<TileSheet>(keelCtx(m_tctx), m_path).unwrapThrow()),
|
m_img(*readObj<TileSheet>(keelCtx(m_tctx), m_path).unwrapThrow()),
|
||||||
// ignore failure to load palette
|
// ignore failure to load palette
|
||||||
m_pal(readObj<Palette>(keelCtx(m_tctx), m_img.defaultPalette).value),
|
m_pal(readObj<Palette>(keelCtx(m_tctx), m_img.defaultPalette).value),
|
||||||
m_undoStack(undoStack) {
|
m_undoStack(undoStack) {
|
||||||
normalizeSubsheets(m_img.subsheet);
|
normalizeSubsheets(m_img.subsheet);
|
||||||
m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated);
|
m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated);
|
||||||
m_undoStack.changeTriggered.connect(this, &TileSheetEditorModel::markUpdatedCmdId);
|
m_undoStack.changeTriggered.connect(this, &TileSheetEditorModel::markUpdatedCmdId);
|
||||||
|
setPalPath();
|
||||||
|
m_sctx.project->fileMoved.connect(this, &TileSheetEditorModel::handleFileRename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileSheetEditorModel::cut() {
|
void TileSheetEditorModel::cut() {
|
||||||
@ -116,18 +118,7 @@ bool TileSheetEditorModel::acceptsClipboardPayload() const noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ox::StringView TileSheetEditorModel::palPath() const noexcept {
|
ox::StringView TileSheetEditorModel::palPath() const noexcept {
|
||||||
auto &path = m_img.defaultPalette;
|
return m_palPath;
|
||||||
constexpr ox::StringView uuidPrefix = "uuid://";
|
|
||||||
if (ox::beginsWith(path, uuidPrefix)) {
|
|
||||||
auto const uuid = substr(path, uuidPrefix.bytes());
|
|
||||||
auto const out = keelCtx(m_tctx).uuidToPath.at(uuid);
|
|
||||||
if (out.error) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
return *out.value;
|
|
||||||
} else {
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error TileSheetEditorModel::setPalette(ox::StringViewCR path) noexcept {
|
ox::Error TileSheetEditorModel::setPalette(ox::StringViewCR path) noexcept {
|
||||||
@ -318,10 +309,33 @@ void TileSheetEditorModel::getFillPixels(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TileSheetEditorModel::setPalPath() noexcept {
|
||||||
|
auto &path = m_img.defaultPalette;
|
||||||
|
constexpr ox::StringView uuidPrefix = "uuid://";
|
||||||
|
if (ox::beginsWith(path, uuidPrefix)) {
|
||||||
|
auto const uuid = substr(path, uuidPrefix.bytes());
|
||||||
|
auto const out = keelCtx(m_tctx).uuidToPath.at(uuid);
|
||||||
|
if (!out.error) {
|
||||||
|
m_palPath = *out.value;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
m_palPath = path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TileSheetEditorModel::pushCommand(studio::UndoCommand *cmd) noexcept {
|
void TileSheetEditorModel::pushCommand(studio::UndoCommand *cmd) noexcept {
|
||||||
std::ignore = m_undoStack.push(ox::UPtr<studio::UndoCommand>{cmd});
|
std::ignore = m_undoStack.push(ox::UPtr<studio::UndoCommand>{cmd});
|
||||||
m_ongoingDrawCommand = dynamic_cast<DrawCommand*>(cmd);
|
m_ongoingDrawCommand = dynamic_cast<DrawCommand*>(cmd);
|
||||||
m_updated = true;
|
m_updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ox::Error TileSheetEditorModel::handleFileRename(ox::StringViewCR newPath, ox::UUID const&id) noexcept {
|
||||||
|
if ((beginsWith(m_img.defaultPalette, "uuid://") &&
|
||||||
|
substr(m_img.defaultPalette, 7) == id.toString()) ||
|
||||||
|
m_img.defaultPalette == newPath) {
|
||||||
|
m_palPath = newPath;
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
|
|||||||
studio::StudioContext &m_sctx;
|
studio::StudioContext &m_sctx;
|
||||||
turbine::Context &m_tctx;
|
turbine::Context &m_tctx;
|
||||||
ox::String m_path;
|
ox::String m_path;
|
||||||
|
ox::String m_palPath;
|
||||||
TileSheet m_img;
|
TileSheet m_img;
|
||||||
TileSheet::SubSheetIdx m_activeSubsSheetIdx;
|
TileSheet::SubSheetIdx m_activeSubsSheetIdx;
|
||||||
keel::AssetRef<Palette> m_pal;
|
keel::AssetRef<Palette> m_pal;
|
||||||
@ -36,7 +37,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
|
|||||||
bool m_updated = false;
|
bool m_updated = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TileSheetEditorModel(studio::StudioContext &sctx, ox::StringViewCR path, studio::UndoStack &undoStack);
|
TileSheetEditorModel(studio::StudioContext &sctx, ox::StringParam path, studio::UndoStack &undoStack);
|
||||||
|
|
||||||
~TileSheetEditorModel() override = default;
|
~TileSheetEditorModel() override = default;
|
||||||
|
|
||||||
@ -132,8 +133,12 @@ class TileSheetEditorModel: public ox::SignalHandler {
|
|||||||
ox::Point const&pt,
|
ox::Point const&pt,
|
||||||
int oldColor) const noexcept;
|
int oldColor) const noexcept;
|
||||||
|
|
||||||
|
void setPalPath() noexcept;
|
||||||
|
|
||||||
void pushCommand(studio::UndoCommand *cmd) noexcept;
|
void pushCommand(studio::UndoCommand *cmd) noexcept;
|
||||||
|
|
||||||
|
ox::Error handleFileRename(ox::StringViewCR newPath, ox::UUID const&id) noexcept;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr TileSheet const&TileSheetEditorModel::img() const noexcept {
|
constexpr TileSheet const&TileSheetEditorModel::img() const noexcept {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user