diff --git a/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.CompactPalette;1 b/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.CompactPalette;1 new file mode 100644 index 0000000..ef34e1e --- /dev/null +++ b/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.CompactPalette;1 @@ -0,0 +1,23 @@ +O1;net.drinkingtea.ox.TypeDescriptor;1;{ + "fieldList" : + [ + { + "fieldName" : "pages", + "subscriptLevels" : 2, + "subscriptStack" : + [ + { + "subscriptType" : 4 + }, + { + "subscriptType" : 4 + } + ], + "typeId" : "B.uint16;0" + } + ], + "preloadable" : true, + "primitiveType" : 5, + "typeName" : "net.drinkingtea.nostalgia.gfx.CompactPalette", + "typeVersion" : 1 +} \ No newline at end of file diff --git a/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.CompactTileSheet;1 b/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.CompactTileSheet;1 new file mode 100644 index 0000000..277efdd --- /dev/null +++ b/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.CompactTileSheet;1 @@ -0,0 +1,28 @@ +O1;net.drinkingtea.ox.TypeDescriptor;1;{ + "fieldList" : + [ + { + "fieldName" : "bpp", + "typeId" : "B.int8;0" + }, + { + "fieldName" : "defaultPalette", + "typeId" : "net.drinkingtea.ox.FileAddress;1" + }, + { + "fieldName" : "pixels", + "subscriptLevels" : 1, + "subscriptStack" : + [ + { + "subscriptType" : 4 + } + ], + "typeId" : "B.uint8;0" + } + ], + "preloadable" : true, + "primitiveType" : 5, + "typeName" : "net.drinkingtea.nostalgia.gfx.CompactTileSheet", + "typeVersion" : 1 +} \ No newline at end of file diff --git a/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.Palette.PalettePage;2 b/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.Palette.PalettePage;2 new file mode 100644 index 0000000..5b26ee3 --- /dev/null +++ b/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.Palette.PalettePage;2 @@ -0,0 +1,23 @@ +O1;net.drinkingtea.ox.TypeDescriptor;1;{ + "fieldList" : + [ + { + "fieldName" : "name", + "typeId" : "net.drinkingtea.ox.BasicString#8#;1" + }, + { + "fieldName" : "colors", + "subscriptLevels" : 1, + "subscriptStack" : + [ + { + "subscriptType" : 4 + } + ], + "typeId" : "net.drinkingtea.nostalgia.gfx.PaletteColor;2" + } + ], + "primitiveType" : 5, + "typeName" : "net.drinkingtea.nostalgia.gfx.Palette.PalettePage", + "typeVersion" : 2 +} \ No newline at end of file diff --git a/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.Palette;5 b/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.Palette;5 new file mode 100644 index 0000000..797c7ce --- /dev/null +++ b/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.Palette;5 @@ -0,0 +1,31 @@ +O1;net.drinkingtea.ox.TypeDescriptor;1;{ + "fieldList" : + [ + { + "fieldName" : "colorNames", + "subscriptLevels" : 1, + "subscriptStack" : + [ + { + "subscriptType" : 4 + } + ], + "typeId" : "net.drinkingtea.ox.BasicString#8#;1" + }, + { + "fieldName" : "pages", + "subscriptLevels" : 1, + "subscriptStack" : + [ + { + "subscriptType" : 4 + } + ], + "typeId" : "net.drinkingtea.nostalgia.gfx.Palette.PalettePage;2" + } + ], + "preloadable" : true, + "primitiveType" : 5, + "typeName" : "net.drinkingtea.nostalgia.gfx.Palette", + "typeVersion" : 5 +} \ No newline at end of file diff --git a/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.PaletteColor;2 b/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.PaletteColor;2 new file mode 100644 index 0000000..24ca751 --- /dev/null +++ b/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.PaletteColor;2 @@ -0,0 +1,24 @@ +O1;net.drinkingtea.ox.TypeDescriptor;1;{ + "fieldList" : + [ + { + "fieldName" : "r", + "typeId" : "B.uint8;0" + }, + { + "fieldName" : "g", + "typeId" : "B.uint8;0" + }, + { + "fieldName" : "b", + "typeId" : "B.uint8;0" + }, + { + "fieldName" : "a", + "typeId" : "B.uint8;0" + } + ], + "primitiveType" : 5, + "typeName" : "net.drinkingtea.nostalgia.gfx.PaletteColor", + "typeVersion" : 2 +} \ No newline at end of file diff --git a/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.TileSheet.SubSheet;5 b/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.TileSheet.SubSheet;5 new file mode 100644 index 0000000..03740cf --- /dev/null +++ b/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.TileSheet.SubSheet;5 @@ -0,0 +1,46 @@ +O1;net.drinkingtea.ox.TypeDescriptor;1;{ + "fieldList" : + [ + { + "fieldName" : "id", + "typeId" : "B.int32;0" + }, + { + "fieldName" : "name", + "typeId" : "net.drinkingtea.ox.BasicString#8#;1" + }, + { + "fieldName" : "rows", + "typeId" : "B.int32;0" + }, + { + "fieldName" : "columns", + "typeId" : "B.int32;0" + }, + { + "fieldName" : "subsheets", + "subscriptLevels" : 1, + "subscriptStack" : + [ + { + "subscriptType" : 4 + } + ], + "typeId" : "net.drinkingtea.nostalgia.gfx.TileSheet.SubSheet;5" + }, + { + "fieldName" : "pixels", + "subscriptLevels" : 1, + "subscriptStack" : + [ + { + "subscriptType" : 4 + } + ], + "typeId" : "B.uint8;0" + } + ], + "primitiveType" : 5, + "typeName" : "net.drinkingtea.nostalgia.gfx.TileSheet.SubSheet", + "typeVersion" : 5 +} \ No newline at end of file diff --git a/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.TileSheet;5 b/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.TileSheet;5 new file mode 100644 index 0000000..a789389 --- /dev/null +++ b/sample_project/.nostalgia/type_descriptors/net.drinkingtea.nostalgia.gfx.TileSheet;5 @@ -0,0 +1,24 @@ +O1;net.drinkingtea.ox.TypeDescriptor;1;{ + "fieldList" : + [ + { + "fieldName" : "bpp", + "typeId" : "B.int8;0" + }, + { + "fieldName" : "idIt", + "typeId" : "B.int32;0" + }, + { + "fieldName" : "defaultPalette", + "typeId" : "net.drinkingtea.ox.BasicString#8#;1" + }, + { + "fieldName" : "subsheet", + "typeId" : "net.drinkingtea.nostalgia.gfx.TileSheet.SubSheet;5" + } + ], + "primitiveType" : 5, + "typeName" : "net.drinkingtea.nostalgia.gfx.TileSheet", + "typeVersion" : 5 +} \ No newline at end of file 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 20c9203..4809aa1 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp @@ -36,21 +36,12 @@ OX_MODEL_BEGIN(TileSheetEditorConfig) OX_MODEL_END() static ox::Vector normalizePixelSizes( - ox::Vector const&inPixels, - int const bpp) noexcept { - uint_t const bytesPerTile = bpp == 8 ? PixelsPerTile : PixelsPerTile / 2; + ox::Vector const&inPixels) noexcept { ox::Vector outPixels; - if (bytesPerTile == 64) { // 8 BPP - outPixels.resize(inPixels.size()); - for (std::size_t i = 0; i < inPixels.size(); ++i) { - outPixels[i] = inPixels[i]; - } - } else { // 4 BPP - outPixels.resize(inPixels.size() * 2); - for (std::size_t i = 0; i < inPixels.size(); ++i) { - outPixels[i * 2 + 0] = inPixels[i] & 0xF; - outPixels[i * 2 + 1] = inPixels[i] >> 4; - } + outPixels.reserve(inPixels.size()); + outPixels.resize(inPixels.size()); + for (std::size_t i = 0; i < inPixels.size(); ++i) { + outPixels[i] = inPixels[i]; } return outPixels; } @@ -409,12 +400,11 @@ void TileSheetEditorImGui::showSubsheetEditor() noexcept { ox::Error TileSheetEditorImGui::exportSubhseetToPng(int const scale) const noexcept { OX_REQUIRE(path, studio::saveFile({{"PNG", "png"}})); // subsheet to png - auto const&img = m_model.img(); auto const&s = m_model.activeSubSheet(); auto const&pal = m_model.pal(); auto const width = s.columns * TileWidth; auto const height = s.rows * TileHeight; - auto pixels = normalizePixelSizes(s.pixels, img.bpp); + auto pixels = normalizePixelSizes(s.pixels); pixels = normalizePixelArrangement(pixels, s.columns, scale); auto const err = toPngFile( path, @@ -566,8 +556,10 @@ void TileSheetEditorImGui::drawPaletteMenu() noexcept { m_view.setPalIdx(i); } if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) { - auto const rqst = ox::sfmt>("{};{}", i, m_model.palettePage()); - oxLogError(studio::navigateTo(m_sctx, m_model.palPath(), rqst)); + studio::navigateTo( + m_sctx, + m_model.palPath(), + ox::sfmt("{};{}", i, m_model.palettePage())); } // Column: color RGB ImGui::TableNextColumn(); diff --git a/src/olympic/studio/applib/src/studioapp.cpp b/src/olympic/studio/applib/src/studioapp.cpp index a17e8c5..6782603 100644 --- a/src/olympic/studio/applib/src/studioapp.cpp +++ b/src/olympic/studio/applib/src/studioapp.cpp @@ -18,8 +18,8 @@ namespace studio { -ox::Error navigateTo(StudioContext &ctx, ox::StringViewCR filePath, ox::StringViewCR args) noexcept { - return ctx.ui.navigateTo(filePath, args); +void navigateTo(StudioContext &ctx, ox::StringParam filePath, ox::StringParam navArgs) noexcept { + ctx.ui.navigateTo(std::move(filePath), std::move(navArgs)); } namespace ig { @@ -111,10 +111,8 @@ void StudioUI::handleKeyEvent(turbine::Key const key, bool const down) noexcept } } -ox::Error StudioUI::navigateTo(ox::StringViewCR path, ox::StringViewCR navArgs) noexcept { - OX_RETURN_ERROR(openFile(path)); - m_activeEditor->navigateTo(navArgs); - return {}; +void StudioUI::navigateTo(ox::StringParam path, ox::StringParam navArgs) noexcept { + m_navAction.emplace(std::move(path), std::move(navArgs)); } void StudioUI::draw() noexcept { @@ -287,6 +285,11 @@ void StudioUI::drawTabs() noexcept { } m_closeActiveTab = false; } + if (m_navAction) { + oxLogError(openFile(m_navAction->path)); + m_activeEditor->navigateTo(m_navAction->args); + m_navAction.reset(); + } } void StudioUI::loadEditorMaker(EditorMaker const&editorMaker) noexcept { diff --git a/src/olympic/studio/applib/src/studioapp.hpp b/src/olympic/studio/applib/src/studioapp.hpp index a37c531..8c8903f 100644 --- a/src/olympic/studio/applib/src/studioapp.hpp +++ b/src/olympic/studio/applib/src/studioapp.hpp @@ -62,13 +62,18 @@ class StudioUI: public ox::SignalHandler { &m_renameFile, }; bool m_showProjectExplorer = true; + struct NavAction { + ox::String path; + ox::String args; + }; + ox::Optional m_navAction; public: explicit StudioUI(turbine::Context &ctx, ox::StringParam projectDataDir) noexcept; void handleKeyEvent(turbine::Key, bool down) noexcept; - ox::Error navigateTo(ox::StringViewCR path, ox::StringViewCR navArgs = {}) noexcept; + void navigateTo(ox::StringParam path, ox::StringParam navArgs) noexcept; [[nodiscard]] constexpr Project *project() noexcept { diff --git a/src/olympic/studio/modlib/include/studio/context.hpp b/src/olympic/studio/modlib/include/studio/context.hpp index f14fe0e..3093313 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(StudioContext &ctx) noexcept { return keelCtx(ctx.tctx); } -ox::Error navigateTo(StudioContext &ctx, ox::StringViewCR filePath, ox::StringViewCR args) noexcept; +void navigateTo(StudioContext &ctx, ox::StringParam filePath, ox::StringParam navArgs) noexcept; }