diff --git a/Makefile b/Makefile index 4994411..bcbfdad 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ pkg-gba: build .PHONY: pkg-mac pkg-mac: install - ${BC_CMD_ENVRUN} ${BC_PY3} ./util/scripts/pkg-dmg.py + ${BC_CMD_ENVRUN} ${BC_PY3} ./util/scripts/pkg-dmg.py NostalgiaStudio .PHONY: generate-studio-rsrc generate-studio-rsrc: diff --git a/deps/ox/src/ox/std/stringparam.hpp b/deps/ox/src/ox/std/stringparam.hpp index b875ac3..32e9e5b 100644 --- a/deps/ox/src/ox/std/stringparam.hpp +++ b/deps/ox/src/ox/std/stringparam.hpp @@ -20,6 +20,8 @@ class StringParam { constexpr StringParam(StringParam &&o) noexcept: m_value{std::move(o.m_value)} {} constexpr StringParam(char const*value) noexcept: m_value{value} {} constexpr StringParam(detail::BaseStringView const&value) noexcept: m_value{value} {} + template + constexpr StringParam(ox::IString const&value) noexcept: m_value{value} {} constexpr StringParam(ox::String const&value) noexcept: m_value{value} {} constexpr StringParam(ox::String &&value) noexcept: m_value{std::move(value)} {} constexpr operator ox::String() && noexcept { return std::move(m_value); } diff --git a/src/nostalgia/modules/gfx/include/nostalgia/gfx/tilesheet.hpp b/src/nostalgia/modules/gfx/include/nostalgia/gfx/tilesheet.hpp index 14652ec..7593e09 100644 --- a/src/nostalgia/modules/gfx/include/nostalgia/gfx/tilesheet.hpp +++ b/src/nostalgia/modules/gfx/include/nostalgia/gfx/tilesheet.hpp @@ -426,6 +426,8 @@ ox::Error resizeSubsheet(TileSheet::SubSheet &ss, ox::Size const&sz) noexcept; [[nodiscard]] TileSheet::SubSheetIdx validateSubSheetIdx(TileSheet const&ts, TileSheet::SubSheetIdx idx) noexcept; +ox::Result getSubSheetIdx(TileSheet const &ts, SubSheetId pId) noexcept; + [[nodiscard]] TileSheet::SubSheet &getSubSheet( ox::SpanView const&idx, diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp index 2bea079..2c574aa 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp @@ -388,6 +388,17 @@ ox::Error TileSheetEditorImGui::saveItem() noexcept { return m_model.saveFile(); } +void TileSheetEditorImGui::navigateTo(ox::StringViewCR arg) noexcept { + auto const subSheetId = strToInt(arg); + if (subSheetId.error) { + return; + } + if (auto const [val, err] = getSubSheetIdx(m_model.img(), subSheetId.value); + !err) { + setActiveSubsheet(val); + } +} + void TileSheetEditorImGui::showSubsheetEditor() noexcept { auto const&sheet = m_model.activeSubSheet(); if (!sheet.subsheets.empty()) { @@ -451,7 +462,7 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept { if (wheelh != 0) { m_view.scrollH(fbSize, wheelh); } - if (ImGui::IsMouseDown(0) && m_prevMouseDownPos != mousePos) { + if (ImGui::IsMouseClicked(0) && m_prevMouseDownPos != mousePos) { m_prevMouseDownPos = mousePos; switch (m_tool) { case TileSheetTool::Draw: diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp index e16a2ce..53cac5b 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp @@ -87,6 +87,8 @@ class TileSheetEditorImGui: public studio::Editor { protected: ox::Error saveItem() noexcept override; + void navigateTo(ox::StringViewCR arg) noexcept override; + private: void showSubsheetEditor() noexcept; diff --git a/src/nostalgia/modules/gfx/src/tilesheet.cpp b/src/nostalgia/modules/gfx/src/tilesheet.cpp index d30e51a..796ce31 100644 --- a/src/nostalgia/modules/gfx/src/tilesheet.cpp +++ b/src/nostalgia/modules/gfx/src/tilesheet.cpp @@ -2,6 +2,8 @@ * Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved. */ +#include "nostalgia/gfx/tilesheet.hpp" + #include #include @@ -187,6 +189,28 @@ TileSheet::SubSheetIdx validateSubSheetIdx(TileSheet const&ts, TileSheet::SubShe return validateSubSheetIdx(std::move(idx), 0, ts.subsheet); } +static ox::Error getSubSheetIdx(TileSheet::SubSheet const &ss, SubSheetId const pId, TileSheet::SubSheetIdx &idx) noexcept { + if (ss.id == pId) { + return {}; + } + for (uint32_t i{}; auto const &sub : ss.subsheets) { + idx.emplace_back(i); + auto const err = getSubSheetIdx(sub, pId, idx); + if (!err) { + return {}; + } + idx.pop_back(); + ++i; + } + return ox::Error{1, "SubSheet not found"}; +} + +ox::Result getSubSheetIdx(TileSheet const &ts, SubSheetId const pId) noexcept { + ox::Result out; + OX_RETURN_ERROR(getSubSheetIdx(ts.subsheet, pId, out.value)); + return out; +} + #if defined(__GNUC__) && __GNUC__ >= 13 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdangling-reference" diff --git a/src/olympic/studio/applib/src/studioui.cpp b/src/olympic/studio/applib/src/studioui.cpp index b617f0e..a6d0d6e 100644 --- a/src/olympic/studio/applib/src/studioui.cpp +++ b/src/olympic/studio/applib/src/studioui.cpp @@ -31,7 +31,15 @@ static bool shutdownHandler(turbine::Context &ctx) { } void navigateTo(Context &ctx, ox::StringParam filePath, ox::StringParam navArgs) noexcept { - ctx.ui.navigateTo(std::move(filePath), std::move(navArgs)); + ox::String path = std::move(filePath); + if (beginsWith(path, "uuid://")) { + auto [p, err] = keel::uuidUrlToPath(keelCtx(ctx), path); + if (err) { + return; + } + path = p; + } + ctx.ui.navigateTo(std::move(path), std::move(navArgs)); } namespace ig { diff --git a/src/olympic/studio/modlib/include/studio/context.hpp b/src/olympic/studio/modlib/include/studio/context.hpp index bc6a3e3..17f067a 100644 --- a/src/olympic/studio/modlib/include/studio/context.hpp +++ b/src/olympic/studio/modlib/include/studio/context.hpp @@ -27,6 +27,6 @@ inline keel::Context &keelCtx(Context &ctx) noexcept { return keelCtx(ctx.tctx); } -void navigateTo(Context &ctx, ox::StringParam filePath, ox::StringParam navArgs) noexcept; +void navigateTo(Context &ctx, ox::StringParam filePath, ox::StringParam navArgs = "") noexcept; } diff --git a/util/scripts/pkg-dmg.py b/util/scripts/pkg-dmg.py index d006912..41ad679 100755 --- a/util/scripts/pkg-dmg.py +++ b/util/scripts/pkg-dmg.py @@ -5,6 +5,8 @@ import shutil import subprocess import sys +target_name = sys.argv[1] + def rm(path: str): file_exists = os.path.exists(path) is_link = os.path.islink(path) @@ -26,12 +28,12 @@ def run(args: list[str]): -dmg_dir = 'dist/darwin-arm64-release/NostalgiaStudio' +dmg_dir = f'dist/darwin-arm64-release/{target_name}' dmg = f'{dmg_dir}.dmg' rm(dmg) rm(dmg_dir) mkdir_p(dmg_dir) -shutil.copytree('dist/darwin-arm64-release/NostalgiaStudio.app', f'{dmg_dir}/NostalgiaStudio.app') +shutil.copytree(f'dist/darwin-arm64-release/{target_name}.app', f'{dmg_dir}/{target_name}.app') os.symlink('/Applications', f'{dmg_dir}/Applications') run(['hdiutil', 'create', '-srcfolder', dmg_dir, dmg]) rm(dmg_dir)