diff --git a/src/anm2/anm2.cpp b/src/anm2/anm2.cpp index 335994f..54276bf 100644 --- a/src/anm2/anm2.cpp +++ b/src/anm2/anm2.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "file_.hpp" @@ -199,6 +200,28 @@ namespace anm2ed::anm2 Anm2 Anm2::normalized_for_serialize() const { auto normalized = *this; + auto sanitize_layer_order = [](Animation& animation) + { + std::vector sanitized{}; + sanitized.reserve(animation.layerAnimations.size()); + std::set seen{}; + + for (auto id : animation.layerOrder) + { + if (!animation.layerAnimations.contains(id)) continue; + if (!seen.insert(id).second) continue; + sanitized.push_back(id); + } + + std::vector missing{}; + missing.reserve(animation.layerAnimations.size()); + for (auto& id : animation.layerAnimations | std::views::keys) + if (!seen.contains(id)) missing.push_back(id); + + std::sort(missing.begin(), missing.end()); + sanitized.insert(sanitized.end(), missing.begin(), missing.end()); + animation.layerOrder = std::move(sanitized); + }; std::unordered_map layerRemap{}; int normalizedID = 0; @@ -214,6 +237,7 @@ namespace anm2ed::anm2 for (auto& animation : normalized.animations.items) { + sanitize_layer_order(animation); std::unordered_map layerAnimations{}; std::vector layerOrder{}; @@ -231,6 +255,7 @@ namespace anm2ed::anm2 animation.layerAnimations = std::move(layerAnimations); animation.layerOrder = std::move(layerOrder); + sanitize_layer_order(animation); } return normalized; diff --git a/src/anm2/anm2_animations.cpp b/src/anm2/anm2_animations.cpp index 1cfb030..5bce099 100644 --- a/src/anm2/anm2_animations.cpp +++ b/src/anm2/anm2_animations.cpp @@ -136,4 +136,4 @@ namespace anm2ed::anm2 return finalIndex; } -} \ No newline at end of file +} diff --git a/src/anm2/anm2_sounds.cpp b/src/anm2/anm2_sounds.cpp index 425a457..6c07273 100644 --- a/src/anm2/anm2_sounds.cpp +++ b/src/anm2/anm2_sounds.cpp @@ -1,5 +1,7 @@ #include "anm2.hpp" +#include + #include "map_.hpp" #include "path_.hpp" #include "working_directory.hpp" diff --git a/src/imgui/toast.cpp b/src/imgui/toast.cpp index 9e3274a..bc04ea4 100644 --- a/src/imgui/toast.cpp +++ b/src/imgui/toast.cpp @@ -1,5 +1,7 @@ #include "toast.hpp" +#include + #include "log.hpp" #include diff --git a/src/imgui/window/animation_preview.cpp b/src/imgui/window/animation_preview.cpp index 5542a3e..802b05e 100644 --- a/src/imgui/window/animation_preview.cpp +++ b/src/imgui/window/animation_preview.cpp @@ -780,9 +780,11 @@ namespace anm2ed::imgui for (auto& id : animation->layerOrder) { + if (!animation->layerAnimations.contains(id)) continue; auto& layerAnimation = animation->layerAnimations[id]; if (!layerAnimation.isVisible) continue; + if (!anm2.content.layers.contains(id)) continue; auto& layer = anm2.content.layers.at(id); auto spritesheet = anm2.spritesheet_get(layer.spritesheetID); diff --git a/src/imgui/window/events.cpp b/src/imgui/window/events.cpp index b0a9f59..8a99134 100644 --- a/src/imgui/window/events.cpp +++ b/src/imgui/window/events.cpp @@ -1,5 +1,6 @@ #include "events.hpp" +#include #include #include "log.hpp" diff --git a/src/imgui/window/layers.cpp b/src/imgui/window/layers.cpp index 2fa8105..e59235f 100644 --- a/src/imgui/window/layers.cpp +++ b/src/imgui/window/layers.cpp @@ -1,5 +1,6 @@ #include "layers.hpp" +#include #include #include "log.hpp" diff --git a/src/imgui/window/nulls.cpp b/src/imgui/window/nulls.cpp index abb4c08..c93ae9a 100644 --- a/src/imgui/window/nulls.cpp +++ b/src/imgui/window/nulls.cpp @@ -1,5 +1,6 @@ #include "nulls.hpp" +#include #include #include "log.hpp" diff --git a/src/imgui/window/sounds.cpp b/src/imgui/window/sounds.cpp index 3beb8d3..5021ae4 100644 --- a/src/imgui/window/sounds.cpp +++ b/src/imgui/window/sounds.cpp @@ -1,6 +1,7 @@ #include "sounds.hpp" #include +#include #include #include diff --git a/src/imgui/window/spritesheets.cpp b/src/imgui/window/spritesheets.cpp index a5eb90a..595e90d 100644 --- a/src/imgui/window/spritesheets.cpp +++ b/src/imgui/window/spritesheets.cpp @@ -595,7 +595,7 @@ namespace anm2ed::imgui mergePopup.close(); }; - auto optionsSize = child_size_get(5); + auto optionsSize = child_size_get(6); if (ImGui::BeginChild("##Merge Spritesheets Options", optionsSize, ImGuiChildFlags_Borders)) { ImGui::SeparatorText(localize.get(LABEL_REGION_PROPERTIES_ORIGIN)); diff --git a/src/imgui/window/timeline.cpp b/src/imgui/window/timeline.cpp index 81f1c38..af9dfe1 100644 --- a/src/imgui/window/timeline.cpp +++ b/src/imgui/window/timeline.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include diff --git a/src/imgui/window/welcome.cpp b/src/imgui/window/welcome.cpp index 59b9524..3ac1897 100644 --- a/src/imgui/window/welcome.cpp +++ b/src/imgui/window/welcome.cpp @@ -1,5 +1,6 @@ #include "welcome.hpp" +#include #include #include "path_.hpp" diff --git a/src/imgui/wizard/configure.cpp b/src/imgui/wizard/configure.cpp index 5e3dc0b..eab9e0b 100644 --- a/src/imgui/wizard/configure.cpp +++ b/src/imgui/wizard/configure.cpp @@ -1,6 +1,9 @@ #include "configure.hpp" #include "imgui_.hpp" +#include "log.hpp" +#include "path_.hpp" +#include "sdl.hpp" using namespace anm2ed::types; @@ -180,6 +183,7 @@ namespace anm2ed::imgui::wizard shortcut(manager.chords[SHORTCUT_CONFIRM]); if (ImGui::Button(localize.get(BASIC_SAVE), widgetSize)) { + auto settingsPath = util::sdl::preferences_directory_get() / "settings.ini"; settings = temporary; ImGui::GetIO().KeyRepeatDelay = settings.keyboardRepeatDelay; @@ -193,6 +197,8 @@ namespace anm2ed::imgui::wizard for (auto& document : manager.documents) document.snapshots.apply_limit(); + settings.save(settingsPath, ImGui::SaveIniSettingsToMemory(nullptr)); + isSet = true; } ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_SETTINGS_SAVE)); diff --git a/src/loader.cpp b/src/loader.cpp index 51c64b4..7fdfd6b 100644 --- a/src/loader.cpp +++ b/src/loader.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -22,7 +23,6 @@ #ifdef _WIN32 #include "util/path_.hpp" #include - #include #include #endif diff --git a/src/log.cpp b/src/log.cpp index e0de220..958bc0b 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -1,6 +1,7 @@ #include "log.hpp" #include +#include #include #include "file_.hpp" diff --git a/src/settings.cpp b/src/settings.cpp index be984d5..e0689e8 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -338,7 +338,15 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1496,860 S void Settings::save(const std::filesystem::path& path, const std::string& imguiData) { + auto pathUtf8 = path::to_utf8(path); + logger.info(std::format("Saving settings to: {}", pathUtf8)); std::ofstream file(path, std::ios::out | std::ios::binary); + if (!file.is_open()) + { + logger.error(std::format("Failed to save settings file: {}", pathUtf8)); + return; + } + file << "[Settings]\n"; auto value_save = [&](const std::string& key, const auto& value) @@ -395,6 +403,12 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1496,860 S << imguiData; file.flush(); + if (file.fail()) + { + logger.error(std::format("Failed while writing settings file: {}", pathUtf8)); + return; + } file.close(); + logger.info(std::format("Saved settings to: {}", pathUtf8)); } }