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:
1 parent
2d0f70b1e5
commit
0b6f67d9bd
72 files changed
+4974
-4025
No files matched your search
+24
-24
@@ -6,31 +6,32 @@
|
||||
using namespace anm2ed;
|
||||
using namespace anm2ed::test;
|
||||
|
||||
Anm2 fixture_load_with_uids(const char* name)
|
||||
{
|
||||
auto anm2 = anm2_load(file_load(CORPUS_DIR / name));
|
||||
anm2.uids_repair();
|
||||
return anm2;
|
||||
}
|
||||
model::Model fixture_load_with_uids(const char* name) { return model_load(file_load(CORPUS_DIR / name)); }
|
||||
|
||||
// Applies an edit and follows the selection through it, the way a commit does.
|
||||
void selection_edit(Anm2& anm2, Selection& selection, auto&& edit)
|
||||
void selection_edit(model::Model& anm2, Selection& selection, auto&& edit)
|
||||
{
|
||||
auto before = selection_focus_get(selection, UidIndex(anm2));
|
||||
auto before = selection_focus_get(selection, model::UidIndex(anm2));
|
||||
edit();
|
||||
anm2.uids_repair();
|
||||
selection_follow(selection, anm2, UidIndex(anm2), before);
|
||||
selection_follow(selection, anm2, model::UidIndex(anm2), before);
|
||||
}
|
||||
|
||||
TEST_CASE("uids are unique and non-zero after load")
|
||||
{
|
||||
for (const auto& fixture : fixtures_get())
|
||||
{
|
||||
auto anm2 = anm2_load(file_load(fixture));
|
||||
auto anm2 = model_load(file_load(fixture));
|
||||
std::set<std::uint64_t> uids{};
|
||||
bool isUnique{true};
|
||||
element_each(anm2.root,
|
||||
[&](const Element& element) { isUnique &= element.uid != 0 && uids.insert(element.uid).second; });
|
||||
for (auto [index, animation] : anm2.animations_get())
|
||||
model::animation_tracks_each(*animation,
|
||||
[&](const model::Track& track)
|
||||
{
|
||||
isUnique &= uids.insert(track.uid).second;
|
||||
for (const auto& frame : track.frames)
|
||||
isUnique &= uids.insert(frame.uid).second;
|
||||
});
|
||||
INFO("fixture: ", fixture.filename().string());
|
||||
CHECK(isUnique);
|
||||
}
|
||||
@@ -46,7 +47,7 @@ TEST_CASE("selected frames and focus follow inserts and moves")
|
||||
selection_edit(anm2, selection, [&] { edit::frame_insert(anm2, {0, LAYER, 0, -1}, 0); });
|
||||
selection_edit(anm2, selection, [&] { edit::frames_reverse(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 0, 1}}); });
|
||||
|
||||
UidIndex index(anm2);
|
||||
model::UidIndex index(anm2);
|
||||
CHECK(selection_focus_get(selection, index) == Reference{0, LAYER, 0, 0});
|
||||
CHECK(selection_references_get(selection, index, SelectionKind::FRAMES) ==
|
||||
std::set<Reference>{{0, LAYER, 0, 0}, {0, LAYER, 1, 0}});
|
||||
@@ -60,33 +61,32 @@ TEST_CASE("a removed focus falls back to its nearest survivor")
|
||||
selection_references_set(selection, anm2, SelectionKind::FRAMES, {{0, LAYER, 0, 1}});
|
||||
|
||||
selection_edit(anm2, selection, [&] { edit::frames_delete(anm2, {{0, LAYER, 0, 1}}); });
|
||||
CHECK(selection_focus_get(selection, UidIndex(anm2)) == Reference{0, LAYER, 0, 0});
|
||||
CHECK(selection_focus_get(selection, model::UidIndex(anm2)) == Reference{0, LAYER, 0, 0});
|
||||
CHECK(selection.uids[SelectionKind::FRAMES].empty());
|
||||
|
||||
selection_edit(anm2, selection, [&] { edit::items_remove(anm2, 0, {{LAYER, {0}}}, {}); });
|
||||
CHECK(selection_focus_get(selection, UidIndex(anm2)) == Reference{0, ROOT});
|
||||
CHECK(selection_focus_get(selection, model::UidIndex(anm2)) == Reference{0, ROOT});
|
||||
|
||||
selection_focus_set(selection, anm2, {1, ROOT, -1, 0});
|
||||
selection_edit(anm2, selection, [&] { edit::animations_remove(anm2, {1}, {}); });
|
||||
CHECK(selection_focus_get(selection, UidIndex(anm2)) == Reference{0, ROOT});
|
||||
CHECK(selection_focus_get(selection, model::UidIndex(anm2)) == Reference{0, ROOT});
|
||||
}
|
||||
|
||||
TEST_CASE("track and group selection follow regrouping")
|
||||
{
|
||||
auto anm2 = fixture_load_with_uids("03a_groups_nested.anm2");
|
||||
auto group =
|
||||
child_first_get(*child_first_get(*anm2.element_get(ElementType::ANIMATION, 0), ElementType::LAYER_ANIMATIONS),
|
||||
ElementType::GROUP);
|
||||
const model::TrackGroup* group{};
|
||||
model::groups_each(anm2.animation_get(0)->layers, [&](const model::TrackGroup& candidate) { group = &candidate; });
|
||||
REQUIRE(group);
|
||||
auto groupId = group->id;
|
||||
Selection selection{};
|
||||
selection_references_set(selection, anm2, SelectionKind::TRACKS, {{0, LAYER, 0, -1, LAYER, group->id}});
|
||||
selection_references_set(selection, anm2, SelectionKind::GROUPS, {{0, LAYER, group->id}});
|
||||
selection_references_set(selection, anm2, SelectionKind::TRACKS, {{0, LAYER, 0, -1, LAYER, groupId}});
|
||||
selection_references_set(selection, anm2, SelectionKind::GROUPS, {{0, LAYER, groupId}});
|
||||
|
||||
selection_edit(anm2, selection,
|
||||
[&] { edit::items_move(anm2, 0, LAYER, {0}, {}, {false, LAYER, 2, -1}, false, false); });
|
||||
|
||||
UidIndex index(anm2);
|
||||
model::UidIndex index(anm2);
|
||||
CHECK(selection_references_get(selection, index, SelectionKind::TRACKS) == std::set<Reference>{{0, LAYER, 0}});
|
||||
CHECK(selection_references_get(selection, index, SelectionKind::GROUPS) ==
|
||||
std::set<Reference>{{0, LAYER, group->id}});
|
||||
CHECK(selection_references_get(selection, index, SelectionKind::GROUPS) == std::set<Reference>{{0, LAYER, groupId}});
|
||||
}
|
||||
Reference in new issue
Block a user