diff --git a/src/anm2/anm2.cpp b/src/anm2/anm2.cpp index 8c13252..b081ecf 100644 --- a/src/anm2/anm2.cpp +++ b/src/anm2/anm2.cpp @@ -96,11 +96,14 @@ namespace anm2ed constexpr std::array ORIGIN_VALUES = {"", "TopLeft", "Center"}; constexpr std::string_view ANM2ED_GROUP_FRAME_BACKUP_TAG = "FrameRestore"; + constexpr std::string_view SOURCE_DOCUMENT_TAG = "SourceDocument"; void group_metadata_embed(Element&); void group_metadata_extract(Element&, Flags); void groups_flatten(Element&); + void groups_nest(Element&); void group_frames_restore(Element&); + void source_document_erase(Element&); void region_frame_ids_repair(Element&); Element* child_first_get(Element&, ElementType); const Element* child_first_get(const Element&, ElementType); @@ -146,6 +149,22 @@ namespace anm2ed return (int)animations.children.size(); } + bool is_source_document_tag(std::string_view tag) + { + return tag == SOURCE_DOCUMENT_TAG; + } + + const XMLElement* source_document_get(const XMLElement* rootElement) + { + if (!rootElement) return nullptr; + if (is_source_document_tag(rootElement->Name() ? rootElement->Name() : "")) return rootElement; + + for (auto child = rootElement->FirstChildElement(); child; child = child->NextSiblingElement()) + if (is_source_document_tag(child->Name() ? child->Name() : "")) return child; + + return nullptr; + } + bool anm2_document_load(Anm2& anm2, XMLDocument& document, std::string* errorString) { auto rootElement = document.RootElement(); @@ -156,7 +175,13 @@ namespace anm2ed return false; } - anm2.root = element_read(rootElement); + auto sourceElement = source_document_get(rootElement); + anm2.root = element_read(sourceElement ? sourceElement : rootElement); + if (sourceElement) + { + anm2.root.type = ElementType::ANIMATED_ACTOR; + anm2.root.tag = "AnimatedActor"; + } group_metadata_embed(anm2.root); group_frames_restore(anm2.root); groups_flatten(anm2.root); @@ -262,8 +287,7 @@ namespace anm2ed auto cos = std::cos(radians); auto sin = std::sin(radians); - frame.position = - rootFrame.position + glm::vec2(offset.x * cos - offset.y * sin, offset.x * sin + offset.y * cos); + frame.position = rootFrame.position + glm::vec2(offset.x * cos - offset.y * sin, offset.x * sin + offset.y * cos); frame.scale *= rootScale; frame.rotation += rootFrame.rotation; frame.tint *= rootFrame.tint; @@ -374,7 +398,7 @@ namespace anm2ed if (restoredGroupIds.empty()) return; std::erase_if(container.children, [&](const Element& item) - { return item.type == trackType && restoredGroupIds.contains(item.groupId); }); + { return item.type == trackType && restoredGroupIds.contains(item.groupId); }); } void group_frames_restore(Element& element) @@ -580,9 +604,25 @@ namespace anm2ed return out; } + bool is_nested_group_parent(ElementType parentType, Flags flags) + { + return has_flag(flags, SERIALIZE_NESTED_GROUPS) && + (parentType == ElementType::ANIMATIONS || parentType == ElementType::LAYER_ANIMATIONS || + parentType == ElementType::NULL_ANIMATIONS); + } + + bool is_group_id_serialized(Flags flags) + { + return has_flag(flags, SERIALIZE_GROUPS) && !has_flag(flags, SERIALIZE_NESTED_GROUPS); + } + bool element_write_skip(const Element& element, ElementType parentType, Flags flags) { if (!is_track_child_valid(parentType, element.type)) return true; + if ((element.type == ElementType::OVERLAY || element.type == ElementType::SHADER || + element.type == ElementType::UNIFORM || element.type == ElementType::COMPONENT) && + !has_flag(flags, SERIALIZE_EXTENSIONS)) + return true; if (element.type == ElementType::SOUNDS && (!has_flag(flags, SERIALIZE_SOUNDS) || element.children.empty())) return true; if ((element.type == ElementType::LAYER_ANIMATION_GROUPS || element.type == ElementType::NULL_ANIMATION_GROUPS) && @@ -691,7 +731,7 @@ namespace anm2ed } else if (element.type == ElementType::GROUP) { - out->SetAttribute("Id", element.id); + if (!is_nested_group_parent(parentType, flags)) out->SetAttribute("Id", element.id); out->SetAttribute("Name", element.name.c_str()); out->SetAttribute("IsExpanded", element.isExpanded); out->SetAttribute("Visible", element.isVisible); @@ -714,19 +754,19 @@ namespace anm2ed out->SetAttribute("Name", element.name.c_str()); out->SetAttribute("FrameNum", element.frameNum); out->SetAttribute("Loop", element.isLoop); - if (element.groupId != -1 && has_flag(flags, SERIALIZE_GROUPS)) out->SetAttribute("GroupId", element.groupId); + if (element.groupId != -1 && is_group_id_serialized(flags)) out->SetAttribute("GroupId", element.groupId); } else if (element.type == ElementType::LAYER_ANIMATION) { out->SetAttribute("LayerId", element.layerId); out->SetAttribute("Visible", element.isVisible); - if (element.groupId != -1 && has_flag(flags, SERIALIZE_GROUPS)) out->SetAttribute("GroupId", element.groupId); + if (element.groupId != -1 && is_group_id_serialized(flags)) out->SetAttribute("GroupId", element.groupId); } else if (element.type == ElementType::NULL_ANIMATION) { out->SetAttribute("NullId", element.nullId); out->SetAttribute("Visible", element.isVisible); - if (element.groupId != -1 && has_flag(flags, SERIALIZE_GROUPS)) out->SetAttribute("GroupId", element.groupId); + if (element.groupId != -1 && is_group_id_serialized(flags)) out->SetAttribute("GroupId", element.groupId); } else if (element.type == ElementType::FRAME) frame_attributes_write(out, element, parentType, flags); @@ -960,7 +1000,8 @@ namespace anm2ed { hash_attr_append(hash, "Id", element.id); hash_path_attr_append(hash, "Path", element.path); - if (element.type == ElementType::OVERLAY && !element.isVisible) hash_attr_append(hash, "Visible", element.isVisible); + if (element.type == ElementType::OVERLAY && !element.isVisible) + hash_attr_append(hash, "Visible", element.isVisible); } else if (element.type == ElementType::SHADER) { @@ -1004,7 +1045,7 @@ namespace anm2ed } else if (element.type == ElementType::GROUP) { - hash_attr_append(hash, "Id", element.id); + if (!is_nested_group_parent(parentType, flags)) hash_attr_append(hash, "Id", element.id); hash_attr_append(hash, "Name", element.name); hash_attr_append(hash, "IsExpanded", element.isExpanded); hash_attr_append(hash, "Visible", element.isVisible); @@ -1027,19 +1068,19 @@ namespace anm2ed hash_attr_append(hash, "Name", element.name); hash_attr_append(hash, "FrameNum", element.frameNum); hash_attr_append(hash, "Loop", element.isLoop); - if (element.groupId != -1 && has_flag(flags, SERIALIZE_GROUPS)) hash_attr_append(hash, "GroupId", element.groupId); + if (element.groupId != -1 && is_group_id_serialized(flags)) hash_attr_append(hash, "GroupId", element.groupId); } else if (element.type == ElementType::LAYER_ANIMATION) { hash_attr_append(hash, "LayerId", element.layerId); hash_attr_append(hash, "Visible", element.isVisible); - if (element.groupId != -1 && has_flag(flags, SERIALIZE_GROUPS)) hash_attr_append(hash, "GroupId", element.groupId); + if (element.groupId != -1 && is_group_id_serialized(flags)) hash_attr_append(hash, "GroupId", element.groupId); } else if (element.type == ElementType::NULL_ANIMATION) { hash_attr_append(hash, "NullId", element.nullId); hash_attr_append(hash, "Visible", element.isVisible); - if (element.groupId != -1 && has_flag(flags, SERIALIZE_GROUPS)) hash_attr_append(hash, "GroupId", element.groupId); + if (element.groupId != -1 && is_group_id_serialized(flags)) hash_attr_append(hash, "GroupId", element.groupId); } else if (element.type == ElementType::FRAME) frame_attributes_hash_append(hash, element, parentType, flags); @@ -1162,7 +1203,7 @@ namespace anm2ed for (const auto& group : groups) if (group.id >= 0) groupIds.insert(group.id); std::erase_if(container.children, [&](const Element& child) - { return child.type == ElementType::GROUP && groupIds.contains(child.id); }); + { return child.type == ElementType::GROUP && groupIds.contains(child.id); }); std::stable_sort(groups.begin(), groups.end(), [](const Element& left, const Element& right) @@ -1308,6 +1349,63 @@ namespace anm2ed groups_flatten(child); } + void group_children_nest(Element& container, ElementType childType) + { + if (childType == ElementType::UNKNOWN) return; + + std::set groupIds{}; + for (const auto& child : container.children) + if (child.type == ElementType::GROUP && child.id >= 0) groupIds.insert(child.id); + if (groupIds.empty()) return; + + std::unordered_map> groupedChildren{}; + for (const auto& child : container.children) + { + if (child.type != childType || !groupIds.contains(child.groupId)) continue; + auto groupedChild = child; + groupedChild.groupId = -1; + groupedChildren[child.groupId].push_back(std::move(groupedChild)); + } + + std::vector nested{}; + nested.reserve(container.children.size()); + for (auto child : container.children) + { + if (child.type == childType && groupIds.contains(child.groupId)) continue; + if (child.type == ElementType::GROUP) + { + auto groupId = child.id; + child.index = -1; + if (auto grouped = groupedChildren.find(groupId); grouped != groupedChildren.end()) + child.children.insert(child.children.end(), std::make_move_iterator(grouped->second.begin()), + std::make_move_iterator(grouped->second.end())); + } + nested.push_back(std::move(child)); + } + + container.children = std::move(nested); + } + + void groups_nest(Element& element) + { + if (element.type == ElementType::ANIMATIONS) + group_children_nest(element, ElementType::ANIMATION); + else if (element.type == ElementType::LAYER_ANIMATIONS) + group_children_nest(element, ElementType::LAYER_ANIMATION); + else if (element.type == ElementType::NULL_ANIMATIONS) + group_children_nest(element, ElementType::NULL_ANIMATION); + + for (auto& child : element.children) + groups_nest(child); + } + + void source_document_erase(Element& element) + { + std::erase_if(element.children, [](const Element& child) { return is_source_document_tag(child.tag); }); + for (auto& child : element.children) + source_document_erase(child); + } + Element* child_first_get(Element& element, ElementType type) { for (auto& child : element.children) @@ -1599,37 +1697,40 @@ namespace anm2ed auto layerAnimations = child_first_get(animation, ElementType::LAYER_ANIMATIONS); if (!layerAnimations) continue; - tracks_each(*layerAnimations, ElementType::LAYER_ANIMATION, [&](Element& layerAnimation) - { - auto layer = child_id_get(*layers, ElementType::LAYER_ELEMENT, layerAnimation.layerId); - auto spritesheet = - layer ? child_id_get(*spritesheets, ElementType::SPRITESHEET, layer->spritesheetId) : nullptr; - if (!spritesheet) return; + tracks_each(*layerAnimations, ElementType::LAYER_ANIMATION, + [&](Element& layerAnimation) + { + auto layer = child_id_get(*layers, ElementType::LAYER_ELEMENT, layerAnimation.layerId); + auto spritesheet = + layer ? child_id_get(*spritesheets, ElementType::SPRITESHEET, layer->spritesheetId) : nullptr; + if (!spritesheet) return; - for (auto& frame : layerAnimation.children) - { - if (frame.type != ElementType::FRAME) continue; + for (auto& frame : layerAnimation.children) + { + if (frame.type != ElementType::FRAME) continue; - auto frameCrop = glm::ivec2(frame.crop); - auto frameSize = glm::ivec2(frame.size); - auto framePivot = glm::ivec2(frame.pivot); - auto is_region_match = [&](const Element& region) - { - return region.type == ElementType::REGION && glm::ivec2(region.crop) == frameCrop && - glm::ivec2(region.size) == frameSize && glm::ivec2(region.pivot) == framePivot; - }; + auto frameCrop = glm::ivec2(frame.crop); + auto frameSize = glm::ivec2(frame.size); + auto framePivot = glm::ivec2(frame.pivot); + auto is_region_match = [&](const Element& region) + { + return region.type == ElementType::REGION && glm::ivec2(region.crop) == frameCrop && + glm::ivec2(region.size) == frameSize && glm::ivec2(region.pivot) == framePivot; + }; - auto region = frame.regionId == -1 ? nullptr : child_id_get(*spritesheet, ElementType::REGION, frame.regionId); - if (region && is_region_match(*region)) continue; + auto region = frame.regionId == -1 + ? nullptr + : child_id_get(*spritesheet, ElementType::REGION, frame.regionId); + if (region && is_region_match(*region)) continue; - for (const auto& candidate : spritesheet->children) - if (is_region_match(candidate)) - { - frame.regionId = candidate.id; - break; - } - } - }); + for (const auto& candidate : spritesheet->children) + if (is_region_match(candidate)) + { + frame.regionId = candidate.id; + break; + } + } + }); } } @@ -2055,13 +2156,26 @@ namespace anm2ed return false; } - void track_frames_bake(Element& track, int interval, bool isRoundScale, bool isRoundRotation) + enum class InterpolationBakeType + { + SPECIAL, + ALL + }; + + bool is_frame_interpolation_baked(const Element& frame, InterpolationBakeType type) + { + if (frame.interpolation == Interpolation::NONE) return false; + return type == InterpolationBakeType::ALL || frame.interpolation != Interpolation::LINEAR; + } + + void track_frames_bake(Element& track, int interval, bool isRoundScale, bool isRoundRotation, + InterpolationBakeType type) { for (int index = (int)track.children.size() - 1; index >= 0; --index) { auto original = track.children[index]; if (original.type != ElementType::FRAME) continue; - if (original.interpolation == Interpolation::NONE || original.interpolation == Interpolation::LINEAR) continue; + if (!is_frame_interpolation_baked(original, type)) continue; if (original.duration <= FRAME_DURATION_MIN) { @@ -2100,16 +2214,27 @@ namespace anm2ed } } - void special_interpolated_frames_bake(Element& element, int interval, bool isRoundScale, bool isRoundRotation) + void interpolated_frames_bake(Element& element, int interval, bool isRoundScale, bool isRoundRotation, + InterpolationBakeType type) { if (is_track(element)) { - track_frames_bake(element, interval, isRoundScale, isRoundRotation); + track_frames_bake(element, interval, isRoundScale, isRoundRotation, type); return; } for (auto& child : element.children) - special_interpolated_frames_bake(child, interval, isRoundScale, isRoundRotation); + interpolated_frames_bake(child, interval, isRoundScale, isRoundRotation, type); + } + + void special_interpolated_frames_bake(Element& element, int interval, bool isRoundScale, bool isRoundRotation) + { + interpolated_frames_bake(element, interval, isRoundScale, isRoundRotation, InterpolationBakeType::SPECIAL); + } + + void all_interpolated_frames_bake(Element& element, int interval, bool isRoundScale, bool isRoundRotation) + { + interpolated_frames_bake(element, interval, isRoundScale, isRoundRotation, InterpolationBakeType::ALL); } void layer_animation_ids_remap(Element& element, const std::unordered_map& remap) @@ -2205,16 +2330,28 @@ namespace anm2ed XMLElement* Anm2::to_element(XMLDocument& document, Options options) const { - auto serialized = normalized_for_serialize(options.flags); - serialized.region_frames_sync(true); - return element_to_xml(document, serialized.root, ElementType::UNKNOWN, options.flags); + (void)options; + + auto isaac = normalized_for_serialize(SERIALIZE_ISAAC_DEFAULT); + isaac.region_frames_sync(true); + auto out = element_to_xml(document, isaac.root, ElementType::UNKNOWN, SERIALIZE_ISAAC_DEFAULT); + + auto editor = normalized_for_serialize(SERIALIZE_ANM2ED_DEFAULT); + editor.region_frames_sync(true); + auto extension = element_to_xml(document, editor.root, ElementType::UNKNOWN, SERIALIZE_ANM2ED_DEFAULT); + extension->SetName(SOURCE_DOCUMENT_TAG.data()); + out->InsertEndChild(extension); + + return out; } std::uint64_t Anm2::hash(Options options) const { - auto serialized = normalized_for_serialize(options.flags); - serialized.region_frames_sync(true); - return element_hash(serialized.root, options.flags); + auto serialized = to_string(options); + auto hash = ANM2_HASH_OFFSET; + for (auto c : serialized) + hash_byte_append(hash, (unsigned char)c); + return hash; } bool Anm2::is_special_interpolated_frames() const { return ::anm2ed::is_special_interpolated_frames(root); } @@ -2239,38 +2376,45 @@ namespace anm2ed auto layerAnimations = child_first_get(animation, ElementType::LAYER_ANIMATIONS); if (!layerAnimations) continue; - tracks_each(*layerAnimations, ElementType::LAYER_ANIMATION, [&](Element& layerAnimation) - { - auto layer = child_id_get(*layers, ElementType::LAYER_ELEMENT, layerAnimation.layerId); - auto spritesheet = - layer ? child_id_get(*spritesheets, ElementType::SPRITESHEET, layer->spritesheetId) : nullptr; - if (!spritesheet) return; + tracks_each(*layerAnimations, ElementType::LAYER_ANIMATION, + [&](Element& layerAnimation) + { + auto layer = child_id_get(*layers, ElementType::LAYER_ELEMENT, layerAnimation.layerId); + auto spritesheet = + layer ? child_id_get(*spritesheets, ElementType::SPRITESHEET, layer->spritesheetId) : nullptr; + if (!spritesheet) return; - for (auto& frame : layerAnimation.children) - { - if (frame.type != ElementType::FRAME || frame.regionId == -1) continue; - auto region = child_id_get(*spritesheet, ElementType::REGION, frame.regionId); - if (!region) - { - if (isClearInvalid) frame.regionId = -1; - continue; - } + for (auto& frame : layerAnimation.children) + { + if (frame.type != ElementType::FRAME || frame.regionId == -1) continue; + auto region = child_id_get(*spritesheet, ElementType::REGION, frame.regionId); + if (!region) + { + if (isClearInvalid) frame.regionId = -1; + continue; + } - frame.crop = region->crop; - frame.size = region->size; - frame.pivot = region->pivot; - } - }); + frame.crop = region->crop; + frame.size = region->size; + frame.pivot = region->pivot; + } + }); } } Anm2 Anm2::normalized_for_serialize(Flags flags) const { auto normalized = *this; + source_document_erase(normalized.root); group_frames_restore(normalized.root); groups_flatten(normalized.root); if (has_flag(flags, SERIALIZE_BAKE_GROUP_FRAMES)) group_frames_bake(normalized.root); - group_metadata_extract(normalized.root, flags); + if (has_flag(flags, SERIALIZE_FLATTEN_SPECIAL_INTERPOLATED_FRAMES)) + all_interpolated_frames_bake(normalized.root, FRAME_DURATION_MIN, false, false); + if (has_flag(flags, SERIALIZE_GROUPS) && has_flag(flags, SERIALIZE_NESTED_GROUPS)) + groups_nest(normalized.root); + else + group_metadata_extract(normalized.root, flags); auto content = child_first_get(normalized.root, ElementType::CONTENT); if (content) std::erase_if(content->children, [](const Element& element) { return element.tag == "Groups"; }); @@ -2407,8 +2551,8 @@ namespace anm2ed Element* Anm2::element_get(Reference reference) { auto itemType = static_cast(reference.itemType); - auto item = element_get(reference.animationIndex, itemType, reference.itemID, reference.groupType, - reference.groupId); + auto item = + element_get(reference.animationIndex, itemType, reference.itemID, reference.groupType, reference.groupId); if (reference.frameIndex < 0) return item; return item ? track_frame_get(*item, reference.frameIndex) : nullptr; } @@ -2416,8 +2560,8 @@ namespace anm2ed const Element* Anm2::element_get(Reference reference) const { auto itemType = static_cast(reference.itemType); - auto item = element_get(reference.animationIndex, itemType, reference.itemID, reference.groupType, - reference.groupId); + auto item = + element_get(reference.animationIndex, itemType, reference.itemID, reference.groupType, reference.groupId); if (reference.frameIndex < 0) return item; return item ? track_frame_get(*item, reference.frameIndex) : nullptr; } @@ -2519,11 +2663,12 @@ namespace anm2ed if (animation.type != ElementType::ANIMATION) continue; auto layerAnimations = child_first_get(animation, ElementType::LAYER_ANIMATIONS); if (!layerAnimations) continue; - tracks_each(*layerAnimations, ElementType::LAYER_ANIMATION, [&](const Element& layerAnimation) - { - for (const auto& frame : layerAnimation.children) - if (frame.type == ElementType::FRAME && frame.regionId != -1) used.insert(frame.regionId); - }); + tracks_each(*layerAnimations, ElementType::LAYER_ANIMATION, + [&](const Element& layerAnimation) + { + for (const auto& frame : layerAnimation.children) + if (frame.type == ElementType::FRAME && frame.regionId != -1) used.insert(frame.regionId); + }); } std::set unused{}; @@ -2660,36 +2805,38 @@ namespace anm2ed auto layerAnimations = child_first_get(animation, ElementType::LAYER_ANIMATIONS); if (!layerAnimations) continue; - tracks_each(*layerAnimations, ElementType::LAYER_ANIMATION, [&](const Element& layerAnimation) - { - if (!layerAnimation.isVisible || !is_track_group_visible(*layerAnimations, layerAnimation)) return; + tracks_each(*layerAnimations, ElementType::LAYER_ANIMATION, + [&](const Element& layerAnimation) + { + if (!layerAnimation.isVisible || !is_track_group_visible(*layerAnimations, layerAnimation)) return; - auto itemTransform = transform; - if (isRootTransform && layerAnimation.groupId != -1) - if (auto group = child_id_get(*layerAnimations, ElementType::GROUP, layerAnimation.groupId)) - if (auto groupRoot = child_first_get(*group, ElementType::ROOT_ANIMATION)) - { - auto groupRootFrame = frame_generate(*groupRoot, t); - itemTransform *= math::quad_model_parent_get(groupRootFrame.position, {}, - math::percent_to_unit(groupRootFrame.scale), - groupRootFrame.rotation); - } + auto itemTransform = transform; + if (isRootTransform && layerAnimation.groupId != -1) + if (auto group = child_id_get(*layerAnimations, ElementType::GROUP, layerAnimation.groupId)) + if (auto groupRoot = child_first_get(*group, ElementType::ROOT_ANIMATION)) + { + auto groupRootFrame = frame_generate(*groupRoot, t); + itemTransform *= math::quad_model_parent_get(groupRootFrame.position, {}, + math::percent_to_unit(groupRootFrame.scale), + groupRootFrame.rotation); + } - auto frame = frame_effective(layerAnimation.layerId, frame_generate(layerAnimation, t)); - if (frame.size == glm::vec2() || !frame.isVisible) return; + auto frame = frame_effective(layerAnimation.layerId, frame_generate(layerAnimation, t)); + if (frame.size == glm::vec2() || !frame.isVisible) return; - auto layerTransform = itemTransform * math::quad_model_get(frame.size, frame.position, frame.pivot, - math::percent_to_unit(frame.scale), frame.rotation); - for (auto& corner : CORNERS) - { - auto world = layerTransform * glm::vec4(corner, 0.0f, 1.0f); - minX = std::min(minX, world.x); - minY = std::min(minY, world.y); - maxX = std::max(maxX, world.x); - maxY = std::max(maxY, world.y); - isAny = true; - } - }); + auto layerTransform = + itemTransform * math::quad_model_get(frame.size, frame.position, frame.pivot, + math::percent_to_unit(frame.scale), frame.rotation); + for (auto& corner : CORNERS) + { + auto world = layerTransform * glm::vec4(corner, 0.0f, 1.0f); + minX = std::min(minX, world.x); + minY = std::min(minY, world.y); + maxX = std::max(maxX, world.x); + maxY = std::max(maxY, world.y); + isAny = true; + } + }); } if (!isAny) return glm::vec4(-1.0f); diff --git a/src/anm2/anm2.hpp b/src/anm2/anm2.hpp index 27ea07c..6bf8a9d 100644 --- a/src/anm2/anm2.hpp +++ b/src/anm2/anm2.hpp @@ -188,16 +188,22 @@ namespace anm2ed SERIALIZE_SOUNDS = 1 << 2, SERIALIZE_REDUNDANT_FRAME_REGION_VALUES = 1 << 3, SERIALIZE_BAKE_SPECIAL_INTERPOLATED_FRAMES = 1 << 4, - SERIALIZE_BAKE_GROUP_FRAMES = 1 << 5 + SERIALIZE_BAKE_GROUP_FRAMES = 1 << 5, + SERIALIZE_NESTED_GROUPS = 1 << 6, + SERIALIZE_EXTENSIONS = 1 << 7, + SERIALIZE_FLATTEN_SPECIAL_INTERPOLATED_FRAMES = 1 << 8 }; using Flags = int; constexpr bool has_flag(Flags flags, Flag flag) { return (flags & flag) != 0; } - constexpr Flags SERIALIZE_EDITOR_DEFAULT = - SERIALIZE_GROUPS | SERIALIZE_REGIONS | SERIALIZE_SOUNDS | SERIALIZE_REDUNDANT_FRAME_REGION_VALUES; + constexpr Flags SERIALIZE_EDITOR_DEFAULT = SERIALIZE_GROUPS | SERIALIZE_REGIONS | SERIALIZE_SOUNDS | + SERIALIZE_REDUNDANT_FRAME_REGION_VALUES | SERIALIZE_EXTENSIONS; constexpr Flags SERIALIZE_DEFAULT = SERIALIZE_EDITOR_DEFAULT | SERIALIZE_BAKE_SPECIAL_INTERPOLATED_FRAMES | SERIALIZE_BAKE_GROUP_FRAMES; + constexpr Flags SERIALIZE_ISAAC_DEFAULT = SERIALIZE_BAKE_GROUP_FRAMES | SERIALIZE_FLATTEN_SPECIAL_INTERPOLATED_FRAMES; + constexpr Flags SERIALIZE_ANM2ED_DEFAULT = + SERIALIZE_GROUPS | SERIALIZE_REGIONS | SERIALIZE_SOUNDS | SERIALIZE_NESTED_GROUPS | SERIALIZE_EXTENSIONS; struct Options { diff --git a/src/imgui/documents.cpp b/src/imgui/documents.cpp index 192a898..8466b51 100644 --- a/src/imgui/documents.cpp +++ b/src/imgui/documents.cpp @@ -46,15 +46,6 @@ namespace anm2ed::imgui #undef ANM2_DRAG_DROP_MERGE_PRESETS - Options save_options_get(const Settings& settings) - { - Flags flags{SERIALIZE_GROUPS | SERIALIZE_REGIONS | SERIALIZE_SOUNDS}; - if (settings.fileIsKeepRedundantFrameRegionValues) flags |= SERIALIZE_REDUNDANT_FRAME_REGION_VALUES; - if (settings.fileIsBakeSpecialInterpolatedFrames) flags |= SERIALIZE_BAKE_SPECIAL_INTERPOLATED_FRAMES; - if (settings.isFileBakeGroupFrames) flags |= SERIALIZE_BAKE_GROUP_FRAMES; - return {.flags = flags}; - } - void anm2_drag_drop_merge_queue(Manager& manager, const std::vector& paths, Document::FileMergePreset preset) { @@ -159,10 +150,7 @@ namespace anm2ed::imgui document.lastAutosaveTime += ImGui::GetIO().DeltaTime; if (document.lastAutosaveTime > time::SECOND_M) { - auto options = save_options_get(settings); - manager.command_push({i, - [options](Manager& manager, Document& document) - { manager.autosave(document, options); }}); + manager.command_push({i, [](Manager& manager, Document& document) { manager.autosave(document); }}); } } } diff --git a/src/imgui/taskbar.cpp b/src/imgui/taskbar.cpp index 3e7c4ae..04f38c2 100644 --- a/src/imgui/taskbar.cpp +++ b/src/imgui/taskbar.cpp @@ -27,44 +27,35 @@ namespace anm2ed::imgui constexpr auto GENERATE_REGIONS_TARGET_SELECTION = 0; constexpr auto GENERATE_REGIONS_TARGET_ALL = 1; - Options save_options_get(Settings& settings) + bool Taskbar::save_execute(Manager& manager, const PendingSave& request) { - Flags flags{SERIALIZE_GROUPS | SERIALIZE_REGIONS | SERIALIZE_SOUNDS}; - if (settings.fileIsKeepRedundantFrameRegionValues) flags |= SERIALIZE_REDUNDANT_FRAME_REGION_VALUES; - if (settings.fileIsBakeSpecialInterpolatedFrames) flags |= SERIALIZE_BAKE_SPECIAL_INTERPOLATED_FRAMES; - if (settings.isFileBakeGroupFrames) flags |= SERIALIZE_BAKE_GROUP_FRAMES; - return {.flags = flags}; + return manager.save(request.index, request.path); } - bool Taskbar::save_execute(Manager& manager, Settings& settings, const PendingSave& request) - { - return manager.save(request.index, request.path, save_options_get(settings)); - } - - void Taskbar::save_enqueue(Manager& manager, Settings& settings, const PendingSave& request) + void Taskbar::save_enqueue(Manager& manager, const PendingSave& request) { auto index = request.index; auto path = request.path; - auto options = save_options_get(settings); manager.command_push({.runManager = [=](Manager& manager) - { manager.save(index, path, options); }}); + { manager.save(index, path); }}); } 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}; if (isQueued) { - save_enqueue(manager, settings, request); + save_enqueue(manager, request); return true; } - return save_execute(manager, settings, request); + return save_execute(manager, request); } bool Taskbar::save_manual(Manager& manager, Settings& settings, int index, const std::filesystem::path& path) diff --git a/src/imgui/taskbar.hpp b/src/imgui/taskbar.hpp index 74604a9..0eaacce 100644 --- a/src/imgui/taskbar.hpp +++ b/src/imgui/taskbar.hpp @@ -47,8 +47,8 @@ namespace anm2ed::imgui bool isGenerateRegionsMapFrames{true}; bool isQuittingMode{}; - bool save_execute(Manager&, Settings&, const PendingSave&); - void save_enqueue(Manager&, Settings&, const PendingSave&); + bool save_execute(Manager&, const PendingSave&); + void save_enqueue(Manager&, const PendingSave&); bool save_request(Manager&, Settings&, int = -1, const std::filesystem::path& = {}, bool = false); public: diff --git a/src/imgui/wizard/configure.cpp b/src/imgui/wizard/configure.cpp index dd718b5..131a9e9 100644 --- a/src/imgui/wizard/configure.cpp +++ b/src/imgui/wizard/configure.cpp @@ -68,18 +68,6 @@ namespace anm2ed::imgui::wizard input_int_range(localize.get(LABEL_STACK_SIZE), temporary.fileSnapshotStackSize, 0, 100); ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_STACK_SIZE)); - ImGui::SeparatorText(localize.get(LABEL_SERIALIZATION)); - ImGui::Checkbox(localize.get(LABEL_KEEP_REDUNDANT_FRAME_REGION_VALUES), - &temporary.fileIsKeepRedundantFrameRegionValues); - ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_KEEP_REDUNDANT_FRAME_REGION_VALUES)); - - ImGui::Checkbox(localize.get(LABEL_BAKE_SPECIAL_INTERPOLATED_FRAMES_ON_SAVE), - &temporary.fileIsBakeSpecialInterpolatedFrames); - ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_BAKE_SPECIAL_INTERPOLATED_FRAMES_ON_SAVE)); - - ImGui::Checkbox(localize.get(LABEL_BAKE_GROUP_FRAMES_ON_SAVE), &temporary.isFileBakeGroupFrames); - ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_BAKE_GROUP_FRAMES_ON_SAVE)); - ImGui::SeparatorText(localize.get(LABEL_OPTIONS)); ImGui::Checkbox(localize.get(LABEL_OVERWRITE_WARNING), &temporary.fileIsWarnOverwrite); ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_OVERWRITE_WARNING)); diff --git a/src/resource/strings.hpp b/src/resource/strings.hpp index cc61f44..7bc485f 100644 --- a/src/resource/strings.hpp +++ b/src/resource/strings.hpp @@ -270,12 +270,8 @@ namespace anm2ed X(LABEL_CLEAR_LIST, "Clear List", "Limpiar Lista", "Стереть список", "清除列表", "기록 삭제") \ X(LABEL_CLOSE, "Close", "Cerrar", "Закрыть", "关闭", "닫기") \ X(LABEL_CURRENT_SELECTION, "Current Selection", "Selección actual", "Текущее выделение", "当前选择", "현재 선택") \ - X(LABEL_SERIALIZATION, "Serialization", "Serialización", "Сериализация", "序列化", "직렬화") \ X(LABEL_GROUPS, "Groups", "Grupos", "Группы", "组", "그룹") \ X(LABEL_REGIONS, "Regions", "Regiones", "Регионы", "区域", "영역") \ - X(LABEL_KEEP_REDUNDANT_FRAME_REGION_VALUES, "Keep redundant frame information for frames with regions", "Mantener información redundante en frames con regiones", "Сохранять избыточные данные кадров с регионами", "保留带区域帧的冗余信息", "영역이 있는 프레임의 중복 정보 유지") \ - X(LABEL_BAKE_SPECIAL_INTERPOLATED_FRAMES_ON_SAVE, "Automatically bake frames with special interpolation modes", "Hornear frames con interpolación especial al guardar", "Запекать кадры со специальной интерполяцией при сохранении", "保存时烘焙特殊插值帧", "저장 시 특수 보간 프레임 베이크") \ - X(LABEL_BAKE_GROUP_FRAMES_ON_SAVE, "Bake frames inside groups if applicable", "Hornear frames dentro de grupos si corresponde", "Запекать кадры внутри групп при необходимости", "适用时烘焙组内帧", "필요 시 그룹 안의 프레임 베이크") \ X(LABEL_CUSTOM_RANGE, "Custom Range", "Rango Personalizado", "Пользовательский диапазон", "自定义范围", "길이 맞춤설정") \ X(LABEL_DELETE, "Delete", "Borrar", "Удалить", "删除", "삭제") \ X(LABEL_DELETE_ANIMATIONS_AFTER, "Delete Animations After", "Borrar Animaciones Despues", "Удалить анимации после", "删除之后的动画", "기존 애니메이션 삭제") \ @@ -604,9 +600,6 @@ namespace anm2ed X(TOOLTIP_CHANGE_ALL_NULLS, "The frame property changes will apply to null frames.", "Los cambios de propiedades de frame se aplicaran a los frames null.", "Изменения свойств кадра будут применены к нулевым кадрам.", "帧属性更改将应用于 Null 帧。", "프레임 속성 변경 사항을 Null 프레임에 적용합니다.") \ X(TOOLTIP_CENTER_VIEW, "Centers the view.", "Centra la vista.", "Центрирует вид.", "居中视角.", "미리보기 화면을 가운데에 맞춥니다.") \ X(TOOLTIP_CLOSE_SETTINGS, "Close without updating settings.", "Cerrar sin actualizar las configuraciones.", "Закрыть без обновления настройки.", "关闭但不保存设置.", "설정을 갱신하지 않고 닫습니다.") \ - X(TOOLTIP_KEEP_REDUNDANT_FRAME_REGION_VALUES, "Keep crop, size, and pivot values on frames with regions.\nIf disabled, The Binding of Isaac: Rebirth may have parsing or playback issues.", "Mantiene los valores de recorte, tamaño y pivote en frames con regiones.\nSi se desactiva, The Binding of Isaac: Rebirth puede tener problemas de análisis o reproducción.", "Сохраняет значения обрезки, размера и точки вращения в кадрах с регионами.\nЕсли отключить, в The Binding of Isaac: Rebirth возможны проблемы разбора или воспроизведения.", "保留带区域帧的裁剪、大小和枢轴值。\n如果禁用,The Binding of Isaac: Rebirth 可能出现解析或播放问题。", "영역이 있는 프레임의 자르기, 크기, 중심점 값을 유지합니다.\n끄면 The Binding of Isaac: Rebirth에서 파싱 또는 재생 문제가 생길 수 있습니다.") \ - X(TOOLTIP_BAKE_SPECIAL_INTERPOLATED_FRAMES_ON_SAVE, "Bake frames with special interpolation modes only in the saved file.\nIf disabled, The Binding of Isaac: Rebirth may have parsing or playback issues.", "Hornea frames con modos de interpolación especial solo en el archivo guardado.\nSi se desactiva, The Binding of Isaac: Rebirth puede tener problemas de análisis o reproducción.", "Запекает кадры со специальными режимами интерполяции только в сохраняемом файле.\nЕсли отключить, в The Binding of Isaac: Rebirth возможны проблемы разбора или воспроизведения.", "仅在保存的文件中烘焙带特殊插值模式的帧。\n如果禁用,The Binding of Isaac: Rebirth 可能出现解析或播放问题。", "저장되는 파일에서만 특수 보간 모드 프레임을 베이크합니다.\n끄면 The Binding of Isaac: Rebirth에서 파싱 또는 재생 문제가 생길 수 있습니다.") \ - X(TOOLTIP_BAKE_GROUP_FRAMES_ON_SAVE, "Bake child layer/null frames when their group root has non-default transform or color values.\nIf disabled, The Binding of Isaac: Rebirth may have parsing or playback issues.", "Hornea frames de capas/null hijos cuando la raíz del grupo tenga transformaciones o valores de color no predeterminados.\nSi se desactiva, The Binding of Isaac: Rebirth puede tener problemas de análisis o reproducción.", "Запекает дочерние кадры слоев/null, когда корень группы имеет нестандартные преобразования или цветовые значения.\nЕсли отключить, в The Binding of Isaac: Rebirth возможны проблемы разбора или воспроизведения.", "当组根具有非默认变换或颜色值时,烘焙子图层/null 帧。\n如果禁用,The Binding of Isaac: Rebirth 可能出现解析或播放问题。", "그룹 루트에 기본값이 아닌 변형 또는 색상 값이 있을 때 하위 레이어/null 프레임을 베이크합니다.\n끄면 The Binding of Isaac: Rebirth에서 파싱 또는 재생 문제가 생길 수 있습니다.") \ X(TOOLTIP_COLOR_OFFSET, "Change the color added onto the frame.", "Cambia el color añadido al Frame.", "Изменить цвет, который добавлен на кадр.", "更改覆盖在帧上的颜色.", "프레임에 더해지는 색을 변경합니다.") \ X(TOOLTIP_REGION, "Set the spritesheet region the frame will use.", "Establece la región del spritesheet que usará el frame.", "Установить регион спрайт-листа, который будет использовать кадр.", "设置帧将使用的图集区域.", "프레임이 사용할 스프라이트 시트 영역을 설정합니다.") \ X(TOOLTIP_REGION_PROPERTIES_ORIGIN, "Use a preset origin for the region.", "Usa un origen predefinido para la región.", "Использовать предустановленную точку отсчета для региона.", "为区域使用预设原点。", "영역에 사전 설정된 원점을 사용합니다.") \ diff --git a/src/settings.hpp b/src/settings.hpp index f322ce2..dfdf271 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -65,9 +65,6 @@ namespace anm2ed X(FILE_IS_AUTOSAVE, fileIsAutosave, STRING_UNDEFINED, BOOL, true) \ X(FILE_IS_WARN_OVERWRITE, fileIsWarnOverwrite, STRING_UNDEFINED, BOOL, true) \ X(FILE_SNAPSHOT_STACK_SIZE, fileSnapshotStackSize, STRING_UNDEFINED, INT, 50) \ - X(FILE_IS_KEEP_REDUNDANT_FRAME_REGION_VALUES, fileIsKeepRedundantFrameRegionValues, STRING_UNDEFINED, BOOL, true) \ - X(FILE_IS_BAKE_SPECIAL_INTERPOLATED_FRAMES, fileIsBakeSpecialInterpolatedFrames, STRING_UNDEFINED, BOOL, true) \ - X(IS_FILE_BAKE_GROUP_FRAMES, isFileBakeGroupFrames, STRING_UNDEFINED, BOOL, true) \ \ X(KEYBOARD_REPEAT_DELAY, keyboardRepeatDelay, STRING_UNDEFINED, FLOAT, 0.300f) \ X(KEYBOARD_REPEAT_RATE, keyboardRepeatRate, STRING_UNDEFINED, FLOAT, 0.050f) \