Stage 7: typed model; Element tree is internal to model/xml.cpp

- src/model: typed Model (Info, Content, nested TrackGroup/AnimationGroup,
  copy-on-write shared animations, Extras/XmlNode passthrough for unknown XML,
  layout vectors so saves stay byte-identical).
- src/edit, Document, Selection, Snapshots, every window, the timeline, wizards
  and popups now read and edit model::Model; no UI code touches Element.
- anm2/ is reduced to the XML reader/writer/normalizer behind model/xml.cpp;
  dead Element operations (merge, regions, item_add, rect, frame helpers,
  element_get/unused, deserialize) are deleted.
- Goldens, invariants, undo walk and the local corpus (1,251 files) match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-03 16:53:17 -04:00
1 parent 2d0f70b1e5
commit 0b6f67d9bd
72 files changed
+4974 -4025

No files matched your search

+12 -12
View File
@@ -2,7 +2,8 @@
namespace anm2ed
{
std::set<Reference> selection_references_get(const Selection& selection, const UidIndex& index, SelectionKind kind)
std::set<Reference> selection_references_get(const Selection& selection, const model::UidIndex& index,
SelectionKind kind)
{
std::set<Reference> references{};
if (auto uids = selection.uids.find(kind); uids != selection.uids.end())
@@ -16,31 +17,31 @@ namespace anm2ed
return handle.frame ? handle.frame : handle.item ? handle.item : handle.animation;
}
void selection_references_set(Selection& selection, const Anm2& anm2, SelectionKind kind,
void selection_references_set(Selection& selection, const model::Model& model, SelectionKind kind,
const std::set<Reference>& references)
{
auto& uids = selection.uids[kind];
uids.clear();
for (auto reference : references)
if (auto uid = handle_uid_get(anm2.handle_get(reference, kind == SelectionKind::GROUPS))) uids.insert(uid);
if (auto uid = handle_uid_get(model.handle_get(reference, kind == SelectionKind::GROUPS))) uids.insert(uid);
}
// The most specific part of the focus that still exists.
Reference selection_focus_get(const Selection& selection, const UidIndex& index)
Reference selection_focus_get(const Selection& selection, const model::UidIndex& index)
{
for (auto uid : {selection.focus.frame, selection.focus.item, selection.focus.animation})
if (auto reference = index.reference_get(uid)) return *reference;
return {};
}
void selection_focus_set(Selection& selection, const Anm2& anm2, Reference reference)
void selection_focus_set(Selection& selection, const model::Model& model, Reference reference)
{
selection.focus = anm2.handle_get(reference);
selection.focus = model.handle_get(reference);
}
// After an edit: drops uids that no longer exist, and moves a focus whose element was removed to its nearest
// survivor (a frame at the same index of its track, the animation's root track, or the nearest animation).
void selection_follow(Selection& selection, const Anm2& anm2, const UidIndex& index, Reference before)
void selection_follow(Selection& selection, const model::Model& model, const model::UidIndex& index, Reference before)
{
for (auto& [kind, uids] : selection.uids)
std::erase_if(uids, [&](std::uint64_t uid) { return !index.contains(uid); });
@@ -51,8 +52,7 @@ namespace anm2ed
if (is_removed(animationUid) || !animationUid)
{
auto animations = anm2.element_get(ElementType::ANIMATIONS);
auto count = animations ? animations_count_get(*animations) : 0;
auto count = model.animations_count_get();
reference =
count > 0 && animationUid ? Reference{std::clamp(before.animationIndex, 0, count - 1), ROOT} : Reference{};
}
@@ -60,13 +60,13 @@ namespace anm2ed
reference = {reference.animationIndex, ROOT};
else if (is_removed(frameUid))
{
auto track = anm2.element_get(reference);
auto count = track ? track_frames_count_get(*track) : 0;
auto track = model.track_get(reference);
auto count = track ? (int)track->frames.size() : 0;
reference.frameIndex = count > 0 ? std::clamp(before.frameIndex, 0, count - 1) : -1;
}
else
return;
selection_focus_set(selection, anm2, reference);
selection_focus_set(selection, model, reference);
}
}