Stage 3: operations layer (src/edit) and one undo entry point
- src/edit/ (in anm2ed_core): frame, track, animation, region, grid and change-all edits as plain functions of the model. Each returns the uids of what it created for the UI to select; copies get fresh uids. - Document::edit_apply snapshots, runs an operation and commits; edit_begin starts drag edits. window_edit, edit_command_push, snapshot_command_push, SnapshotKind and the tracks/frames/regions/textures snapshot kinds are gone; Snapshots has a single push(message, isTextures). - Timeline, animations, regions, shaders, items, wizards, taskbar and file merge call the edit layer; they keep only selection, scrolling and toasts. - Snapshots, Storage, Playback and ImGui core build into anm2ed_core, so undo is testable: tests/undo.cpp runs a seeded random walk of edits per fixture and checks every undo/redo state by hash, plus selection follow through undo. - types::edit renamed types::edit_state (clashed with the edit namespace). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
20bfbace7a
commit
700b613c62
63 files changed
+3223
-1775
No files matched your search
@@ -248,45 +248,15 @@ namespace anm2ed::imgui::wizard
|
||||
[=, queuedAnimations = std::set<int>(animations.begin(), animations.end()), isRoot = settings.changeIsRoot,
|
||||
isLayers = settings.changeIsLayers, isNulls = settings.changeIsNulls](Manager&, Document& document)
|
||||
{
|
||||
auto& anm2 = document.anm2;
|
||||
std::vector<std::tuple<Element*, ItemType, std::set<int>>> targets{};
|
||||
auto all_target_push = [&](Element* item, ItemType type)
|
||||
{
|
||||
if (!item) return;
|
||||
auto indices = std::views::iota(0, track_frames_count_get(*item));
|
||||
targets.emplace_back(item, type, std::set<int>(indices.begin(), indices.end()));
|
||||
};
|
||||
|
||||
edit::ChangeTargets targets{.isRoot = isRoot, .isLayers = isLayers, .isNulls = isNulls};
|
||||
if (isFramesDestination)
|
||||
{
|
||||
std::map<Reference, std::set<int>> groupedFrames{};
|
||||
for (auto frameReference : selectedFrameReferences)
|
||||
groupedFrames[{frameReference.animationIndex, frameReference.itemType, frameReference.itemID, -1,
|
||||
frameReference.groupType, frameReference.groupId}]
|
||||
.insert(frameReference.frameIndex);
|
||||
for (auto& [itemReference, selection] : groupedFrames)
|
||||
if (auto item = anm2.element_get(itemReference))
|
||||
targets.emplace_back(item, (ItemType)itemReference.itemType, selection);
|
||||
}
|
||||
targets.references = {selectedFrameReferences.begin(), selectedFrameReferences.end()};
|
||||
else if (isItemsDestination)
|
||||
for (auto itemReference : selectedItemReferences)
|
||||
all_target_push(anm2.element_get(itemReference), (ItemType)itemReference.itemType);
|
||||
targets.references = {selectedItemReferences.begin(), selectedItemReferences.end()};
|
||||
else
|
||||
for (auto animationIndex : queuedAnimations)
|
||||
{
|
||||
auto animation = anm2.element_get(ElementType::ANIMATION, animationIndex);
|
||||
if (!animation) continue;
|
||||
if (isRoot) all_target_push(animation_item_get(*animation, ItemType::ROOT), ItemType::ROOT);
|
||||
for (const auto& row : TRACK_CONTAINERS)
|
||||
if (auto container = child_first_get(*animation, row.container);
|
||||
container && (row.itemType == ItemType::LAYER ? isLayers : isNulls))
|
||||
tracks_each(*container, row.track, [&](Element& track) { all_target_push(&track, row.itemType); });
|
||||
}
|
||||
|
||||
document.snapshots.anm2_push(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
|
||||
for (auto& [item, type, selection] : targets)
|
||||
frames_change(*item, frameChange, type, changeType, selection);
|
||||
document.change(Document::FRAMES);
|
||||
targets.animations = queuedAnimations;
|
||||
document.edit_apply(EDIT_CHANGE_FRAME_PROPERTIES, Document::FRAMES, [&](Anm2& anm2)
|
||||
{ return edit::frames_change_apply(anm2, targets, frameChange, changeType); });
|
||||
}});
|
||||
isChanged = true;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user