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
+21
-2
@@ -731,6 +731,25 @@ namespace anm2ed
|
||||
snapshots.commit();
|
||||
}
|
||||
|
||||
void Document::edit_begin(StringType label, bool isTextures) { snapshots.push(localize.get(label), isTextures); }
|
||||
|
||||
edit::Uids Document::edit_run(StringType label, ChangeType type, const std::function<edit::Uids(Anm2&)>& operation)
|
||||
{
|
||||
edit_begin(label);
|
||||
auto uids = operation(anm2);
|
||||
change(type);
|
||||
return uids;
|
||||
}
|
||||
|
||||
std::vector<Reference> Document::references_get(const edit::Uids& uids) const
|
||||
{
|
||||
UidIndex index(anm2);
|
||||
std::vector<Reference> references{};
|
||||
for (auto uid : uids)
|
||||
if (auto reference = index.reference_get(uid)) references.push_back(*reference);
|
||||
return references;
|
||||
}
|
||||
|
||||
bool Document::is_dirty() const { return hash != saveHash; }
|
||||
bool Document::is_autosave_dirty() const { return hash != autosaveHash; }
|
||||
|
||||
@@ -916,7 +935,7 @@ namespace anm2ed
|
||||
}
|
||||
if (loaded.empty()) return;
|
||||
|
||||
snapshots.anm2_push(localize.get(EDIT_ADD_SPRITESHEET));
|
||||
edit_begin(EDIT_ADD_SPRITESHEET);
|
||||
|
||||
std::set<int> added{};
|
||||
for (auto& [relativePath, texture] : loaded)
|
||||
@@ -940,7 +959,7 @@ namespace anm2ed
|
||||
auto items = anm2.element_get(ElementType::SOUNDS);
|
||||
if (!items || std::ranges::all_of(paths, [](const auto& path) { return path.empty(); })) return;
|
||||
|
||||
snapshots.anm2_push(localize.get(EDIT_ADD_SOUND));
|
||||
edit_begin(EDIT_ADD_SOUND);
|
||||
|
||||
std::set<int> added{};
|
||||
for (auto& path : paths)
|
||||
|
||||
Reference in new issue
Block a user