diff --git a/deps/nostalgia/deps/ox/src/ox/mc/test/tests.cpp b/deps/nostalgia/deps/ox/src/ox/mc/test/tests.cpp index 1ff87d1..08c4a0f 100644 --- a/deps/nostalgia/deps/ox/src/ox/mc/test/tests.cpp +++ b/deps/nostalgia/deps/ox/src/ox/mc/test/tests.cpp @@ -316,7 +316,7 @@ std::map tests = { testIn.Union.Int = 93; oxAssert(ox::writeMC(dataBuff.data(), dataBuff.size(), testIn), "Data generation failed"); ox::TypeStore typeStore; - const auto [type, typeErr] = ox::buildTypeDef(&typeStore, &testIn); + const auto [type, typeErr] = ox::buildTypeDef(typeStore, testIn); oxAssert(typeErr, "Descriptor write failed"); ox::ModelObject testOut; oxReturnError(testOut.setType(type)); @@ -368,7 +368,7 @@ std::map tests = { testIn.Struct.IString = "Test String 2"; oxAssert(ox::writeMC(dataBuff, dataBuffLen, testIn), "Data generation failed"); ox::TypeStore typeStore; - const auto [type, typeErr] = ox::buildTypeDef(&typeStore, &testIn); + const auto [type, typeErr] = ox::buildTypeDef(typeStore, testIn); oxAssert(typeErr, "Descriptor write failed"); ox::BufferReader br({dataBuff, dataBuffLen}); oxReturnError(ox::walkModel(type, br, diff --git a/deps/nostalgia/deps/ox/src/ox/model/descwrite.hpp b/deps/nostalgia/deps/ox/src/ox/model/descwrite.hpp index 089314d..817bfc1 100644 --- a/deps/nostalgia/deps/ox/src/ox/model/descwrite.hpp +++ b/deps/nostalgia/deps/ox/src/ox/model/descwrite.hpp @@ -357,8 +357,8 @@ constexpr const DescriptorType *TypeDescWriter::getType(StringViewCR tn, int typ } template -constexpr Result buildTypeDef(TypeStore *typeStore) noexcept { - TypeDescWriter writer(typeStore); +constexpr Result buildTypeDef(TypeStore &typeStore) noexcept { + TypeDescWriter writer(&typeStore); ModelHandlerInterface handler(&writer); if (std::is_constant_evaluated()) { std::allocator a; @@ -373,10 +373,10 @@ constexpr Result buildTypeDef(TypeStore *typeStore) noexcept { } template -constexpr Result buildTypeDef(TypeStore *typeStore, T *val) noexcept { - TypeDescWriter writer(typeStore); +constexpr Result buildTypeDef(TypeStore &typeStore, T &val) noexcept { + TypeDescWriter writer(&typeStore); ModelHandlerInterface handler(&writer); - oxReturnError(model(&handler, val)); + oxReturnError(model(&handler, &val)); return writer.definition(); } diff --git a/deps/nostalgia/deps/ox/src/ox/model/modelvalue.hpp b/deps/nostalgia/deps/ox/src/ox/model/modelvalue.hpp index 90088cf..7a62060 100644 --- a/deps/nostalgia/deps/ox/src/ox/model/modelvalue.hpp +++ b/deps/nostalgia/deps/ox/src/ox/model/modelvalue.hpp @@ -652,7 +652,7 @@ class ModelObject { } [[nodiscard]] - constexpr CRString typeName() const noexcept { + constexpr StringCR typeName() const noexcept { return m_type->typeName; } diff --git a/deps/nostalgia/deps/ox/src/ox/oc/test/tests.cpp b/deps/nostalgia/deps/ox/src/ox/oc/test/tests.cpp index e6597dc..13747d5 100644 --- a/deps/nostalgia/deps/ox/src/ox/oc/test/tests.cpp +++ b/deps/nostalgia/deps/ox/src/ox/oc/test/tests.cpp @@ -207,7 +207,7 @@ const std::map tests = { testIn.Union.Int = 93; oxAssert(ox::writeOC(testIn).moveTo(dataBuff), "Data generation failed"); ox::TypeStore typeStore; - auto type = ox::buildTypeDef(&typeStore, &testIn); + auto type = ox::buildTypeDef(typeStore, testIn); oxAssert(type.error, "Descriptor write failed"); ox::ModelObject testOut; oxReturnError(testOut.setType(type.value)); @@ -257,7 +257,7 @@ const std::map tests = { auto [oc, ocErr] = ox::writeOC(testIn); oxAssert(ocErr, "Data generation failed"); ox::TypeStore typeStore; - auto type = ox::buildTypeDef(&typeStore, &testIn); + auto type = ox::buildTypeDef(typeStore, testIn); oxAssert(type.error, "Descriptor write failed"); oxReturnError(ox::walkModel(type.value, oc.data(), oc.size(), [](const ox::Vector&, const ox::Vector&, const ox::DescriptorField &f, diff --git a/deps/nostalgia/deps/ox/src/ox/std/string.hpp b/deps/nostalgia/deps/ox/src/ox/std/string.hpp index 7c43bb9..7d6a7ba 100644 --- a/deps/nostalgia/deps/ox/src/ox/std/string.hpp +++ b/deps/nostalgia/deps/ox/src/ox/std/string.hpp @@ -539,7 +539,7 @@ constexpr void BasicString::set(const char8_t *str) noexcept extern template class BasicString<8>; using String = BasicString<8>; -using CRString = String const&; +using StringCR = String const&; [[nodiscard]] diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp index dd5f53e..ebf079a 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp @@ -98,6 +98,12 @@ void PaletteEditorImGui::drawColumn(ox::CStringView txt) noexcept { ImGui::Text("%s", txt.c_str()); } +void PaletteEditorImGui::colorInput(ox::CStringView label, int &v, bool &inputFocused) noexcept { + ImGui::InputInt(label.c_str(), &v, 1, 5); + inputFocused = inputFocused || ImGui::IsItemFocused(); + v = ox::max(v, 0); +} + void PaletteEditorImGui::drawColorsEditor() noexcept { constexpr auto tableFlags = ImGuiTableFlags_RowBg; auto const colorsSz = ImGui::GetContentRegionAvail(); @@ -238,17 +244,27 @@ void PaletteEditorImGui::drawColorEditor() noexcept { ox::IString<50> name; name = currentName; ImGui::InputText("Name", name.data(), name.cap() + 1); + bool inputFocused = ImGui::IsItemFocused(); ImGui::Separator(); - ImGui::InputInt("Red", &r, 1, 5); - ImGui::InputInt("Green", &g, 1, 5); - ImGui::InputInt("Blue", &b, 1, 5); + colorInput("Red", r, inputFocused); + colorInput("Green", g, inputFocused); + colorInput("Blue", b, inputFocused); if (ig::PushButton("Apply to all pages", {-1, ig::BtnSz.y})) { std::ignore = pushCommand( m_pal, m_page, m_selectedColorRow); } - r = ox::max(r, 0); - g = ox::max(g, 0); - b = ox::max(b, 0); + if (!inputFocused) { + auto const lastColor = largestPage(m_pal) - 1; + if (ImGui::IsKeyPressed(ImGuiKey_0, false)) { + m_selectedColorRow = ox::min(9, lastColor); + } else for (auto i = 9u; i < 10; --i) { + auto const key = static_cast(ImGuiKey_1 + i); + if (ImGui::IsKeyPressed(key, false)) { + m_selectedColorRow = ox::min(i, lastColor); + break; + } + } + } auto const newColor = color16(r, g, b, a); if (c != newColor) { std::ignore = pushCommand(m_pal, m_page, m_selectedColorRow, newColor); diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp index feefa08..d11d614 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp @@ -56,6 +56,8 @@ class PaletteEditorImGui: public studio::Editor { drawColumn(ox::itoa(i)); } + static void colorInput(ox::CStringView label, int &v, bool &inputFocused) noexcept; + void drawColorsEditor() noexcept; void drawPagesEditor() noexcept; diff --git a/deps/nostalgia/src/olympic/keel/include/keel/module.hpp b/deps/nostalgia/src/olympic/keel/include/keel/module.hpp index 13de7f1..6d17a1b 100644 --- a/deps/nostalgia/src/olympic/keel/include/keel/module.hpp +++ b/deps/nostalgia/src/olympic/keel/include/keel/module.hpp @@ -15,7 +15,7 @@ using TypeDescGenerator = ox::Error(*)(ox::TypeStore&); template ox::Error generateTypeDesc(ox::TypeStore &ts) noexcept { - return ox::buildTypeDef(&ts).error; + return ox::buildTypeDef(ts).error; } class Module { diff --git a/deps/nostalgia/src/olympic/studio/modlib/include/studio/project.hpp b/deps/nostalgia/src/olympic/studio/modlib/include/studio/project.hpp index 0672271..203cf1d 100644 --- a/deps/nostalgia/src/olympic/studio/modlib/include/studio/project.hpp +++ b/deps/nostalgia/src/olympic/studio/modlib/include/studio/project.hpp @@ -131,12 +131,15 @@ class Project { template ox::Error Project::writeObj(ox::StringViewCR path, T const&obj, ox::ClawFormat fmt) noexcept { oxRequireM(buff, ox::writeClaw(obj, fmt)); + if (fmt == ox::ClawFormat::Organic) { + buff.pop_back(); + } // write to FS oxReturnError(mkdir(parentDir(path))); oxReturnError(writeBuff(path, buff)); // write type descriptor if (m_typeStore.get().error) { - oxReturnError(ox::buildTypeDef(&m_typeStore, &obj)); + oxReturnError(ox::buildTypeDef(m_typeStore, obj)); } oxRequire(desc, m_typeStore.get()); auto const descPath = ox::sfmt("{}/{}", m_typeDescPath, buildTypeId(*desc));