Stage 6: Document::change() always refreshes derived data; ChangeType removed

change() now flushes drafts, re-syncs assets and shaders, rebuilds every label
list and the uid index, and commits. Document::ChangeType, the switch in
change(), the type parameter of edit_apply/edit_run/edit_push/assets_sync,
Window::changeType and every per-call change type (about 40 sites) are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-03 15:59:44 -04:00
1 parent 9f43a210c5
commit 2d0f70b1e5
25 files changed
+128 -202

No files matched your search

+26 -56
View File
@@ -191,7 +191,7 @@ namespace anm2ed
this->path = path; this->path = path;
isValid = anm2.isValid; isValid = anm2.isValid;
clean(); clean();
change(Document::ALL); change();
} }
Document::Document(Document&& other) noexcept : DocumentData(std::move(other)), editTarget(other.editTarget) {} Document::Document(Document&& other) noexcept : DocumentData(std::move(other)), editTarget(other.editTarget) {}
@@ -251,7 +251,7 @@ namespace anm2ed
void Document::texture_change(int id) void Document::texture_change(int id)
{ {
if (texture_get(id) && anm2.element_get(ElementType::SPRITESHEET, id)) change(SPRITESHEETS); if (texture_get(id) && anm2.element_get(ElementType::SPRITESHEET, id)) change();
} }
bool Document::texture_reload(int id) bool Document::texture_reload(int id)
@@ -321,17 +321,14 @@ namespace anm2ed
return true; return true;
} }
void Document::assets_sync(ChangeType type) void Document::assets_sync()
{ {
if (type == ALL || type == SPRITESHEETS || type == TEXTURES) document::resources_sync(*this, ElementType::SPRITESHEET, textures, texturePaths,
document::resources_sync(*this, ElementType::SPRITESHEET, textures, texturePaths, [&](int id, const std::filesystem::path& path)
[&](int id, const std::filesystem::path& path) { texture_set(id, resource::Image(path)); });
{ texture_set(id, resource::Image(path)); }); document::resources_sync(*this, ElementType::SOUND_ELEMENT, sounds, soundPaths,
if (type == ALL || type == SOUNDS) [&](int id, const std::filesystem::path& path)
document::resources_sync(*this, ElementType::SOUND_ELEMENT, sounds, soundPaths, { sound_set(id, resource::AudioData(path)); });
[&](int id, const std::filesystem::path& path)
{ sound_set(id, resource::AudioData(path)); });
if (type != ALL && type != SHADERS) return;
std::set<int> validShaderIds{}; std::set<int> validShaderIds{};
util::WorkingDirectory workingDirectory(directory_get()); util::WorkingDirectory workingDirectory(directory_get());
@@ -513,7 +510,7 @@ namespace anm2ed
for (auto& region : spritesheet->children) for (auto& region : spritesheet->children)
if (region.type == ElementType::REGION && crops.contains(region.id)) region.crop = crops.at(region.id); if (region.type == ElementType::REGION && crops.contains(region.id)) region.crop = crops.at(region.id);
assets_sync(SPRITESHEETS); assets_sync();
return true; return true;
} }
@@ -595,7 +592,7 @@ namespace anm2ed
textures.erase(id); textures.erase(id);
} }
assets_sync(ALL); assets_sync();
return true; return true;
} }
@@ -636,12 +633,13 @@ namespace anm2ed
std::erase_if(spritesheetSaveHashes, is_invalid); std::erase_if(spritesheetSaveHashes, is_invalid);
} }
void Document::change(ChangeType type) // Commits the pending edit and rebuilds everything derived from the model.
void Document::change()
{ {
for (auto& [id, draft] : std::exchange(textureDrafts, {})) for (auto& [id, draft] : std::exchange(textureDrafts, {}))
textures[id] = assets.image_add(std::move(draft)); textures[id] = assets.image_add(std::move(draft));
hash_set(); hash_set();
assets_sync(type); assets_sync();
auto events_set = [&]() auto events_set = [&]()
{ {
@@ -688,39 +686,11 @@ namespace anm2ed
document::element_name_get); document::element_name_get);
}; };
switch (type) events_set();
{ spritesheets_set();
case EVENTS: regions_set();
events_set(); shaders_set();
break; sounds_set();
case SPRITESHEETS:
spritesheets_set();
regions_set();
break;
case SHADERS:
shaders_set();
break;
case SOUNDS:
sounds_set();
break;
case FRAMES:
events_set();
sounds_set();
break;
case ITEMS:
spritesheets_set();
break;
case ANIMATIONS:
case ALL:
events_set();
spritesheets_set();
regions_set();
shaders_set();
sounds_set();
break;
default:
break;
}
snapshots.commit(); snapshots.commit();
index = UidIndex(anm2); index = UidIndex(anm2);
@@ -728,11 +698,11 @@ namespace anm2ed
void Document::edit_begin(StringType label) { snapshots.push(localize.get(label)); } void Document::edit_begin(StringType label) { snapshots.push(localize.get(label)); }
edit::Uids Document::edit_run(StringType label, ChangeType type, const std::function<edit::Uids(Anm2&)>& operation) edit::Uids Document::edit_run(StringType label, const std::function<edit::Uids(Anm2&)>& operation)
{ {
edit_begin(label); edit_begin(label);
auto uids = operation(anm2); auto uids = operation(anm2);
change(type); change();
return uids; return uids;
} }
@@ -752,7 +722,7 @@ namespace anm2ed
{ {
auto spritesheet = anm2.element_get(ElementType::SPRITESHEET, id); auto spritesheet = anm2.element_get(ElementType::SPRITESHEET, id);
if (!spritesheet) return; if (!spritesheet) return;
assets_sync(TEXTURES); assets_sync();
spritesheetHashes[id] = document::spritesheet_hash_get(*spritesheet, textures.contains(id) ? textures.at(id) : 0); spritesheetHashes[id] = document::spritesheet_hash_get(*spritesheet, textures.contains(id) ? textures.at(id) : 0);
} }
@@ -936,7 +906,7 @@ namespace anm2ed
toast_log(Level::INFO, TOAST_SPRITESHEET_INITIALIZED, element.id, path::to_utf8(element.path)); toast_log(Level::INFO, TOAST_SPRITESHEET_INITIALIZED, element.id, path::to_utf8(element.path));
} }
spritesheet.selection = added; spritesheet.selection = added;
change(Document::SPRITESHEETS); change();
} }
void Document::sounds_add(const std::vector<std::filesystem::path>& paths) void Document::sounds_add(const std::vector<std::filesystem::path>& paths)
@@ -961,7 +931,7 @@ namespace anm2ed
toast_log(Level::INFO, TOAST_SOUND_INITIALIZED, element.id, path::to_utf8(element.path)); toast_log(Level::INFO, TOAST_SOUND_INITIALIZED, element.id, path::to_utf8(element.path));
} }
sound.selection = added; sound.selection = added;
change(Document::SOUNDS); change();
} }
void Document::undo() void Document::undo()
@@ -969,7 +939,7 @@ namespace anm2ed
if (!snapshots.undo()) return; if (!snapshots.undo()) return;
document::frame_time_sync(*this); document::frame_time_sync(*this);
toast_log(Level::INFO, TOAST_UNDO, message); toast_log(Level::INFO, TOAST_UNDO, message);
change(Document::ALL); change();
} }
void Document::redo() void Document::redo()
@@ -977,7 +947,7 @@ namespace anm2ed
if (!snapshots.redo()) return; if (!snapshots.redo()) return;
document::frame_time_sync(*this); document::frame_time_sync(*this);
toast_log(Level::INFO, TOAST_REDO, message); toast_log(Level::INFO, TOAST_REDO, message);
change(Document::ALL); change();
} }
bool Document::is_able_to_undo() { return !snapshots.undoStack.is_empty(); } bool Document::is_able_to_undo() { return !snapshots.undoStack.is_empty(); }
+5 -22
View File
@@ -66,23 +66,6 @@ namespace anm2ed
class Document : public DocumentData class Document : public DocumentData
{ {
public: public:
enum ChangeType
{
INFO,
LAYERS,
NULLS,
SPRITESHEETS,
TEXTURES,
SHADERS,
EVENTS,
ANIMATIONS,
ITEMS,
FRAMES,
SOUNDS,
ALL,
COUNT
};
enum class FrameReferenceFallback enum class FrameReferenceFallback
{ {
NONE, NONE,
@@ -112,7 +95,7 @@ namespace anm2ed
Document(Document&&) noexcept; Document(Document&&) noexcept;
Document& operator=(Document&&) noexcept; Document& operator=(Document&&) noexcept;
bool save(const std::filesystem::path& = {}, std::string* = nullptr, Options = {}); bool save(const std::filesystem::path& = {}, std::string* = nullptr, Options = {});
void assets_sync(ChangeType = ALL); void assets_sync();
void texture_change(int); void texture_change(int);
bool texture_reload(int); bool texture_reload(int);
bool sound_reload(int); bool sound_reload(int);
@@ -128,14 +111,14 @@ namespace anm2ed
bool spritesheets_merge(const std::set<int>&, bool, bool, bool, origin::Type); bool spritesheets_merge(const std::set<int>&, bool, bool, bool, origin::Type);
void hash_set(); void hash_set();
void clean(); void clean();
void change(ChangeType); void change();
void edit_begin(StringType); void edit_begin(StringType);
edit::Uids edit_run(StringType, ChangeType, const std::function<edit::Uids(Anm2&)>&); edit::Uids edit_run(StringType, const std::function<edit::Uids(Anm2&)>&);
// Snapshots for undo, runs the operation on the model, then commits; void operations select nothing. // Snapshots for undo, runs the operation on the model, then commits; void operations select nothing.
template <class Operation> edit::Uids edit_apply(StringType label, ChangeType type, Operation&& operation) template <class Operation> edit::Uids edit_apply(StringType label, Operation&& operation)
{ {
return edit_run(label, type, return edit_run(label,
[&](Anm2& anm2) -> edit::Uids [&](Anm2& anm2) -> edit::Uids
{ {
if constexpr (std::is_void_v<std::invoke_result_t<Operation&, Anm2&>>) if constexpr (std::is_void_v<std::invoke_result_t<Operation&, Anm2&>>)
+1 -1
View File
@@ -51,7 +51,7 @@ namespace anm2ed::imgui
{ {
manager.command_push({manager.selected, [paths, preset](Manager&, Document& document) manager.command_push({manager.selected, [paths, preset](Manager&, Document& document)
{ {
document.edit_apply(EDIT_MERGE_ANM2, Document::ALL, document.edit_apply(EDIT_MERGE_ANM2,
[&](Anm2& anm2) [&](Anm2& anm2)
{ {
for (auto& path : paths) for (auto& path : paths)
+1 -1
View File
@@ -204,7 +204,7 @@ namespace anm2ed::imgui::popup
item.isShowRect = queuedAddItemIsShowRect; item.isShowRect = queuedAddItemIsShowRect;
int addId{-1}; int addId{-1};
document.edit_apply(EDIT_ADD_ITEM, Document::ITEMS, document.edit_apply(EDIT_ADD_ITEM,
[&](Anm2& anm2) [&](Anm2& anm2)
{ {
addId = anm2.item_add((ItemType)queuedType, queuedAnimationIndex, addId = anm2.item_add((ItemType)queuedType, queuedAnimationIndex,
+4 -7
View File
@@ -170,11 +170,9 @@ namespace anm2ed::imgui
if (ImGui::MenuItem(localize.get(LABEL_SCAN_AND_SET_REGIONS), nullptr, false, document && hasRegions)) if (ImGui::MenuItem(localize.get(LABEL_SCAN_AND_SET_REGIONS), nullptr, false, document && hasRegions))
{ {
manager.command_push({manager.selected, [](Manager&, Document& document) manager.command_push(
{ {manager.selected, [](Manager&, Document& document)
document.edit_apply(EDIT_SCAN_AND_SET_REGIONS, Document::FRAMES, { document.edit_apply(EDIT_SCAN_AND_SET_REGIONS, [](Anm2& anm2) { anm2.regions_scan(); }); }});
[](Anm2& anm2) { anm2.regions_scan(); });
}});
toast_log(Level::INFO, TOAST_SCAN_AND_SET_REGIONS); toast_log(Level::INFO, TOAST_SCAN_AND_SET_REGIONS);
} }
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_WIZARD_SCAN_AND_SET_REGIONS)); ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_WIZARD_SCAN_AND_SET_REGIONS));
@@ -286,8 +284,7 @@ namespace anm2ed::imgui
{ {
if (queuedAnimationIndices.empty()) return; if (queuedAnimationIndices.empty()) return;
document.edit_apply( document.edit_apply(
EDIT_GENERATE_REGIONS_FROM_ANIMATIONS, EDIT_GENERATE_REGIONS_FROM_ANIMATIONS, [&](Anm2& anm2)
queuedMapping == RegionFrameMapping::SET ? Document::ALL : Document::SPRITESHEETS, [&](Anm2& anm2)
{ anm2.regions_generate(queuedAnimationIndices, {}, queuedFormat, queuedMapping); }); { anm2.regions_generate(queuedAnimationIndices, {}, queuedFormat, queuedMapping); });
}}); }});
generateRegionsPopup.close(); generateRegionsPopup.close();
+1 -4
View File
@@ -1353,10 +1353,7 @@ namespace anm2ed::imgui
frame_change_apply({.shearX = shear.x - frame->shear.x, .shearY = shear.y - frame->shear.y}, ChangeType::ADD); frame_change_apply({.shearX = shear.x - frame->shear.x, .shearY = shear.y - frame->shear.y}, ChangeType::ADD);
}; };
auto frames_changed = [&]() auto frames_changed = [&]()
{ { manager.command_push({manager.selected, [](Manager&, Document& document) { document.change(); }}); };
manager.command_push(
{manager.selected, [](Manager&, Document& document) { document.change(Document::FRAMES); }});
};
auto null_rect_change = [&](vec2 topLeft, vec2 rectSize) auto null_rect_change = [&](vec2 topLeft, vec2 rectSize)
{ {
topLeft = vec2(ivec2(topLeft)); topLeft = vec2(ivec2(topLeft));
+8 -10
View File
@@ -146,7 +146,7 @@ namespace anm2ed::imgui
void animations_erase(Window& window, Document& document, const std::set<int>& indices, const std::set<int>& groupIds, void animations_erase(Window& window, Document& document, const std::set<int>& indices, const std::set<int>& groupIds,
StringType label) StringType label)
{ {
document.edit_apply(label, window.changeType, document.edit_apply(label,
[&](Anm2& anm2) [&](Anm2& anm2)
{ {
animation_overlay_reset(document, indices); animation_overlay_reset(document, indices);
@@ -187,7 +187,7 @@ namespace anm2ed::imgui
std::set<int> groupIds{}; std::set<int> groupIds{};
std::string errorString{}; std::string errorString{};
auto uids = document.edit_apply( auto uids = document.edit_apply(
edit, window.changeType, edit,
[&](Anm2& anm2) [&](Anm2& anm2)
{ {
auto uids = edit::animations_paste(anm2, text, start, targetGroupId, groupIds, &errorString); auto uids = edit::animations_paste(anm2, text, start, targetGroupId, groupIds, &errorString);
@@ -231,7 +231,7 @@ namespace anm2ed::imgui
return -1; return -1;
int merged{-1}; int merged{-1};
document.edit_apply(EDIT_MERGE_ANIMATIONS, Document::ANIMATIONS, document.edit_apply(EDIT_MERGE_ANIMATIONS,
[&](Anm2& anm2) [&](Anm2& anm2)
{ {
animation_overlay_reset(document, sources); animation_overlay_reset(document, sources);
@@ -276,7 +276,7 @@ namespace anm2ed::imgui
{ {
auto animations = window_container_get(window, document); auto animations = window_container_get(window, document);
if (!animations) return; if (!animations) return;
document.edit_apply(EDIT_MOVE_ANIMATIONS, window.changeType, document.edit_apply(EDIT_MOVE_ANIMATIONS,
[&](Anm2& anm2) [&](Anm2& anm2)
{ {
animation_items_move(window, document, anm2, items, animation_items_move(window, document, anm2, items,
@@ -382,7 +382,7 @@ namespace anm2ed::imgui
if (!group || (name.value_or(group->name) == group->name && if (!group || (name.value_or(group->name) == group->name &&
isExpanded.value_or(group->isExpanded) == group->isExpanded)) isExpanded.value_or(group->isExpanded) == group->isExpanded))
return; return;
document.edit_apply(edit, Document::ANIMATIONS, document.edit_apply(edit,
[&](Anm2&) [&](Anm2&)
{ {
group->name = name.value_or(group->name); group->name = name.value_or(group->name);
@@ -475,7 +475,6 @@ namespace anm2ed::imgui
Window window{}; Window window{};
window.title = LABEL_ANIMATIONS_WINDOW; window.title = LABEL_ANIMATIONS_WINDOW;
window.isOpen = &Settings::windowIsAnimations; window.isOpen = &Settings::windowIsAnimations;
window.changeType = Document::ANIMATIONS;
window.containerType = ElementType::ANIMATIONS; window.containerType = ElementType::ANIMATIONS;
window.elementType = ElementType::ANIMATION; window.elementType = ElementType::ANIMATION;
window.childLabel = "##Animations Child"; window.childLabel = "##Animations Child";
@@ -600,7 +599,7 @@ namespace anm2ed::imgui
: selected && groupIds.contains(selected->groupId) ? selected->groupId : selected && groupIds.contains(selected->groupId) ? selected->groupId
: -1; : -1;
document.edit_apply(EDIT_ADD_ANIMATION, window.changeType, document.edit_apply(EDIT_ADD_ANIMATION,
[&](Anm2& anm2) [&](Anm2& anm2)
{ {
auto uids = auto uids =
@@ -693,7 +692,7 @@ namespace anm2ed::imgui
std::set<int> targetSet(targetIndices.begin(), targetIndices.end()); std::set<int> targetSet(targetIndices.begin(), targetIndices.end());
auto groupId = element_child_next_id_get(*animations, ElementType::GROUP); auto groupId = element_child_next_id_get(*animations, ElementType::GROUP);
document.edit_apply(EDIT_GROUP_ITEMS, window.changeType, document.edit_apply(EDIT_GROUP_ITEMS,
[&](Anm2& anm2) [&](Anm2& anm2)
{ {
auto uids = edit::animations_group(anm2, targetSet, localize.get(TEXT_NEW_GROUP)); auto uids = edit::animations_group(anm2, targetSet, localize.get(TEXT_NEW_GROUP));
@@ -708,8 +707,7 @@ namespace anm2ed::imgui
auto animations = window_container_get(window, document); auto animations = window_container_get(window, document);
auto animation = document.anm2.element_get(ElementType::ANIMATION, *document.animation.selection.begin()); auto animation = document.anm2.element_get(ElementType::ANIMATION, *document.animation.selection.begin());
if (!animations || !animation) return; if (!animations || !animation) return;
document.edit_apply(EDIT_DEFAULT_ANIMATION, window.changeType, document.edit_apply(EDIT_DEFAULT_ANIMATION, [&](Anm2&) { animations->defaultAnimation = animation->name; });
[&](Anm2&) { animations->defaultAnimation = animation->name; });
}; };
window.body_update = window.body_update =
[](Window& window, Manager& manager, Settings& settings, Resources&, Clipboard&, Document& document) [](Window& window, Manager& manager, Settings& settings, Resources&, Clipboard&, Document& document)
+1 -1
View File
@@ -77,7 +77,7 @@ namespace anm2ed::imgui
queuedReference.groupId}); queuedReference.groupId});
if (state == edit_state::START || state == edit_state::COMPLETE) document.edit_begin(message); if (state == edit_state::START || state == edit_state::COMPLETE) document.edit_begin(message);
behavior(document, *frame, item, queuedReference); behavior(document, *frame, item, queuedReference);
if (state == edit_state::END || state == edit_state::COMPLETE) document.change(Document::FRAMES); if (state == edit_state::END || state == edit_state::COMPLETE) document.change();
}}); }});
}; };
+9 -14
View File
@@ -43,14 +43,12 @@ namespace anm2ed::imgui
popup.end(); popup.end();
} }
Window item_window_make(StringType title, bool Settings::* isOpen, Document::ChangeType changeType, Window item_window_make(StringType title, bool Settings::* isOpen, ElementType elementType, const char* childLabel,
ElementType elementType, const char* childLabel, StringType addTooltip, StringType addTooltip, StringType removeUnusedTooltip)
StringType removeUnusedTooltip)
{ {
Window window{}; Window window{};
window.title = title; window.title = title;
window.isOpen = isOpen; window.isOpen = isOpen;
window.changeType = changeType;
window.containerType = ELEMENT_CONTAINERS[(int)elementType]; window.containerType = ELEMENT_CONTAINERS[(int)elementType];
window.elementType = elementType; window.elementType = elementType;
window.childLabel = childLabel; window.childLabel = childLabel;
@@ -65,9 +63,8 @@ namespace anm2ed::imgui
Window layers_window_register() Window layers_window_register()
{ {
auto window = auto window = item_window_make(LABEL_LAYERS_WINDOW, &Settings::windowIsLayers, ElementType::LAYER_ELEMENT,
item_window_make(LABEL_LAYERS_WINDOW, &Settings::windowIsLayers, Document::LAYERS, ElementType::LAYER_ELEMENT, "##Layers Child", TOOLTIP_ADD_LAYER, TOOLTIP_REMOVE_UNUSED_LAYERS);
"##Layers Child", TOOLTIP_ADD_LAYER, TOOLTIP_REMOVE_UNUSED_LAYERS);
window.addEdit = EDIT_ADD_LAYER; window.addEdit = EDIT_ADD_LAYER;
window.propertiesEdit = EDIT_SET_LAYER_PROPERTIES; window.propertiesEdit = EDIT_SET_LAYER_PROPERTIES;
window.pasteEdit = EDIT_PASTE_LAYERS; window.pasteEdit = EDIT_PASTE_LAYERS;
@@ -100,9 +97,8 @@ namespace anm2ed::imgui
Window nulls_window_register() Window nulls_window_register()
{ {
auto window = auto window = item_window_make(LABEL_NULLS_WINDOW, &Settings::windowIsNulls, ElementType::NULL_ELEMENT,
item_window_make(LABEL_NULLS_WINDOW, &Settings::windowIsNulls, Document::NULLS, ElementType::NULL_ELEMENT, "##Nulls Child", TOOLTIP_ADD_NULL, TOOLTIP_REMOVE_UNUSED_NULLS);
"##Nulls Child", TOOLTIP_ADD_NULL, TOOLTIP_REMOVE_UNUSED_NULLS);
window.addEdit = EDIT_ADD_NULL; window.addEdit = EDIT_ADD_NULL;
window.propertiesEdit = EDIT_SET_NULL_PROPERTIES; window.propertiesEdit = EDIT_SET_NULL_PROPERTIES;
window.pasteEdit = EDIT_PASTE_NULLS; window.pasteEdit = EDIT_PASTE_NULLS;
@@ -126,9 +122,8 @@ namespace anm2ed::imgui
Window events_window_register() Window events_window_register()
{ {
auto window = auto window = item_window_make(LABEL_EVENTS_WINDOW, &Settings::windowIsEvents, ElementType::EVENT_ELEMENT,
item_window_make(LABEL_EVENTS_WINDOW, &Settings::windowIsEvents, Document::EVENTS, ElementType::EVENT_ELEMENT, "##Events Child", TOOLTIP_ADD_EVENT, TOOLTIP_REMOVE_UNUSED_EVENTS);
"##Events Child", TOOLTIP_ADD_EVENT, TOOLTIP_REMOVE_UNUSED_EVENTS);
window.addEdit = EDIT_ADD_EVENT; window.addEdit = EDIT_ADD_EVENT;
window.renameEdit = EDIT_RENAME_EVENT; window.renameEdit = EDIT_RENAME_EVENT;
window.pasteEdit = EDIT_PASTE_EVENTS; window.pasteEdit = EDIT_PASTE_EVENTS;
@@ -143,7 +138,7 @@ namespace anm2ed::imgui
event.name = localize.get(TEXT_NEW_EVENT); event.name = localize.get(TEXT_NEW_EVENT);
auto events = window_container_get(window, document); auto events = window_container_get(window, document);
if (!events) return; if (!events) return;
document.edit_apply(window.addEdit, window.changeType, document.edit_apply(window.addEdit,
[&](Anm2&) [&](Anm2&)
{ {
event.id = element_child_next_id_get(*events, ElementType::EVENT_ELEMENT); event.id = element_child_next_id_get(*events, ElementType::EVENT_ELEMENT);
+5 -6
View File
@@ -173,7 +173,7 @@ namespace anm2ed::imgui
document.region.selection.clear(); document.region.selection.clear();
} }
} }
document.change(Document::SPRITESHEETS); document.change();
} }
toast_log(Level::INFO, TOAST_EXPORT_REGION, sourceRegion.name, pathString); toast_log(Level::INFO, TOAST_EXPORT_REGION, sourceRegion.name, pathString);
@@ -218,7 +218,7 @@ namespace anm2ed::imgui
{ {
auto spritesheet = document.anm2.element_get(ElementType::SPRITESHEET, spritesheetId); auto spritesheet = document.anm2.element_get(ElementType::SPRITESHEET, spritesheetId);
if (!spritesheet) return; if (!spritesheet) return;
document.edit_apply(EDIT_MOVE_REGIONS, window.changeType, document.edit_apply(EDIT_MOVE_REGIONS,
[&](Anm2&) [&](Anm2&)
{ {
vector::move_indices_to_position(spritesheet->children, indices, targetIndex); vector::move_indices_to_position(spritesheet->children, indices, targetIndex);
@@ -384,7 +384,6 @@ namespace anm2ed::imgui
Window window{}; Window window{};
window.title = LABEL_REGIONS_WINDOW; window.title = LABEL_REGIONS_WINDOW;
window.isOpen = &Settings::windowIsRegions; window.isOpen = &Settings::windowIsRegions;
window.changeType = Document::SPRITESHEETS;
window.elementType = ElementType::REGION; window.elementType = ElementType::REGION;
window.childLabel = "##Regions Child"; window.childLabel = "##Regions Child";
window.cardLines = REGION_CARD_LINES; window.cardLines = REGION_CARD_LINES;
@@ -451,13 +450,13 @@ namespace anm2ed::imgui
}; };
window.remove_unused = [](Window& window, Manager&, Settings&, Document& document, Clipboard&) window.remove_unused = [](Window& window, Manager&, Settings&, Document& document, Clipboard&)
{ {
document.edit_apply(EDIT_REMOVE_UNUSED_REGIONS, window.changeType, [&](Anm2& anm2) document.edit_apply(EDIT_REMOVE_UNUSED_REGIONS, [&](Anm2& anm2)
{ return edit::regions_remove_unused(anm2, document.spritesheet.reference); }); { return edit::regions_remove_unused(anm2, document.spritesheet.reference); });
}; };
window.trim = [](Window& window, Manager&, Settings&, Document& document, Clipboard&) window.trim = [](Window& window, Manager&, Settings&, Document& document, Clipboard&)
{ {
auto& region = document.region; auto& region = document.region;
document.edit_apply(EDIT_TRIM_REGIONS, window.changeType, document.edit_apply(EDIT_TRIM_REGIONS,
[&](Anm2&) [&](Anm2&)
{ {
if (!document.regions_trim(document.spritesheet.reference, region.selection)) return; if (!document.regions_trim(document.spritesheet.reference, region.selection)) return;
@@ -473,7 +472,7 @@ namespace anm2ed::imgui
if (!spritesheet || clipboard.is_empty()) return; if (!spritesheet || clipboard.is_empty()) return;
auto maxIdBefore = element_child_max_id_get(*spritesheet, ElementType::REGION); auto maxIdBefore = element_child_max_id_get(*spritesheet, ElementType::REGION);
std::string errorString{}; std::string errorString{};
document.edit_apply(EDIT_PASTE_REGIONS, window.changeType, document.edit_apply(EDIT_PASTE_REGIONS,
[&](Anm2& anm2) [&](Anm2& anm2)
{ {
edit::regions_paste(anm2, document.spritesheet.reference, clipboard.get(), edit::regions_paste(anm2, document.spritesheet.reference, clipboard.get(),
+5 -5
View File
@@ -71,7 +71,7 @@ namespace anm2ed::imgui
if (shader) if (shader)
{ {
shader->*member = path::backslash_replace(value); shader->*member = path::backslash_replace(value);
document.change(Document::SHADERS); document.change();
} }
} }
@@ -125,7 +125,7 @@ namespace anm2ed::imgui
void shader_uniform_config_save(Document& document, Element& shaderElement, const resource::shader::Uniform& uniform) void shader_uniform_config_save(Document& document, Element& shaderElement, const resource::shader::Uniform& uniform)
{ {
resource::shader::uniform_config_save(shaderElement, uniform); resource::shader::uniform_config_save(shaderElement, uniform);
document.change(Document::SHADERS); document.change();
} }
void shader_uniform_components_from_value_set(resource::shader::Uniform& uniform) void shader_uniform_components_from_value_set(resource::shader::Uniform& uniform)
@@ -312,7 +312,7 @@ namespace anm2ed::imgui
shader.id = element_child_next_id_get(*shaders, ElementType::SHADER); shader.id = element_child_next_id_get(*shaders, ElementType::SHADER);
shader.name = localize.get(TEXT_NEW_SHADER); shader.name = localize.get(TEXT_NEW_SHADER);
document.edit_apply(EDIT_ADD_SHADER, Document::SHADERS, document.edit_apply(EDIT_ADD_SHADER,
[&](Anm2&) [&](Anm2&)
{ {
shaders->children.push_back(shader); shaders->children.push_back(shader);
@@ -332,7 +332,7 @@ namespace anm2ed::imgui
auto unused = document.anm2.element_unused(ElementType::SHADER); auto unused = document.anm2.element_unused(ElementType::SHADER);
if (unused.empty()) return; if (unused.empty()) return;
document.edit_apply(EDIT_REMOVE_UNUSED_SHADERS, Document::SHADERS, document.edit_apply(EDIT_REMOVE_UNUSED_SHADERS,
[&](Anm2&) [&](Anm2&)
{ {
for (auto id : unused) for (auto id : unused)
@@ -506,7 +506,7 @@ namespace anm2ed::imgui
if (ImGui::BeginChild("##Shader Properties Child", popupSize)) if (ImGui::BeginChild("##Shader Properties Child", popupSize))
{ {
if (propertiesPopup.isJustOpened) ImGui::SetKeyboardFocusHere(); if (propertiesPopup.isJustOpened) ImGui::SetKeyboardFocusHere();
if (input_text_string(localize.get(BASIC_NAME), &shader->name)) document->change(Document::SHADERS); if (input_text_string(localize.get(BASIC_NAME), &shader->name)) document->change();
ImGui::SeparatorText(localize.get(LABEL_FILES)); ImGui::SeparatorText(localize.get(LABEL_FILES));
+2 -3
View File
@@ -18,7 +18,6 @@ namespace anm2ed::imgui
Window window{}; Window window{};
window.title = LABEL_SOUNDS_WINDOW; window.title = LABEL_SOUNDS_WINDOW;
window.isOpen = &Settings::windowIsSounds; window.isOpen = &Settings::windowIsSounds;
window.changeType = Document::SOUNDS;
window.containerType = ElementType::SOUNDS; window.containerType = ElementType::SOUNDS;
window.elementType = ElementType::SOUND_ELEMENT; window.elementType = ElementType::SOUND_ELEMENT;
window.childLabel = "##Sounds Child"; window.childLabel = "##Sounds Child";
@@ -83,7 +82,7 @@ namespace anm2ed::imgui
}; };
window.reload = [](Window& window, Manager&, Settings&, Document& document, Clipboard&) window.reload = [](Window& window, Manager&, Settings&, Document& document, Clipboard&)
{ {
document.edit_apply(EDIT_RELOAD_SOUNDS, window.changeType, document.edit_apply(EDIT_RELOAD_SOUNDS,
[&](Anm2&) [&](Anm2&)
{ {
for (auto id : document.sound.selection) for (auto id : document.sound.selection)
@@ -115,7 +114,7 @@ namespace anm2ed::imgui
{ {
auto sound = window_element_get(window, document, id); auto sound = window_element_get(window, document, id);
if (!sound) return; if (!sound) return;
document.edit_apply(EDIT_REPLACE_SOUND, window.changeType, document.edit_apply(EDIT_REPLACE_SOUND,
[&](Anm2&) [&](Anm2&)
{ {
sound->path = window_asset_path_get(document, dialogPath); sound->path = window_asset_path_get(document, dialogPath);
+7 -10
View File
@@ -364,11 +364,8 @@ namespace anm2ed::imgui
manager.command_push( manager.command_push(
{manager.selected, [label](Manager&, Document& document) { document.edit_begin(label); }}); {manager.selected, [label](Manager&, Document& document) { document.edit_begin(label); }});
}; };
auto document_change_push = [&](Document::ChangeType changeType) auto document_change_push = [&]()
{ { manager.command_push({manager.selected, [](Manager&, Document& document) { document.change(); }}); };
manager.command_push(
{manager.selected, [changeType](Manager&, Document& document) { document.change(changeType); }});
};
auto frame_change_apply_to = [&](const std::set<Reference>& frameReferences, FrameChange frameChange, auto frame_change_apply_to = [&](const std::set<Reference>& frameReferences, FrameChange frameChange,
ChangeType changeType = ChangeType::ADJUST) ChangeType changeType = ChangeType::ADJUST)
{ {
@@ -651,7 +648,7 @@ namespace anm2ed::imgui
change.pivotY = region->pivot.y; change.pivotY = region->pivot.y;
} }
frame_change_apply(change); frame_change_apply(change);
document_change_push(Document::FRAMES); document_change_push();
} }
} }
if (isMouseDown || isMouseMiddleDown) pan += mouseDelta; if (isMouseDown || isMouseMiddleDown) pan += mouseDelta;
@@ -681,7 +678,7 @@ namespace anm2ed::imgui
} }
} }
if (isEnd) document_change_push(Document::SPRITESHEETS); if (isEnd) document_change_push();
break; break;
} }
@@ -715,7 +712,7 @@ namespace anm2ed::imgui
} }
} }
if (isEnd) document_change_push(Document::FRAMES); if (isEnd) document_change_push();
break; break;
case tool::CROP: case tool::CROP:
if ((isRegionEditTarget || isRegionInUse || selectedFrameToolReferences.empty()) && if ((isRegionEditTarget || isRegionInUse || selectedFrameToolReferences.empty()) &&
@@ -758,7 +755,7 @@ namespace anm2ed::imgui
} }
} }
if (isEnd) document_change_push(Document::SPRITESHEETS); if (isEnd) document_change_push();
break; break;
} }
@@ -811,7 +808,7 @@ namespace anm2ed::imgui
ImGui::EndTooltip(); ImGui::EndTooltip();
} }
} }
if (isEnd) document_change_push(Document::FRAMES); if (isEnd) document_change_push();
break; break;
case tool::DRAW: case tool::DRAW:
case tool::ERASE: case tool::ERASE:
+14 -16
View File
@@ -50,7 +50,7 @@ namespace anm2ed::imgui
auto texture = document.texture_get(id); auto texture = document.texture_get(id);
if (!spritesheet || (isWritten && !texture)) return; if (!spritesheet || (isWritten && !texture)) return;
document.edit_apply( document.edit_apply(
edit, window.changeType, edit,
[&](Anm2&) [&](Anm2&)
{ {
auto newPath = window_asset_path_get(document, dialogPath); auto newPath = window_asset_path_get(document, dialogPath);
@@ -77,13 +77,13 @@ namespace anm2ed::imgui
}}); }});
} }
void spritesheet_textures_edit(Document& document, StringType edit, Document::ChangeType changeType, void spritesheet_textures_edit(Document& document, StringType edit, const std::function<bool()>& behavior,
const std::function<bool()>& behavior, StringType successToast, StringType failToast) StringType successToast, StringType failToast)
{ {
document.edit_begin(edit); document.edit_begin(edit);
auto isSuccess = behavior(); auto isSuccess = behavior();
toast_log(isSuccess ? Level::INFO : Level::ERROR, isSuccess ? successToast : failToast); toast_log(isSuccess ? Level::INFO : Level::ERROR, isSuccess ? successToast : failToast);
document.change(changeType); document.change();
} }
Window spritesheets_window_register() Window spritesheets_window_register()
@@ -91,7 +91,6 @@ namespace anm2ed::imgui
Window window{}; Window window{};
window.title = LABEL_SPRITESHEETS_WINDOW; window.title = LABEL_SPRITESHEETS_WINDOW;
window.isOpen = &Settings::windowIsSpritesheets; window.isOpen = &Settings::windowIsSpritesheets;
window.changeType = Document::SPRITESHEETS;
window.containerType = ElementType::SPRITESHEETS; window.containerType = ElementType::SPRITESHEETS;
window.elementType = ElementType::SPRITESHEET; window.elementType = ElementType::SPRITESHEET;
window.childLabel = "##Spritesheets Child"; window.childLabel = "##Spritesheets Child";
@@ -178,7 +177,7 @@ namespace anm2ed::imgui
auto unused = document.anm2.element_unused(ElementType::SPRITESHEET); auto unused = document.anm2.element_unused(ElementType::SPRITESHEET);
auto spritesheets = window_container_get(window, document); auto spritesheets = window_container_get(window, document);
if (unused.empty() || !spritesheets) return; if (unused.empty() || !spritesheets) return;
document.edit_apply(EDIT_REMOVE_UNUSED_SPRITESHEETS, window.changeType, document.edit_apply(EDIT_REMOVE_UNUSED_SPRITESHEETS,
[&](Anm2&) [&](Anm2&)
{ {
for (auto id : unused) for (auto id : unused)
@@ -192,7 +191,7 @@ namespace anm2ed::imgui
window.reload = [](Window& window, Manager&, Settings&, Document& document, Clipboard&) window.reload = [](Window& window, Manager&, Settings&, Document& document, Clipboard&)
{ {
auto selected = document.spritesheet.selection; auto selected = document.spritesheet.selection;
document.edit_apply(EDIT_RELOAD_SPRITESHEETS, window.changeType, document.edit_apply(EDIT_RELOAD_SPRITESHEETS,
[&](Anm2&) [&](Anm2&)
{ {
for (auto id : selected) for (auto id : selected)
@@ -295,7 +294,7 @@ namespace anm2ed::imgui
regionOrigin = (origin::Type)settings.mergeSpritesheetsRegionOrigin](Manager&, Document& document) regionOrigin = (origin::Type)settings.mergeSpritesheetsRegionOrigin](Manager&, Document& document)
{ {
spritesheet_textures_edit( spritesheet_textures_edit(
document, EDIT_MERGE_SPRITESHEETS, Document::ALL, document, EDIT_MERGE_SPRITESHEETS,
[&]() [&]()
{ {
if (!document.spritesheets_merge(ids, isAppendRight, isMakeRegions, isMakePrimaryRegion, if (!document.spritesheets_merge(ids, isAppendRight, isMakeRegions, isMakePrimaryRegion,
@@ -329,14 +328,13 @@ namespace anm2ed::imgui
auto result = window_popup_buttons_draw(manager, localize.get(BASIC_PACK), auto result = window_popup_buttons_draw(manager, localize.get(BASIC_PACK),
is_spritesheet_regions(document, window.editId), BASIC_CANCEL); is_spritesheet_regions(document, window.editId), BASIC_CANCEL);
if (result == PopupButton::CONFIRM) if (result == PopupButton::CONFIRM)
manager.command_push({manager.selected, manager.command_push(
[id = window.editId, padding = settings.packPadding](Manager&, Document& document) {manager.selected, [id = window.editId, padding = settings.packPadding](Manager&, Document& document)
{ {
spritesheet_textures_edit( spritesheet_textures_edit(
document, EDIT_PACK_SPRITESHEET, Document::SPRITESHEETS, document, EDIT_PACK_SPRITESHEET, [&]() { return document.spritesheet_pack(id, padding); },
[&]() { return document.spritesheet_pack(id, padding); }, TOAST_PACK_SPRITESHEET, TOAST_PACK_SPRITESHEET, TOAST_PACK_SPRITESHEET_FAILED);
TOAST_PACK_SPRITESHEET_FAILED); }});
}});
if (result != PopupButton::NONE) if (result != PopupButton::NONE)
{ {
window.editId = -1; window.editId = -1;
+2 -3
View File
@@ -209,13 +209,12 @@ namespace anm2ed::imgui
std::set<Reference> drag_frame_references_get(const Reference&); std::set<Reference> drag_frame_references_get(const Reference&);
// Queues an edit on the document; its result is selected (frames by default). // Queues an edit on the document; its result is selected (frames by default).
template <class Operation> template <class Operation>
void edit_push(StringType label, Document::ChangeType type, Operation operation, void edit_push(StringType label, Operation operation, std::function<void(Document&, const edit::Uids&)> select = {})
std::function<void(Document&, const edit::Uids&)> select = {})
{ {
command_push( command_push(
[=, this](Manager&, Document& document) mutable [=, this](Manager&, Document& document) mutable
{ {
auto uids = document.edit_apply(label, type, operation); auto uids = document.edit_apply(label, operation);
select ? select(document, uids) : frames_select_for(document, uids); select ? select(document, uids) : frames_select_for(document, uids);
}); });
} }
+14 -18
View File
@@ -7,8 +7,7 @@ namespace anm2ed::imgui
auto targetReference = reference; auto targetReference = reference;
auto time = (int)document.frameTime; auto time = (int)document.frameTime;
if (!animation || !command_item_reference_get(document, targetReference)) return; if (!animation || !command_item_reference_get(document, targetReference)) return;
edit_push(EDIT_INSERT_FRAME, Document::FRAMES, edit_push(EDIT_INSERT_FRAME, [=](Anm2& anm2) { return edit::frame_insert(anm2, targetReference, time); });
[=](Anm2& anm2) { return edit::frame_insert(anm2, targetReference, time); });
} }
void TimelineContext::frames_delete_action() void TimelineContext::frames_delete_action()
@@ -16,7 +15,7 @@ namespace anm2ed::imgui
auto selectedFrames = document.frame_references_get(Document::FrameReferenceFallback::NONE); auto selectedFrames = document.frame_references_get(Document::FrameReferenceFallback::NONE);
if (selectedFrames.empty()) return; if (selectedFrames.empty()) return;
edit_push( edit_push(
EDIT_DELETE_FRAMES, Document::FRAMES, [=](Anm2& anm2) { return edit::frames_delete(anm2, selectedFrames); }, EDIT_DELETE_FRAMES, [=](Anm2& anm2) { return edit::frames_delete(anm2, selectedFrames); },
[this](Document& document, const edit::Uids&) { frames_selection_set_reference_for(document); }); [this](Document& document, const edit::Uids&) { frames_selection_set_reference_for(document); });
} }
@@ -25,7 +24,7 @@ namespace anm2ed::imgui
auto selectedFrames = document.frame_references_get(Document::FrameReferenceFallback::NONE); auto selectedFrames = document.frame_references_get(Document::FrameReferenceFallback::NONE);
std::erase_if(selectedFrames, is_trigger_reference); std::erase_if(selectedFrames, is_trigger_reference);
if (selectedFrames.empty()) return; if (selectedFrames.empty()) return;
edit_push(EDIT_DUPLICATE_FRAMES, Document::FRAMES, edit_push(EDIT_DUPLICATE_FRAMES,
[=, focus = reference](Anm2& anm2) { return edit::frames_duplicate(anm2, selectedFrames, focus); }); [=, focus = reference](Anm2& anm2) { return edit::frames_duplicate(anm2, selectedFrames, focus); });
} }
@@ -46,8 +45,7 @@ namespace anm2ed::imgui
auto selectedFrames = document.frame_references_get(Document::FrameReferenceFallback::NONE); auto selectedFrames = document.frame_references_get(Document::FrameReferenceFallback::NONE);
std::erase_if(selectedFrames, is_trigger_reference); std::erase_if(selectedFrames, is_trigger_reference);
if (!is_frames_reverse_available(selectedFrames)) return; if (!is_frames_reverse_available(selectedFrames)) return;
edit_push(EDIT_REVERSE_FRAMES, Document::FRAMES, edit_push(EDIT_REVERSE_FRAMES, [=](Anm2& anm2) { return edit::frames_reverse(anm2, selectedFrames); });
[=](Anm2& anm2) { return edit::frames_reverse(anm2, selectedFrames); });
} }
void TimelineContext::frames_bake() void TimelineContext::frames_bake()
@@ -55,9 +53,8 @@ namespace anm2ed::imgui
auto selectedFrames = document.frame_references_get(Document::FrameReferenceFallback::NONE); auto selectedFrames = document.frame_references_get(Document::FrameReferenceFallback::NONE);
std::erase_if(selectedFrames, is_trigger_reference); std::erase_if(selectedFrames, is_trigger_reference);
if (selectedFrames.empty()) return; if (selectedFrames.empty()) return;
edit_push(EDIT_BAKE_FRAMES, Document::FRAMES, edit_push(EDIT_BAKE_FRAMES, [=, interval = settings.bakeInterval, isRoundScale = settings.bakeIsRoundScale,
[=, interval = settings.bakeInterval, isRoundScale = settings.bakeIsRoundScale, isRoundRotation = settings.bakeIsRoundRotation](Anm2& anm2)
isRoundRotation = settings.bakeIsRoundRotation](Anm2& anm2)
{ return edit::frames_bake(anm2, selectedFrames, interval, isRoundScale, isRoundRotation); }); { return edit::frames_bake(anm2, selectedFrames, interval, isRoundScale, isRoundRotation); });
} }
@@ -114,7 +111,7 @@ namespace anm2ed::imgui
document, *animation, bakeIntoOtherFramesTarget, isBakeIntoOtherFramesLayers, isBakeIntoOtherFramesNulls); document, *animation, bakeIntoOtherFramesTarget, isBakeIntoOtherFramesLayers, isBakeIntoOtherFramesNulls);
edit::RootBakeOptions options{settings.bakeIsRoundScale, settings.bakeIsRoundRotation, edit::RootBakeOptions options{settings.bakeIsRoundScale, settings.bakeIsRoundRotation,
settings.bakeIsMatchRootInterpolation, settings.bakeIsUseRootPivot}; settings.bakeIsMatchRootInterpolation, settings.bakeIsUseRootPivot};
edit_push(EDIT_BAKE_INTO_OTHER_FRAMES, Document::FRAMES, edit_push(EDIT_BAKE_INTO_OTHER_FRAMES,
[=](Anm2& anm2) { return edit::root_bake_into(anm2, selectedRootFrames, targetItems, options); }); [=](Anm2& anm2) { return edit::root_bake_into(anm2, selectedRootFrames, targetItems, options); });
} }
@@ -124,8 +121,7 @@ namespace anm2ed::imgui
if (selectedFrames.size() != 1) return; if (selectedFrames.size() != 1) return;
auto targetReference = *selectedFrames.begin(); auto targetReference = *selectedFrames.begin();
auto time = frameSplitTimeAtCursor.value_or((int)std::floor(playback.time)); auto time = frameSplitTimeAtCursor.value_or((int)std::floor(playback.time));
edit_push(EDIT_SPLIT_FRAME, Document::FRAMES, edit_push(EDIT_SPLIT_FRAME, [=](Anm2& anm2) { return edit::frame_split(anm2, targetReference, time); });
[=](Anm2& anm2) { return edit::frame_split(anm2, targetReference, time); });
} }
void TimelineContext::item_remove() void TimelineContext::item_remove()
@@ -136,7 +132,7 @@ namespace anm2ed::imgui
if (row.type == LAYER || row.type == NULL_) (row.isGroup ? groupIds : ids)[row.type].insert(row.id); if (row.type == LAYER || row.type == NULL_) (row.isGroup ? groupIds : ids)[row.type].insert(row.id);
if (!animation || (ids.empty() && groupIds.empty())) return; if (!animation || (ids.empty() && groupIds.empty())) return;
edit_push( edit_push(
EDIT_REMOVE_ITEMS, Document::ITEMS, [=, animationIndex = reference.animationIndex](Anm2& anm2) EDIT_REMOVE_ITEMS, [=, animationIndex = reference.animationIndex](Anm2& anm2)
{ return edit::items_remove(anm2, animationIndex, ids, groupIds); }, { return edit::items_remove(anm2, animationIndex, ids, groupIds); },
[this](Document& document, const edit::Uids&) [this](Document& document, const edit::Uids&)
{ {
@@ -176,7 +172,7 @@ namespace anm2ed::imgui
for (auto itemReference : targetReferences) for (auto itemReference : targetReferences)
ids.insert(itemReference.itemID); ids.insert(itemReference.itemID);
edit_push( edit_push(
EDIT_GROUP_ITEMS, Document::ITEMS, EDIT_GROUP_ITEMS,
[=, animationIndex = reference.animationIndex, type = targetReferences.front().itemType, [=, animationIndex = reference.animationIndex, type = targetReferences.front().itemType,
name = std::string(localize.get(TEXT_NEW_GROUP))](Anm2& anm2) name = std::string(localize.get(TEXT_NEW_GROUP))](Anm2& anm2)
{ return edit::items_group(anm2, animationIndex, type, ids, name); }, { return edit::items_group(anm2, animationIndex, type, ids, name); },
@@ -218,7 +214,7 @@ namespace anm2ed::imgui
if (!tracks.empty()) selection_focus_set(moved, anm2, *tracks.begin()); if (!tracks.empty()) selection_focus_set(moved, anm2, *tracks.begin());
edit_push( edit_push(
EDIT_MOVE_ITEMS, Document::ITEMS, EDIT_MOVE_ITEMS,
[=](Anm2& anm2) [=](Anm2& anm2)
{ {
return edit::items_move(anm2, animationIndex, targetType, ids, groupIds, target, isDropAfter, return edit::items_move(anm2, animationIndex, targetType, ids, groupIds, target, isDropAfter,
@@ -239,7 +235,7 @@ namespace anm2ed::imgui
void TimelineContext::fit_animation_length() void TimelineContext::fit_animation_length()
{ {
if (!animation) return; if (!animation) return;
edit_push(EDIT_FIT_ANIMATION_LENGTH, Document::ANIMATIONS, [animationIndex = reference.animationIndex](Anm2& anm2) edit_push(EDIT_FIT_ANIMATION_LENGTH, [animationIndex = reference.animationIndex](Anm2& anm2)
{ return edit::animation_length_fit(anm2, animationIndex); }); { return edit::animation_length_fit(anm2, animationIndex); });
} }
@@ -274,7 +270,7 @@ namespace anm2ed::imgui
if (selectedFrames.empty()) return; if (selectedFrames.empty()) return;
frame_references_copy(selectedFrames); frame_references_copy(selectedFrames);
edit_push( edit_push(
EDIT_CUT_FRAMES, Document::FRAMES, [=](Anm2& anm2) { return edit::frames_delete(anm2, selectedFrames); }, EDIT_CUT_FRAMES, [=](Anm2& anm2) { return edit::frames_delete(anm2, selectedFrames); },
[this](Document& document, const edit::Uids&) { frames_selection_set_reference_for(document); }); [this](Document& document, const edit::Uids&) { frames_selection_set_reference_for(document); });
} }
@@ -290,7 +286,7 @@ namespace anm2ed::imgui
auto errorString = std::make_shared<std::string>(); auto errorString = std::make_shared<std::string>();
edit_push( edit_push(
EDIT_PASTE_FRAMES, Document::FRAMES, EDIT_PASTE_FRAMES,
[=, targetReference = reference, [=, targetReference = reference,
selectedFrames = document.frame_references_get(Document::FrameReferenceFallback::NONE), selectedFrames = document.frame_references_get(Document::FrameReferenceFallback::NONE),
time = hoveredTime](Anm2& anm2) time = hoveredTime](Anm2& anm2)
+7 -7
View File
@@ -31,7 +31,7 @@ namespace anm2ed::imgui
Reference target{drag.animationIndex, targetType, targetID, -1, targetGroupType, targetGroupId}; Reference target{drag.animationIndex, targetType, targetID, -1, targetGroupType, targetGroupId};
edit_push( edit_push(
EDIT_MOVE_FRAMES, Document::FRAMES, EDIT_MOVE_FRAMES,
[frames = std::set<Reference>(drag.references.begin(), drag.references.end()), target, insertIndex](Anm2& anm2) [frames = std::set<Reference>(drag.references.begin(), drag.references.end()), target, insertIndex](Anm2& anm2)
{ return edit::frames_move(anm2, frames, target, insertIndex); }, { return edit::frames_move(anm2, frames, target, insertIndex); },
[=, this](Document& document, const edit::Uids& uids) [=, this](Document& document, const edit::Uids& uids)
@@ -424,7 +424,7 @@ namespace anm2ed::imgui
if (ImGui::IsKeyDown(ImGuiMod_Alt)) if (ImGui::IsKeyDown(ImGuiMod_Alt))
{ {
auto targetReference = frameReference; auto targetReference = frameReference;
edit_push(EDIT_FRAME_INTERPOLATION, Document::FRAMES, edit_push(EDIT_FRAME_INTERPOLATION,
[=](Anm2& anm2) [=](Anm2& anm2)
{ {
if (auto frame = anm2.element_get(targetReference)) if (auto frame = anm2.element_get(targetReference))
@@ -603,7 +603,7 @@ namespace anm2ed::imgui
{ {
auto item = command_item_reference_get(document, targetReference); auto item = command_item_reference_get(document, targetReference);
if (targetType == TRIGGER && item) frames_sort_by_at_frame(*item); if (targetType == TRIGGER && item) frames_sort_by_at_frame(*item);
document.change(Document::FRAMES); document.change();
}); });
isDraggedFrameActive = false; isDraggedFrameActive = false;
draggedFrameReference = {}; draggedFrameReference = {};
@@ -864,7 +864,7 @@ namespace anm2ed::imgui
if (isLengthChanged && animation) if (isLengthChanged && animation)
{ {
auto animationIndex = animationLengthEditIndex != -1 ? animationLengthEditIndex : currentAnimationIndex; auto animationIndex = animationLengthEditIndex != -1 ? animationLengthEditIndex : currentAnimationIndex;
edit_push(EDIT_ANIMATION_LENGTH, Document::ANIMATIONS, edit_push(EDIT_ANIMATION_LENGTH,
[=](Anm2& anm2) [=](Anm2& anm2)
{ {
auto animation = anm2.element_get(ElementType::ANIMATION, animationIndex); auto animation = anm2.element_get(ElementType::ANIMATION, animationIndex);
@@ -882,7 +882,7 @@ namespace anm2ed::imgui
if (ImGui::Checkbox(localize.get(LABEL_LOOP), &isLoop) && animation) if (ImGui::Checkbox(localize.get(LABEL_LOOP), &isLoop) && animation)
{ {
auto animationIndex = reference.animationIndex; auto animationIndex = reference.animationIndex;
edit_push(EDIT_LOOP, Document::ANIMATIONS, edit_push(EDIT_LOOP,
[=](Anm2& anm2) [=](Anm2& anm2)
{ {
auto animation = anm2.element_get(ElementType::ANIMATION, animationIndex); auto animation = anm2.element_get(ElementType::ANIMATION, animationIndex);
@@ -901,7 +901,7 @@ namespace anm2ed::imgui
ImGui::SetNextItemWidth(widgetSize.x); ImGui::SetNextItemWidth(widgetSize.x);
if (input_int_range(localize.get(LABEL_FPS), fps, FPS_MIN, FPS_MAX)) if (input_int_range(localize.get(LABEL_FPS), fps, FPS_MIN, FPS_MAX))
{ {
edit_push(EDIT_FPS, Document::INFO, edit_push(EDIT_FPS,
[=](Anm2& anm2) [=](Anm2& anm2)
{ {
auto info = element_first_get(anm2.root, ElementType::INFO); auto info = element_first_get(anm2.root, ElementType::INFO);
@@ -922,7 +922,7 @@ namespace anm2ed::imgui
ImGui::SetNextItemWidth(widgetSize.x); ImGui::SetNextItemWidth(widgetSize.x);
if (input_text_string(localize.get(LABEL_AUTHOR), &createdBy)) if (input_text_string(localize.get(LABEL_AUTHOR), &createdBy))
{ {
edit_push(EDIT_AUTHOR, Document::INFO, edit_push(EDIT_AUTHOR,
[=](Anm2& anm2) [=](Anm2& anm2)
{ {
auto info = element_first_get(anm2.root, ElementType::INFO); auto info = element_first_get(anm2.root, ElementType::INFO);
+1 -1
View File
@@ -206,7 +206,7 @@ namespace anm2ed::imgui
auto targetAnimationIndex = groupAnimationIndex; auto targetAnimationIndex = groupAnimationIndex;
auto targetType = groupType; auto targetType = groupType;
auto targetId = groupId; auto targetId = groupId;
edit_push(EDIT_RENAME_GROUP, Document::ITEMS, edit_push(EDIT_RENAME_GROUP,
[=](Anm2& anm2) [=](Anm2& anm2)
{ {
auto animation = anm2.element_get(ElementType::ANIMATION, targetAnimationIndex); auto animation = anm2.element_get(ElementType::ANIMATION, targetAnimationIndex);
+2 -2
View File
@@ -33,7 +33,7 @@ namespace anm2ed::imgui
auto result = window_popup_buttons_draw(manager, localize.get(LABEL_MAKE_MANY_REGIONS)); auto result = window_popup_buttons_draw(manager, localize.get(LABEL_MAKE_MANY_REGIONS));
if (result == PopupButton::CONFIRM) if (result == PopupButton::CONFIRM)
edit_push(EDIT_GENERATE_REGIONS_FROM_ANIMATIONS, Document::ALL, edit_push(EDIT_GENERATE_REGIONS_FROM_ANIMATIONS,
[targetFrames = makeManyRegionReferences, format = settings.generateRegionNameFormat, [targetFrames = makeManyRegionReferences, format = settings.generateRegionNameFormat,
mapping = isMakeManyRegionsMapFrames ? RegionFrameMapping::SET : RegionFrameMapping::PRESERVE]( mapping = isMakeManyRegionsMapFrames ? RegionFrameMapping::SET : RegionFrameMapping::PRESERVE](
Anm2& anm2) { anm2.regions_generate({}, targetFrames, format, mapping); }); Anm2& anm2) { anm2.regions_generate({}, targetFrames, format, mapping); });
@@ -183,7 +183,7 @@ namespace anm2ed::imgui
if (auto frame = command_frame_get(document, frameReference)) if (auto frame = command_frame_get(document, frameReference))
frame->duration = frame->duration =
std::clamp(frame->duration + resize.delta, FRAME_DURATION_MIN, FRAME_DURATION_MAX); std::clamp(frame->duration + resize.delta, FRAME_DURATION_MIN, FRAME_DURATION_MAX);
document.change(Document::FRAMES); document.change();
}); });
} }
isResizeChordHeld[i] = isPressed; isResizeChordHeld[i] = isPressed;
+4 -4
View File
@@ -40,7 +40,7 @@ namespace anm2ed::imgui
{ {
auto targetRow = row; auto targetRow = row;
auto targetAnimationIndex = reference.animationIndex; auto targetAnimationIndex = reference.animationIndex;
edit_push(EDIT_TOGGLE_GROUP_EXPANDED, Document::ITEMS, edit_push(EDIT_TOGGLE_GROUP_EXPANDED,
[=](Anm2& anm2) [=](Anm2& anm2)
{ {
auto animation = anm2.element_get(ElementType::ANIMATION, targetAnimationIndex); auto animation = anm2.element_get(ElementType::ANIMATION, targetAnimationIndex);
@@ -139,7 +139,7 @@ namespace anm2ed::imgui
auto targetType = type; auto targetType = type;
auto targetGroupId = group->id; auto targetGroupId = group->id;
auto targetVisible = !isGroupVisible; auto targetVisible = !isGroupVisible;
edit_push(EDIT_TOGGLE_ITEM_VISIBILITY, Document::FRAMES, edit_push(EDIT_TOGGLE_ITEM_VISIBILITY,
[=](Anm2& anm2) [=](Anm2& anm2)
{ {
auto animation = anm2.element_get(ElementType::ANIMATION, targetAnimationIndex); auto animation = anm2.element_get(ElementType::ANIMATION, targetAnimationIndex);
@@ -403,7 +403,7 @@ namespace anm2ed::imgui
auto targetID = id; auto targetID = id;
auto targetGroupType = row.rootGroupType; auto targetGroupType = row.rootGroupType;
auto targetGroupId = row.rootGroupId; auto targetGroupId = row.rootGroupId;
edit_push(EDIT_TOGGLE_ITEM_VISIBILITY, Document::FRAMES, edit_push(EDIT_TOGGLE_ITEM_VISIBILITY,
[=](Anm2& anm2) [=](Anm2& anm2)
{ {
if (auto item = anm2.element_get( if (auto item = anm2.element_get(
@@ -427,7 +427,7 @@ namespace anm2ed::imgui
if (ImGui::ImageButton("##Rect Toggle", resources.icon_id_get(rectIcon), icon_size_get())) if (ImGui::ImageButton("##Rect Toggle", resources.icon_id_get(rectIcon), icon_size_get()))
{ {
auto nullID = id; auto nullID = id;
edit_push(EDIT_TOGGLE_NULL_RECT, Document::FRAMES, edit_push(EDIT_TOGGLE_NULL_RECT,
[=](Anm2& anm2) [=](Anm2& anm2)
{ {
auto nulls = anm2.element_get(ElementType::NULLS); auto nulls = anm2.element_get(ElementType::NULLS);
+4 -4
View File
@@ -59,7 +59,7 @@ namespace anm2ed::imgui
auto target = auto target =
reference == -1 || !container ? nullptr : child_id_get(*container, window.elementType, reference); reference == -1 || !container ? nullptr : child_id_get(*container, window.elementType, reference);
if (!container || (reference != -1 && !target)) return; if (!container || (reference != -1 && !target)) return;
document.edit_apply(reference == -1 ? window.addEdit : window.propertiesEdit, window.changeType, document.edit_apply(reference == -1 ? window.addEdit : window.propertiesEdit,
[&](Anm2&) [&](Anm2&)
{ {
auto changed = edited; auto changed = edited;
@@ -100,7 +100,7 @@ namespace anm2ed::imgui
{ {
auto element = window_element_get(window, document, key); auto element = window_element_get(window, document, key);
if (!element || element->name == name) return; if (!element || element->name == name) return;
document.edit_apply(window.renameEdit, window.changeType, document.edit_apply(window.renameEdit,
[&](Anm2&) [&](Anm2&)
{ {
element->name = name; element->name = name;
@@ -133,7 +133,7 @@ namespace anm2ed::imgui
return; return;
} }
document.edit_apply(window.pasteEdit, window.changeType, document.edit_apply(window.pasteEdit,
[&](Anm2&) [&](Anm2&)
{ {
document.anm2 = std::move(pasted); document.anm2 = std::move(pasted);
@@ -152,7 +152,7 @@ namespace anm2ed::imgui
auto unused = document.anm2.element_unused(window.elementType); auto unused = document.anm2.element_unused(window.elementType);
auto container = window_container_get(window, document); auto container = window_container_get(window, document);
if (unused.empty() || !container) return; if (unused.empty() || !container) return;
document.edit_apply(window.removeUnusedEdit, window.changeType, document.edit_apply(window.removeUnusedEdit,
[&](Anm2&) [&](Anm2&)
{ {
for (auto id : unused) for (auto id : unused)
-1
View File
@@ -96,7 +96,6 @@ namespace anm2ed::imgui
StringType title{}; StringType title{};
bool Settings::* isOpen{}; bool Settings::* isOpen{};
Document::ChangeType changeType{};
ElementType containerType{ElementType::UNKNOWN}; ElementType containerType{ElementType::UNKNOWN};
ElementType elementType{ElementType::UNKNOWN}; ElementType elementType{ElementType::UNKNOWN};
const char* childLabel{"##Window Child"}; const char* childLabel{"##Window Child"};
@@ -257,7 +257,7 @@ namespace anm2ed::imgui::wizard
targets.references = {selectedItemReferences.begin(), selectedItemReferences.end()}; targets.references = {selectedItemReferences.begin(), selectedItemReferences.end()};
else else
targets.animations = queuedAnimations; targets.animations = queuedAnimations;
document.edit_apply(EDIT_CHANGE_FRAME_PROPERTIES, Document::FRAMES, [&](Anm2& anm2) document.edit_apply(EDIT_CHANGE_FRAME_PROPERTIES, [&](Anm2& anm2)
{ return edit::frames_change_apply(anm2, targets, frameChange, changeType); }); { return edit::frames_change_apply(anm2, targets, frameChange, changeType); });
}}); }});
isChanged = true; isChanged = true;
@@ -150,8 +150,7 @@ namespace anm2ed::imgui::wizard
{ {
edit::GridOptions options{queuedStartPosition, queuedSize, queuedPivot, queuedColumns, edit::GridOptions options{queuedStartPosition, queuedSize, queuedPivot, queuedColumns,
queuedCount, queuedDelay, queuedIsMakeRegions, queuedRegionNameFormat}; queuedCount, queuedDelay, queuedIsMakeRegions, queuedRegionNameFormat};
document.edit_apply(EDIT_GENERATE_ANIMATION_FROM_GRID, document.edit_apply(EDIT_GENERATE_ANIMATION_FROM_GRID, [&](Anm2& anm2)
queuedIsMakeRegions ? Document::ALL : Document::FRAMES, [&](Anm2& anm2)
{ return edit::animation_grid_generate(anm2, queuedLayerReferences, options); }); { return edit::animation_grid_generate(anm2, queuedLayerReferences, options); });
}}); }});
isEnd = true; isEnd = true;
+3 -3
View File
@@ -234,7 +234,7 @@ namespace anm2ed
selected = std::clamp(selected, 0, (int)documents.size() - 1); selected = std::clamp(selected, 0, (int)documents.size() - 1);
pendingSelected = selected; pendingSelected = selected;
if (selected >= 0 && selected < (int)documents.size()) documents[selected].change(Document::ALL); if (selected >= 0 && selected < (int)documents.size()) documents[selected].change();
} }
void Manager::set(int index) void Manager::set(int index)
@@ -250,7 +250,7 @@ namespace anm2ed
selected = index; selected = index;
selection_history_push(selected); selection_history_push(selected);
if (auto document = get()) document->change(Document::ALL); if (auto document = get()) document->change();
} }
void Manager::item_properties_open(ElementType type, int id) void Manager::item_properties_open(ElementType type, int id)
@@ -339,7 +339,7 @@ namespace anm2ed
{ {
document->isForceDirty = true; document->isForceDirty = true;
document->path = document->path_from_autosave_get(path); document->path = document->path_from_autosave_get(path);
document->change(Document::ALL); document->change();
} }
} }
} }