Stage 2: stable element uids and selection that follows edits

- Element::uid: runtime-only, unique per document (uids_repair on load and after
  every edit gives copies and new elements fresh uids; never serialized or hashed)
- Handle {animation, item, frame} uids and UidIndex (one walk: uid -> Reference)
- Snapshots capture the selection's handles when an edit starts and re-resolve the
  fields the edit left untouched on commit, undo and redo; replaces
  restored_snapshot_sanitize. Covers the main reference, frame/item/group
  references, timeline frame selection and the animation list selection.
- tests/selection.cpp: references survive inserts, copies, deletes, animation
  removal/reordering and regrouping

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-03 15:04:16 -04:00
1 parent 26ab394fe4
commit 20bfbace7a
7 files changed
+395 -77

No files matched your search

+24
View File
@@ -8,6 +8,7 @@
#include <string>
#include <string_view>
#include <type_traits>
#include <unordered_map>
#include <vector>
#include <glm/glm.hpp>
@@ -325,6 +326,7 @@ namespace anm2ed
std::vector<int> soundIds{};
std::vector<std::pair<std::string, std::string>> extraAttributes{};
std::string text{};
std::uint64_t uid{};
glm::vec2 pivot{};
glm::vec2 crop{};
glm::vec2 position{};
@@ -347,6 +349,16 @@ namespace anm2ed
auto operator<=>(const Reference&) const = default;
};
// A Reference expressed by runtime uids, so it survives inserts, deletes and moves.
struct Handle
{
std::uint64_t animation{};
std::uint64_t item{};
std::uint64_t frame{};
auto operator<=>(const Handle&) const = default;
};
struct TrackContainer
{
ItemType itemType;
@@ -573,5 +585,17 @@ namespace anm2ed
bool file_merge(const std::filesystem::path&, const std::filesystem::path&, FileMergePreset);
bool regions_generate(const std::set<int>&, const std::set<Reference>&, const std::string&, RegionFrameMapping);
void regions_scan();
void uids_repair();
Handle handle_get(Reference, bool = false) const;
};
// uid -> current Reference, built in one walk; group uids map to {animation, groupType, groupId}.
class UidIndex
{
std::unordered_map<std::uint64_t, Reference> locations{};
public:
explicit UidIndex(const Anm2&);
std::optional<Reference> reference_get(Handle, Reference) const;
};
}