[nostalgia/core/studio] Remove applicationData usages
All checks were successful
Build / build (push) Successful in 2m35s

This commit is contained in:
Gary Talent 2024-03-23 14:52:30 -05:00
parent 6a52319156
commit a4f0c7cdb5
8 changed files with 42 additions and 40 deletions

View File

@ -15,10 +15,11 @@
namespace nostalgia::core { namespace nostalgia::core {
PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &ctx, ox::CRStringView path): PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::CRStringView path):
Editor(path), Editor(path),
m_ctx(ctx.tctx), m_sctx(sctx),
m_pal(*keel::readObj<Palette>(keelCtx(m_ctx), ox::FileAddress(itemPath())).unwrapThrow()) { m_tctx(sctx.tctx),
m_pal(*keel::readObj<Palette>(keelCtx(m_tctx), ox::FileAddress(itemPath())).unwrapThrow()) {
undoStack()->changeTriggered.connect(this, &PaletteEditorImGui::handleCommand); undoStack()->changeTriggered.connect(this, &PaletteEditorImGui::handleCommand);
} }
@ -27,12 +28,12 @@ void PaletteEditorImGui::keyStateChanged(turbine::Key key, bool down) {
return; return;
} }
if (key >= turbine::Key::Num_1 && key <= turbine::Key::Num_9) { if (key >= turbine::Key::Num_1 && key <= turbine::Key::Num_9) {
if (turbine::buttonDown(m_ctx, turbine::Key::Mod_Alt)) { if (turbine::buttonDown(m_tctx, turbine::Key::Mod_Alt)) {
m_page = ox::min<std::size_t>( m_page = ox::min<std::size_t>(
static_cast<uint32_t>(key - turbine::Key::Num_1), m_pal.pages.size() - 1); static_cast<uint32_t>(key - turbine::Key::Num_1), m_pal.pages.size() - 1);
} }
} else if (key == turbine::Key::Num_0) { } else if (key == turbine::Key::Num_0) {
if (turbine::buttonDown(m_ctx, turbine::Key::Mod_Alt)) { if (turbine::buttonDown(m_tctx, turbine::Key::Mod_Alt)) {
m_selectedColorRow = m_selectedColorRow =
ox::min<std::size_t>( ox::min<std::size_t>(
static_cast<uint32_t>(key - turbine::Key::Num_1 + 9), m_pal.pages.size() - 1); static_cast<uint32_t>(key - turbine::Key::Num_1 + 9), m_pal.pages.size() - 1);
@ -57,8 +58,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); return m_sctx.project->writeObj(itemPath(), m_pal);
return sctx->project->writeObj(itemPath(), m_pal);
} }
void PaletteEditorImGui::drawColumn(ox::CStringView txt) noexcept { void PaletteEditorImGui::drawColumn(ox::CStringView txt) noexcept {

View File

@ -14,13 +14,14 @@ namespace nostalgia::core {
class PaletteEditorImGui: public studio::Editor { class PaletteEditorImGui: public studio::Editor {
private: private:
turbine::Context &m_ctx; studio::StudioContext &m_sctx;
turbine::Context &m_tctx;
Palette m_pal; Palette m_pal;
size_t m_selectedColorRow = 0; size_t m_selectedColorRow = 0;
size_t m_page = 0; size_t m_page = 0;
public: public:
PaletteEditorImGui(studio::StudioContext &ctx, ox::CRStringView path); PaletteEditorImGui(studio::StudioContext &sctx, ox::CRStringView path);
void keyStateChanged(turbine::Key key, bool down) override; void keyStateChanged(turbine::Key key, bool down) override;

View File

@ -75,10 +75,11 @@ static ox::Error toPngFile(
8))); 8)));
} }
TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &ctx, ox::CRStringView path): TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::CRStringView path):
Editor(path), Editor(path),
m_ctx(ctx.tctx), m_sctx(sctx),
m_view(m_ctx, path, *undoStack()), m_tctx(m_sctx.tctx),
m_view(m_sctx, path, *undoStack()),
m_model(m_view.model()) { m_model(m_view.model()) {
oxIgnoreError(setPaletteSelection()); oxIgnoreError(setPaletteSelection());
// connect signal/slots // connect signal/slots
@ -134,7 +135,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) {
setPasteEnabled(false); setPasteEnabled(false);
m_model.clearSelection(); m_model.clearSelection();
} else if (key >= turbine::Key::Num_1 && key <= turbine::Key::Num_9) { } else if (key >= turbine::Key::Num_1 && key <= turbine::Key::Num_9) {
if (turbine::buttonDown(m_ctx, turbine::Key::Mod_Alt)) { if (turbine::buttonDown(m_tctx, turbine::Key::Mod_Alt)) {
auto const idx = ox::min<std::size_t>( auto const idx = ox::min<std::size_t>(
static_cast<uint32_t>(key - turbine::Key::Num_1), m_model.pal().pages.size() - 1); static_cast<uint32_t>(key - turbine::Key::Num_1), m_model.pal().pages.size() - 1);
m_model.setPalettePage(idx); m_model.setPalettePage(idx);
@ -143,7 +144,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) {
m_view.setPalIdx(idx); m_view.setPalIdx(idx);
} }
} else if (key == turbine::Key::Num_0) { } else if (key == turbine::Key::Num_0) {
if (turbine::buttonDown(m_ctx, turbine::Key::Mod_Alt)) { if (turbine::buttonDown(m_tctx, turbine::Key::Mod_Alt)) {
auto const idx = ox::min<std::size_t>( auto const idx = ox::min<std::size_t>(
static_cast<uint32_t>(key - turbine::Key::Num_1 + 9), m_model.pal().pages.size() - 1); static_cast<uint32_t>(key - turbine::Key::Num_1 + 9), m_model.pal().pages.size() - 1);
m_model.setPalettePage(idx); m_model.setPalettePage(idx);
@ -235,8 +236,8 @@ void TileSheetEditorImGui::draw(turbine::Context&) noexcept {
ImGui::EndChild(); ImGui::EndChild();
} }
ImGui::EndChild(); ImGui::EndChild();
m_subsheetEditor.draw(m_ctx); m_subsheetEditor.draw(m_tctx);
m_exportMenu.draw(m_ctx); m_exportMenu.draw(m_tctx);
} }
void TileSheetEditorImGui::drawSubsheetSelector( void TileSheetEditorImGui::drawSubsheetSelector(
@ -359,7 +360,7 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
auto const wheelh = io.MouseWheelH; auto const wheelh = io.MouseWheelH;
if (wheel != 0) { if (wheel != 0) {
const auto zoomMod = ox::defines::OS == ox::OS::Darwin ? const auto zoomMod = ox::defines::OS == ox::OS::Darwin ?
io.KeySuper : turbine::buttonDown(m_ctx, turbine::Key::Mod_Ctrl); io.KeySuper : turbine::buttonDown(m_tctx, turbine::Key::Mod_Ctrl);
m_view.scrollV(fbSize, wheel, zoomMod); m_view.scrollV(fbSize, wheel, zoomMod);
} }
if (wheelh != 0) { if (wheelh != 0) {
@ -399,8 +400,7 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
} }
void TileSheetEditorImGui::drawPaletteSelector() noexcept { void TileSheetEditorImGui::drawPaletteSelector() noexcept {
auto &sctx = *applicationData<studio::StudioContext>(m_ctx); auto const&files = m_sctx.project->fileList(core::FileExt_npal);
auto const&files = sctx.project->fileList(core::FileExt_npal);
auto const comboWidthSub = 62; auto const comboWidthSub = 62;
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - comboWidthSub); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - comboWidthSub);
if (ig::ComboBox("Palette", files, m_selectedPaletteIdx)) { if (ig::ComboBox("Palette", files, m_selectedPaletteIdx)) {
@ -465,8 +465,7 @@ ox::Error TileSheetEditorImGui::updateActiveSubsheet(ox::StringView const&name,
ox::Error TileSheetEditorImGui::setPaletteSelection() noexcept { ox::Error TileSheetEditorImGui::setPaletteSelection() noexcept {
auto const&palPath = m_model.palPath(); auto const&palPath = m_model.palPath();
auto &sctx = *applicationData<studio::StudioContext>(m_ctx); auto const&palList = m_sctx.project->fileList(core::FileExt_npal);
auto const&palList = sctx.project->fileList(core::FileExt_npal);
for (std::size_t i = 0; auto const&pal : palList) { for (std::size_t i = 0; auto const&pal : palList) {
if (palPath == pal) { if (palPath == pal) {
m_selectedPaletteIdx = i; m_selectedPaletteIdx = i;

View File

@ -61,7 +61,8 @@ class TileSheetEditorImGui: public studio::Editor {
inline bool isOpen() const noexcept { return m_show; } inline bool isOpen() const noexcept { return m_show; }
}; };
std::size_t m_selectedPaletteIdx = 0; std::size_t m_selectedPaletteIdx = 0;
turbine::Context &m_ctx; studio::StudioContext &m_sctx;
turbine::Context &m_tctx;
ox::Vector<ox::String> m_paletteList; ox::Vector<ox::String> m_paletteList;
SubSheetEditor m_subsheetEditor; SubSheetEditor m_subsheetEditor;
ExportMenu m_exportMenu; ExportMenu m_exportMenu;
@ -73,7 +74,7 @@ class TileSheetEditorImGui: public studio::Editor {
Tool m_tool = Tool::Draw; Tool m_tool = Tool::Draw;
public: public:
TileSheetEditorImGui(studio::StudioContext &ctx, ox::CRStringView path); TileSheetEditorImGui(studio::StudioContext &sctx, ox::CRStringView path);
~TileSheetEditorImGui() override = default; ~TileSheetEditorImGui() override = default;

View File

@ -41,12 +41,13 @@ static void normalizeSubsheets(TileSheet::SubSheet &ss) noexcept {
} }
} }
TileSheetEditorModel::TileSheetEditorModel(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack): TileSheetEditorModel::TileSheetEditorModel(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack):
m_ctx(ctx), m_sctx(sctx),
m_tctx(m_sctx.tctx),
m_path(path), m_path(path),
m_img(*readObj<TileSheet>(keelCtx(m_ctx), 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_ctx), 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);
@ -70,7 +71,7 @@ void TileSheetEditorModel::cut() {
} }
const auto pt1 = m_selectionOrigin == ox::Point(-1, -1) ? ox::Point(0, 0) : m_selectionOrigin; const auto pt1 = m_selectionOrigin == ox::Point(-1, -1) ? ox::Point(0, 0) : m_selectionOrigin;
const auto pt2 = ox::Point(s.columns * TileWidth, s.rows * TileHeight); const auto pt2 = ox::Point(s.columns * TileWidth, s.rows * TileHeight);
turbine::setClipboardObject(m_ctx, std::move(cb)); turbine::setClipboardObject(m_tctx, std::move(cb));
pushCommand(ox::make<CutPasteCommand>(CommandId::Cut, m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb)); pushCommand(ox::make<CutPasteCommand>(CommandId::Cut, m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb));
} }
@ -87,11 +88,11 @@ void TileSheetEditorModel::copy() {
cb->addPixel(pt, c); cb->addPixel(pt, c);
} }
} }
turbine::setClipboardObject(m_ctx, std::move(cb)); turbine::setClipboardObject(m_tctx, std::move(cb));
} }
void TileSheetEditorModel::paste() { void TileSheetEditorModel::paste() {
auto [cb, err] = turbine::getClipboardObject<TileSheetClipboard>(m_ctx); auto [cb, err] = turbine::getClipboardObject<TileSheetClipboard>(m_tctx);
if (err) { if (err) {
oxLogError(err); oxLogError(err);
oxErrf("Could not read clipboard: {}", toStr(err)); oxErrf("Could not read clipboard: {}", toStr(err));
@ -111,7 +112,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept {
constexpr ox::StringView uuidPrefix = "uuid://"; constexpr ox::StringView uuidPrefix = "uuid://";
if (ox::beginsWith(path, uuidPrefix)) { if (ox::beginsWith(path, uuidPrefix)) {
auto uuid = ox::StringView(path.data() + uuidPrefix.bytes(), path.bytes() - uuidPrefix.bytes()); auto uuid = ox::StringView(path.data() + uuidPrefix.bytes(), path.bytes() - uuidPrefix.bytes());
auto out = keelCtx(m_ctx).uuidToPath.at(uuid); auto out = keelCtx(m_tctx).uuidToPath.at(uuid);
if (out.error) { if (out.error) {
return {}; return {};
} }
@ -122,7 +123,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept {
} }
ox::Error TileSheetEditorModel::setPalette(ox::StringView path) noexcept { ox::Error TileSheetEditorModel::setPalette(ox::StringView path) noexcept {
oxRequire(uuid, keelCtx(m_ctx).pathToUuid.at(path)); oxRequire(uuid, keelCtx(m_tctx).pathToUuid.at(path));
pushCommand(ox::make<PaletteChangeCommand>(activeSubSheetIdx(), m_img, uuid->toString())); pushCommand(ox::make<PaletteChangeCommand>(activeSubSheetIdx(), m_img, uuid->toString()));
return {}; return {};
} }
@ -239,7 +240,7 @@ ox::Error TileSheetEditorModel::markUpdatedCmdId(studio::UndoCommand const*cmd)
m_updated = true; m_updated = true;
const auto cmdId = cmd->commandId(); const auto cmdId = cmd->commandId();
if (static_cast<CommandId>(cmdId) == CommandId::PaletteChange) { if (static_cast<CommandId>(cmdId) == CommandId::PaletteChange) {
oxReturnError(readObj<Palette>(keelCtx(m_ctx), m_img.defaultPalette).moveTo(m_pal)); oxReturnError(readObj<Palette>(keelCtx(m_tctx), m_img.defaultPalette).moveTo(m_pal));
m_palettePage = ox::min<size_t>(m_pal->pages.size(), 0); m_palettePage = ox::min<size_t>(m_pal->pages.size(), 0);
paletteChanged.emit(); paletteChanged.emit();
} }
@ -261,8 +262,7 @@ void TileSheetEditorModel::ackUpdate() noexcept {
} }
ox::Error TileSheetEditorModel::saveFile() noexcept { ox::Error TileSheetEditorModel::saveFile() noexcept {
const auto sctx = applicationData<studio::StudioContext>(m_ctx); return m_sctx.project->writeObj(m_path, m_img, ox::ClawFormat::Metal);
return sctx->project->writeObj(m_path, m_img, ox::ClawFormat::Metal);
} }
bool TileSheetEditorModel::pixelSelected(std::size_t idx) const noexcept { bool TileSheetEditorModel::pixelSelected(std::size_t idx) const noexcept {

View File

@ -24,7 +24,8 @@ class TileSheetEditorModel: public ox::SignalHandler {
private: private:
static Palette const s_defaultPalette; static Palette const s_defaultPalette;
turbine::Context &m_ctx; studio::StudioContext &m_sctx;
turbine::Context &m_tctx;
ox::String m_path; ox::String m_path;
TileSheet m_img; TileSheet m_img;
TileSheet::SubSheetIdx m_activeSubsSheetIdx; TileSheet::SubSheetIdx m_activeSubsSheetIdx;
@ -38,7 +39,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
ox::Bounds m_selectionBounds = {{-1, -1}, {-1, -1}}; ox::Bounds m_selectionBounds = {{-1, -1}, {-1, -1}};
public: public:
TileSheetEditorModel(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack); TileSheetEditorModel(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack);
~TileSheetEditorModel() override = default; ~TileSheetEditorModel() override = default;

View File

@ -11,8 +11,8 @@
namespace nostalgia::core { namespace nostalgia::core {
TileSheetEditorView::TileSheetEditorView(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack): TileSheetEditorView::TileSheetEditorView(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack):
m_model(ctx, path, undoStack), m_model(sctx, path, undoStack),
m_pixelsDrawer(m_model) { m_pixelsDrawer(m_model) {
// build shaders // build shaders
oxThrowError(m_pixelsDrawer.buildShader()); oxThrowError(m_pixelsDrawer.buildShader());

View File

@ -50,7 +50,7 @@ class TileSheetEditorView: public ox::SignalHandler {
std::size_t m_palIdx = 0; std::size_t m_palIdx = 0;
public: public:
TileSheetEditorView(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack); TileSheetEditorView(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack);
~TileSheetEditorView() override = default; ~TileSheetEditorView() override = default;