From 98f87c9d46ec3446220e56ac73a5be7a6dbec21c Mon Sep 17 00:00:00 2001 From: shweet Date: Wed, 15 Jul 2026 12:47:44 -0400 Subject: [PATCH] fix sound serialization + extended format --- src/anm2/anm2.cpp | 40 ++++++++++++++++++++++++++++++---- src/anm2/anm2.hpp | 1 + src/imgui/documents.cpp | 4 +++- src/imgui/taskbar.cpp | 8 +++---- src/imgui/taskbar.hpp | 1 + src/imgui/wizard/configure.cpp | 4 ++++ src/resource/strings.hpp | 3 +++ src/settings.cpp | 5 +++++ src/settings.hpp | 2 ++ 9 files changed, 59 insertions(+), 9 deletions(-) diff --git a/src/anm2/anm2.cpp b/src/anm2/anm2.cpp index d72443e..b4afb00 100644 --- a/src/anm2/anm2.cpp +++ b/src/anm2/anm2.cpp @@ -629,9 +629,7 @@ namespace anm2ed if ((element.type == ElementType::LAYER_ANIMATION_GROUPS || element.type == ElementType::NULL_ANIMATION_GROUPS) && (!has_flag(flags, SERIALIZE_GROUPS) || element.children.empty())) return true; - if (element.type == ElementType::SOUND_ELEMENT && parentType == ElementType::TRIGGER && - !has_flag(flags, SERIALIZE_SOUNDS)) - return true; + if (element.type == ElementType::SOUND_ELEMENT && parentType == ElementType::TRIGGER) return true; if (element.type == ElementType::REGION && !has_flag(flags, SERIALIZE_REGIONS)) return true; if (element.type == ElementType::GROUP && !has_flag(flags, SERIALIZE_GROUPS)) return true; return false; @@ -818,11 +816,25 @@ namespace anm2ed } } + void trigger_sounds_xml_insert(XMLDocument& document, XMLElement* out, const Element& element, Flags flags) + { + if (element.type != ElementType::TRIGGER || !has_flag(flags, SERIALIZE_SOUNDS)) return; + + for (auto soundId : element.soundIds) + { + if (soundId == -1) continue; + auto sound = document.NewElement(element_tag_get(ElementType::SOUND_ELEMENT).data()); + sound->SetAttribute("Id", soundId); + out->InsertEndChild(sound); + } + } + XMLElement* element_to_xml(XMLDocument& document, const Element& element, ElementType parentType, Flags flags) { auto tag = element.type == ElementType::UNKNOWN ? std::string_view(element.tag) : element_tag_get(element.type); auto out = document.NewElement(tag.empty() ? element.tag.c_str() : tag.data()); element_attributes_write(out, element, parentType, flags); + trigger_sounds_xml_insert(document, out, element, flags); for (int i = 0; i < (int)element.children.size(); ++i) { @@ -1095,6 +1107,19 @@ namespace anm2ed void element_hash_append(std::uint64_t& hash, const Element& element, ElementType parentType, Flags flags, std::optional bakeAttributes = std::nullopt); + void trigger_sounds_hash_append(std::uint64_t& hash, const Element& element, Flags flags) + { + if (element.type != ElementType::TRIGGER || !has_flag(flags, SERIALIZE_SOUNDS)) return; + + for (auto soundId : element.soundIds) + { + if (soundId == -1) continue; + auto sound = element_make(ElementType::SOUND_ELEMENT); + sound.id = soundId; + element_hash_append(hash, sound, ElementType::TRIGGER, flags); + } + } + void baked_frames_hash_append(std::uint64_t& hash, const Element& track, int index, Flags flags) { const auto& original = track.children[index]; @@ -1131,6 +1156,7 @@ namespace anm2ed if (bakeAttributes) bake_attributes_hash_append(hash, bakeAttributes->interpolation, bakeAttributes->delay); hash_byte_append(hash, '['); + trigger_sounds_hash_append(hash, element, flags); for (int i = 0; i < (int)element.children.size(); ++i) { const auto& child = element.children[i]; @@ -1545,6 +1571,7 @@ namespace anm2ed bool is_track_child_valid(ElementType parentType, ElementType childType) { if (parentType == ElementType::TRIGGERS) return childType == ElementType::TRIGGER; + if (parentType == ElementType::TRIGGER) return childType == ElementType::SOUND_ELEMENT; if (parentType == ElementType::LAYER_ANIMATION_GROUPS || parentType == ElementType::NULL_ANIMATION_GROUPS) return childType == ElementType::GROUP; if (parentType == ElementType::ROOT_ANIMATION || parentType == ElementType::LAYER_ANIMATION || @@ -2387,7 +2414,12 @@ namespace anm2ed XMLElement* Anm2::to_element(XMLDocument& document, Options options) const { - (void)options; + if (options.isExtendedFormat) + { + auto editor = normalized_for_serialize(SERIALIZE_ANM2ED_DEFAULT); + editor.region_frames_sync(true); + return element_to_xml(document, editor.root, ElementType::UNKNOWN, SERIALIZE_ANM2ED_DEFAULT); + } auto isaac = normalized_for_serialize(SERIALIZE_ISAAC_DEFAULT); isaac.region_frames_sync(true); diff --git a/src/anm2/anm2.hpp b/src/anm2/anm2.hpp index 6bf8a9d..104e2dd 100644 --- a/src/anm2/anm2.hpp +++ b/src/anm2/anm2.hpp @@ -208,6 +208,7 @@ namespace anm2ed struct Options { Flags flags{SERIALIZE_DEFAULT}; + bool isExtendedFormat{}; }; struct FrameChange diff --git a/src/imgui/documents.cpp b/src/imgui/documents.cpp index 8466b51..a9c4f8d 100644 --- a/src/imgui/documents.cpp +++ b/src/imgui/documents.cpp @@ -150,7 +150,9 @@ namespace anm2ed::imgui document.lastAutosaveTime += ImGui::GetIO().DeltaTime; if (document.lastAutosaveTime > time::SECOND_M) { - manager.command_push({i, [](Manager& manager, Document& document) { manager.autosave(document); }}); + auto options = settings.anm2_options_get(); + manager.command_push({i, [options](Manager& manager, Document& document) + { manager.autosave(document, options); }}); } } } diff --git a/src/imgui/taskbar.cpp b/src/imgui/taskbar.cpp index 04f38c2..2bcce91 100644 --- a/src/imgui/taskbar.cpp +++ b/src/imgui/taskbar.cpp @@ -29,27 +29,27 @@ namespace anm2ed::imgui bool Taskbar::save_execute(Manager& manager, const PendingSave& request) { - return manager.save(request.index, request.path); + return manager.save(request.index, request.path, request.options); } void Taskbar::save_enqueue(Manager& manager, const PendingSave& request) { auto index = request.index; auto path = request.path; + auto options = request.options; manager.command_push({.runManager = [=](Manager& manager) - { manager.save(index, path); }}); + { manager.save(index, path, options); }}); } bool Taskbar::save_request(Manager& manager, Settings& settings, int index, const std::filesystem::path& path, bool isQueued) { - (void)settings; auto* document = manager.get(index); if (!document) return false; - PendingSave request{.index = index, .path = path}; + PendingSave request{.index = index, .path = path, .options = settings.anm2_options_get()}; if (isQueued) { save_enqueue(manager, request); diff --git a/src/imgui/taskbar.hpp b/src/imgui/taskbar.hpp index 0eaacce..16354e5 100644 --- a/src/imgui/taskbar.hpp +++ b/src/imgui/taskbar.hpp @@ -24,6 +24,7 @@ namespace anm2ed::imgui { int index{-1}; std::filesystem::path path{}; + Options options{}; bool isQueued{}; }; diff --git a/src/imgui/wizard/configure.cpp b/src/imgui/wizard/configure.cpp index 131a9e9..fb6984a 100644 --- a/src/imgui/wizard/configure.cpp +++ b/src/imgui/wizard/configure.cpp @@ -71,6 +71,10 @@ namespace anm2ed::imgui::wizard ImGui::SeparatorText(localize.get(LABEL_OPTIONS)); ImGui::Checkbox(localize.get(LABEL_OVERWRITE_WARNING), &temporary.fileIsWarnOverwrite); ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_OVERWRITE_WARNING)); + + ImGui::SeparatorText(localize.get(LABEL_SERIALIZATION)); + ImGui::Checkbox(localize.get(LABEL_EXTENDED_FORMAT), &temporary.isFileExtendedFormat); + ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_EXTENDED_FORMAT)); } ImGui::EndChild(); diff --git a/src/resource/strings.hpp b/src/resource/strings.hpp index 7bc485f..1fb2a84 100644 --- a/src/resource/strings.hpp +++ b/src/resource/strings.hpp @@ -367,6 +367,8 @@ namespace anm2ed X(LABEL_OVERLAYS_WINDOW, "Overlays###Overlays", "Overlays###Overlays", "Overlays###Overlays", "Overlays###Overlays", "Overlays###Overlays") \ X(LABEL_OVERWRITE_CONFIRMATION, "Are you sure? This will overwrite the existing file.", "¿Estas Seguro? Esto sobreescribira el archivo existente.", "Вы уверены? Это перезапишет существующий файл.", "你确定吗? 这样会覆盖原本的文件.", "저장하시겠습니까? 기존 파일을 덮어쓰게 됩니다.") \ X(LABEL_OVERWRITE_WARNING, "Overwrite Warning", "Alerta de Sobreescribir", "Предупреждение о перезаписи", "覆盖提醒", "덮어쓰기 경고") \ + X(LABEL_SERIALIZATION, "Serialization", "Serialization", "Serialization", "Serialization", "Serialization") \ + X(LABEL_EXTENDED_FORMAT, "Extended Format", "Extended Format", "Extended Format", "Extended Format", "Extended Format") \ X(LABEL_PAUSE, "Pause", "Pausar", "Пауза", "暂停", "일시정지") \ X(LABEL_PIVOTS, "Pivots", "Pivotes", "Точки вращения", "枢轴", "중심점") \ X(LABEL_PLAY, "Play", "Reproducir", "Возпроизвести", "播放", "재생") \ @@ -668,6 +670,7 @@ namespace anm2ed X(TOOLTIP_OVERLAY, "Set an animation to be drawn over the current animation.", "Ajusta una animacion para ser dibujada sobre la animacion actual.", "Установить анимацию, которая будет выведена над текущей анимацией.", "设置一个当前动画的覆盖动画.", "현재 애니메이션 위에 그려질 애니메이션을 설정합니다.") \ X(TOOLTIP_OVERLAY_ALPHA, "Set the alpha of the overlayed animation.", "Ajusta el alpha de la animacion en Overlay", "Установить прозрачность наложенной анимации.", "更改覆盖动画的透明度.", "오버레이된 애니메이션의 불투명도를 설정합니다.") \ X(TOOLTIP_OVERWRITE_WARNING, "A warning will be shown when saving/overwriting a file.", "Una advertencia se mostrara cuando se este guardando/sobreguardando un archivo.", "При сохранении/перезаписи файла будет показано предупреждение.", "保存或覆盖文件时会提示确认。", "저장하거나 덮어쓸 때 경고가 표시됩니다.") \ + X(TOOLTIP_EXTENDED_FORMAT, "Use extended Anm2Ed .anm2 format.\nThis is NOT compatible with The Binding of Isaac: Rebirth!", "Use extended Anm2Ed .anm2 format.\nThis is NOT compatible with The Binding of Isaac: Rebirth!", "Use extended Anm2Ed .anm2 format.\nThis is NOT compatible with The Binding of Isaac: Rebirth!", "Use extended Anm2Ed .anm2 format.\nThis is NOT compatible with The Binding of Isaac: Rebirth!", "Use extended Anm2Ed .anm2 format.\nThis is NOT compatible with The Binding of Isaac: Rebirth!") \ X(TOOLTIP_PAUSE_ANIMATION, "Pause the animation.", "Pausa la animacion.", "Поставить анимацию на паузу.", "暂停动画.", "애니메이션을 일시정지합니다.") \ X(TOOLTIP_PIVOT, "Change the pivot of the frame; i.e., where it is centered.", "Cambia el pivote del Frame; i. e., donde esta centrado.", "Изменить точку поворота кадра, т. е. где он центрирован.", "更改帧枢轴; 比如可以让帧枢轴居中.", "프레임의 중심점을 변경합니다.") \ X(TOOLTIP_PIVOTS, "Toggle the visibility of the animation's pivots.", "Alterna la visibilidad de los pivotes de la animacion.", "Переключить видимость точек поворота анимации.", "切换动画枢轴是否可见.", "애니메이션의 중심점을 표시하거나 숨깁니다.") \ diff --git a/src/settings.cpp b/src/settings.cpp index 1289f15..b487b43 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -322,6 +322,11 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1902,991 file.close(); } + Options Settings::anm2_options_get() const + { + return {.flags = SERIALIZE_DEFAULT, .isExtendedFormat = isFileExtendedFormat}; + } + std::string Settings::imgui_data_load(const std::filesystem::path& path) { auto pathUtf8 = path::to_utf8(path); diff --git a/src/settings.hpp b/src/settings.hpp index dfdf271..6536638 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -64,6 +64,7 @@ namespace anm2ed \ X(FILE_IS_AUTOSAVE, fileIsAutosave, STRING_UNDEFINED, BOOL, true) \ X(FILE_IS_WARN_OVERWRITE, fileIsWarnOverwrite, STRING_UNDEFINED, BOOL, true) \ + X(FILE_IS_EXTENDED_FORMAT, isFileExtendedFormat, STRING_UNDEFINED, BOOL, false) \ X(FILE_SNAPSHOT_STACK_SIZE, fileSnapshotStackSize, STRING_UNDEFINED, INT, 50) \ \ X(KEYBOARD_REPEAT_DELAY, keyboardRepeatDelay, STRING_UNDEFINED, FLOAT, 0.300f) \ @@ -299,6 +300,7 @@ namespace anm2ed Settings() = default; Settings(const std::filesystem::path&); + Options anm2_options_get() const; void save(const std::filesystem::path&, const std::string&); static std::string imgui_data_load(const std::filesystem::path&); };