Holy vibecode Batman!

This commit is contained in:
shweet committed 2026-05-21 21:00:57 -04:00
1 parent 7db835e6d4
commit 1bc5199e3b
140 files changed
+11888 -9481

No files matched your search

+218 -94
View File
@@ -1,31 +1,34 @@
#include "change_all_frame_properties.hpp"
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <vector>
#include "math_.hpp"
#include "math.hpp"
#include "util/imgui/imgui.hpp"
using namespace anm2ed::util::math;
using namespace glm;
namespace anm2ed::imgui::wizard
{
namespace
enum ChangeDestination
{
enum ChangeDestination
{
CHANGE_DESTINATION_FRAMES,
CHANGE_DESTINATION_ANIMATIONS,
};
}
CHANGE_DESTINATION_FRAMES,
CHANGE_DESTINATION_ANIMATIONS,
CHANGE_DESTINATION_ITEMS,
};
void ChangeAllFrameProperties::update(Document& document, Settings& settings, bool isFromWizard)
void ChangeAllFrameProperties::update(Manager& manager, Document& document, Settings& settings, bool isFromWizard)
{
isChanged = false;
auto& anm2 = document.anm2;
auto& frames = document.frames.selection;
auto& frameReferences = document.frames.references;
auto& itemReferences = document.items.references;
auto& animations = document.animation.selection;
auto& isCropX = settings.changeIsCropX;
auto& isCropY = settings.changeIsCropY;
@@ -71,19 +74,56 @@ namespace anm2ed::imgui::wizard
auto& isNulls = settings.changeIsNulls;
auto& itemType = document.reference.itemType;
auto is_frame_reference_changeable = [](const Reference& reference) { return reference.itemType != TRIGGER; };
auto is_item_reference_changeable = [](const Reference& reference) { return reference.itemType != TRIGGER; };
auto selected_frame_references_get = [&]()
{
std::set<Reference> result = frameReferences;
if (result.empty())
for (auto frameIndex : frames)
result.insert({document.reference.animationIndex, itemType, document.reference.itemID, frameIndex});
std::erase_if(result, [&](const Reference& reference) { return !is_frame_reference_changeable(reference); });
return result;
};
auto selected_item_references_get = [&]()
{
std::set<Reference> result = itemReferences;
if (result.empty() && itemType != NONE)
result.insert({document.reference.animationIndex, itemType, document.reference.itemID});
std::erase_if(result, [&](const Reference& reference) { return !is_item_reference_changeable(reference); });
return result;
};
auto selectedFrameReferences = selected_frame_references_get();
auto selectedItemReferences = selected_item_references_get();
bool isFramesDestination = !isFromWizard || destination == CHANGE_DESTINATION_FRAMES;
bool isSelectedFramesAvailable = !frames.empty() && itemType != anm2::TRIGGER;
bool isItemsDestination = isFromWizard && destination == CHANGE_DESTINATION_ITEMS;
bool isSelectedFramesAvailable = !selectedFrameReferences.empty();
bool isSelectedItemsAvailable = !selectedItemReferences.empty();
bool isSelectedAnimationsAvailable = !animations.empty();
if (isFromWizard)
{
if (destination == CHANGE_DESTINATION_FRAMES && !isSelectedFramesAvailable && isSelectedAnimationsAvailable)
destination = CHANGE_DESTINATION_ANIMATIONS;
if (destination == CHANGE_DESTINATION_FRAMES && !isSelectedFramesAvailable)
destination = isSelectedItemsAvailable ? CHANGE_DESTINATION_ITEMS : CHANGE_DESTINATION_ANIMATIONS;
if (destination == CHANGE_DESTINATION_ITEMS && !isSelectedItemsAvailable)
destination = isSelectedFramesAvailable ? CHANGE_DESTINATION_FRAMES : CHANGE_DESTINATION_ANIMATIONS;
if (destination == CHANGE_DESTINATION_ANIMATIONS && !isSelectedAnimationsAvailable && isSelectedItemsAvailable)
destination = CHANGE_DESTINATION_ITEMS;
if (destination == CHANGE_DESTINATION_ANIMATIONS && !isSelectedAnimationsAvailable && isSelectedFramesAvailable)
destination = CHANGE_DESTINATION_FRAMES;
isFramesDestination = destination == CHANGE_DESTINATION_FRAMES;
isItemsDestination = destination == CHANGE_DESTINATION_ITEMS;
}
bool isLayerPropertyAvailable = isFramesDestination ? itemType == anm2::LAYER : isLayers;
auto isLayerPropertyAvailable = isFramesDestination
? std::ranges::any_of(selectedFrameReferences,
[](const Reference& reference)
{ return reference.itemType == LAYER; })
: isItemsDestination
? std::ranges::any_of(selectedItemReferences,
[](const Reference& reference)
{ return reference.itemType == LAYER; })
: isLayers;
#define PROPERTIES_WIDGET(body, checkboxLabel, isEnabled) \
ImGui::Checkbox(checkboxLabel, &isEnabled); \
@@ -212,9 +252,8 @@ namespace anm2ed::imgui::wizard
auto duration_value = [&](const char* checkboxLabel, const char* valueLabel, bool& isEnabled, int& value)
{
PROPERTIES_WIDGET(
input_int_range(valueLabel, value, anm2::FRAME_DURATION_MIN, anm2::FRAME_DURATION_MAX, STEP, STEP_FAST),
checkboxLabel, isEnabled);
PROPERTIES_WIDGET(input_int_range(valueLabel, value, FRAME_DURATION_MIN, FRAME_DURATION_MAX, STEP, STEP_FAST),
checkboxLabel, isEnabled);
};
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImGui::GetStyle().ItemInnerSpacing);
@@ -248,26 +287,22 @@ namespace anm2ed::imgui::wizard
std::vector<int> fallbackIds{-1};
std::vector<std::string> fallbackLabelsString{localize.get(BASIC_NONE)};
std::vector<const char*> fallbackLabels{fallbackLabelsString[0].c_str()};
std::vector<int> interpolationIds{anm2::Frame::Interpolation::NONE, anm2::Frame::Interpolation::LINEAR,
anm2::Frame::Interpolation::EASE_IN, anm2::Frame::Interpolation::EASE_OUT,
anm2::Frame::Interpolation::EASE_IN_OUT};
std::vector<std::string> interpolationLabelsString{
localize.get(BASIC_NONE), localize.get(BASIC_LINEAR), localize.get(BASIC_EASE_IN),
localize.get(BASIC_EASE_OUT), localize.get(BASIC_EASE_IN_OUT)};
std::vector<const char*> interpolationLabels{interpolationLabelsString[0].c_str(),
interpolationLabelsString[1].c_str(),
interpolationLabelsString[2].c_str(),
interpolationLabelsString[3].c_str(),
interpolationLabelsString[4].c_str()};
std::vector<int> interpolationIds{(int)Interpolation::NONE, (int)Interpolation::LINEAR, (int)Interpolation::EASE_IN,
(int)Interpolation::EASE_OUT, (int)Interpolation::EASE_IN_OUT};
std::vector<std::string> interpolationLabelsString{localize.get(BASIC_NONE), localize.get(BASIC_LINEAR),
localize.get(BASIC_EASE_IN), localize.get(BASIC_EASE_OUT),
localize.get(BASIC_EASE_IN_OUT)};
std::vector<const char*> interpolationLabels{
interpolationLabelsString[0].c_str(), interpolationLabelsString[1].c_str(),
interpolationLabelsString[2].c_str(), interpolationLabelsString[3].c_str(),
interpolationLabelsString[4].c_str()};
const Storage* regionStorage = nullptr;
if (itemType == anm2::LAYER && document.reference.itemID != -1)
if (itemType == LAYER && document.reference.itemID != -1)
{
if (auto layerIt = document.anm2.content.layers.find(document.reference.itemID);
layerIt != document.anm2.content.layers.end())
if (auto layer = anm2.element_get(ElementType::LAYER_ELEMENT, document.reference.itemID))
{
auto spritesheetID = layerIt->second.spritesheetID;
auto regionIt = document.regionBySpritesheet.find(spritesheetID);
auto regionIt = document.regionBySpritesheet.find(layer->spritesheetId);
if (regionIt != document.regionBySpritesheet.end()) regionStorage = &regionIt->second;
}
}
@@ -294,9 +329,9 @@ namespace anm2ed::imgui::wizard
#undef PROPERTIES_WIDGET
auto frame_change = [&](anm2::ChangeType changeType)
auto frame_change = [&](ChangeType changeType)
{
anm2::FrameChange frameChange;
FrameChange frameChange;
if (isCropX) frameChange.cropX = crop.x;
if (isCropY) frameChange.cropY = crop.y;
if (isSizeX) frameChange.sizeX = size.x;
@@ -309,7 +344,7 @@ namespace anm2ed::imgui::wizard
if (isScaleY) frameChange.scaleY = scale.y;
if (isRotation) frameChange.rotation = std::make_optional(rotation);
if (isDuration) frameChange.duration = std::make_optional(duration);
if (isRegion) frameChange.regionID = std::make_optional(regionId);
if (isRegion) frameChange.regionId = std::make_optional(regionId);
if (isTintR) frameChange.tintR = tint.r;
if (isTintG) frameChange.tintG = tint.g;
if (isTintB) frameChange.tintB = tint.b;
@@ -318,67 +353,148 @@ namespace anm2ed::imgui::wizard
if (isColorOffsetG) frameChange.colorOffsetG = colorOffset.g;
if (isColorOffsetB) frameChange.colorOffsetB = colorOffset.b;
if (isVisibleSet) frameChange.isVisible = std::make_optional(isVisible);
if (isInterpolationSet)
frameChange.interpolation = std::make_optional(static_cast<anm2::Frame::Interpolation>(interpolation));
if (isInterpolationSet) frameChange.interpolation = std::make_optional(static_cast<Interpolation>(interpolation));
if (isFlipXSet) frameChange.isFlipX = std::make_optional(isFlipX);
if (isFlipYSet) frameChange.isFlipY = std::make_optional(isFlipY);
auto all_frames_selection = [](anm2::Item& item)
{
std::set<int> selection{};
for (int i = 0; i < (int)item.frames.size(); ++i)
selection.insert(i);
return selection;
};
if (isFramesDestination && selectedFrameReferences.empty()) return;
if (isItemsDestination && selectedItemReferences.empty()) return;
if (isFramesDestination)
{
if (auto item = document.item_get())
{
DOCUMENT_EDIT(document, localize.get(EDIT_CHANGE_FRAME_PROPERTIES), Document::FRAMES,
item->frames_change(frameChange, itemType, changeType, frames));
auto queuedFrameReferences = selectedFrameReferences;
auto queuedItemReferences = selectedItemReferences;
auto queuedAnimations = animations;
auto queuedIsFramesDestination = isFramesDestination;
auto queuedIsItemsDestination = isItemsDestination;
auto queuedIsRoot = isRoot;
auto queuedIsLayers = isLayers;
auto queuedIsNulls = isNulls;
isChanged = true;
}
}
else
{
auto behavior = [&]()
{
for (auto animationIndex : animations)
{
if (animationIndex < 0 || animationIndex >= (int)document.anm2.animations.items.size()) continue;
auto& animation = document.anm2.animations.items[animationIndex];
manager.command_push({manager.selected,
[=](Manager&, Document& document)
{
auto all_frames_selection = [](const Element& item)
{
std::set<int> selection{};
int index{};
for (const auto& frame : item.children)
if (frame.type == ElementType::FRAME)
{
selection.insert(index);
++index;
}
return selection;
};
if (isRoot)
{
auto selection = all_frames_selection(animation.rootAnimation);
animation.rootAnimation.frames_change(frameChange, anm2::ROOT, changeType, selection);
}
auto& anm2 = document.anm2;
if (isLayers)
{
for (auto& [_, item] : animation.layerAnimations)
{
auto selection = all_frames_selection(item);
item.frames_change(frameChange, anm2::LAYER, changeType, selection);
}
}
if (queuedIsFramesDestination)
{
std::map<Reference, std::set<int>> groupedFrames{};
for (auto frameReference : queuedFrameReferences)
{
auto itemReference = frameReference;
itemReference.frameIndex = -1;
groupedFrames[itemReference].insert(frameReference.frameIndex);
}
if (isNulls)
{
for (auto& [_, item] : animation.nullAnimations)
{
auto selection = all_frames_selection(item);
item.frames_change(frameChange, anm2::NULL_, changeType, selection);
}
}
}
};
document.snapshot(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
for (auto& [itemReference, selection] : groupedFrames)
{
auto item = anm2.element_get(itemReference.animationIndex,
static_cast<ItemType>(itemReference.itemType),
itemReference.itemID);
if (!item) continue;
frames_change(*item, frameChange, static_cast<ItemType>(itemReference.itemType),
changeType, selection);
}
document.anm2_change(Document::FRAMES);
return;
}
DOCUMENT_EDIT(document, localize.get(EDIT_CHANGE_FRAME_PROPERTIES), Document::FRAMES, behavior());
isChanged = true;
}
if (queuedIsItemsDestination)
{
document.snapshot(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
for (auto itemReference : queuedItemReferences)
{
if (itemReference.itemType == TRIGGER) continue;
auto item = anm2.element_get(itemReference.animationIndex,
static_cast<ItemType>(itemReference.itemType),
itemReference.itemID);
if (!item) continue;
auto selection = all_frames_selection(*item);
frames_change(*item, frameChange, static_cast<ItemType>(itemReference.itemType),
changeType, selection);
}
document.anm2_change(Document::FRAMES);
return;
}
document.snapshot(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
for (auto animationIndex : queuedAnimations)
{
auto animation = anm2.element_get(ElementType::ANIMATION, animationIndex);
if (!animation) continue;
if (queuedIsRoot)
{
if (auto item = animation_item_get(*animation, ItemType::ROOT))
{
auto selection = all_frames_selection(*item);
frames_change(*item, frameChange, ItemType::ROOT, changeType, selection);
}
}
if (queuedIsLayers)
{
auto layerAnimations = element_child_first_get(*animation, ElementType::LAYER_ANIMATIONS);
if (layerAnimations)
{
auto item_change = [&](auto&& self, Element& item) -> void
{
if (item.type == ElementType::GROUP)
{
for (auto& child : item.children)
self(self, child);
return;
}
if (item.type == ElementType::LAYER_ANIMATION)
{
auto selection = all_frames_selection(item);
frames_change(item, frameChange, ItemType::LAYER, changeType, selection);
}
};
for (auto& item : layerAnimations->children)
item_change(item_change, item);
}
}
if (queuedIsNulls)
{
auto nullAnimations = element_child_first_get(*animation, ElementType::NULL_ANIMATIONS);
if (nullAnimations)
{
auto item_change = [&](auto&& self, Element& item) -> void
{
if (item.type == ElementType::GROUP)
{
for (auto& child : item.children)
self(self, child);
return;
}
if (item.type == ElementType::NULL_ANIMATION)
{
auto selection = all_frames_selection(item);
frames_change(item, frameChange, ItemType::NULL_, changeType, selection);
}
};
for (auto& item : nullAnimations->children)
item_change(item_change, item);
}
}
}
document.anm2_change(Document::FRAMES);
}});
isChanged = true;
};
ImGui::Separator();
@@ -394,12 +510,19 @@ namespace anm2ed::imgui::wizard
ImGui::SameLine();
ImGui::BeginDisabled(!isSelectedItemsAvailable);
ImGui::RadioButton(localize.get(LABEL_ITEMS), &destination, CHANGE_DESTINATION_ITEMS);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CHANGE_ALL_DESTINATION_ITEMS));
ImGui::EndDisabled();
ImGui::SameLine();
ImGui::BeginDisabled(!isSelectedAnimationsAvailable);
ImGui::RadioButton(localize.get(LABEL_ANIMATIONS_CHILD), &destination, CHANGE_DESTINATION_ANIMATIONS);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CHANGE_ALL_DESTINATION_ANIMATIONS));
ImGui::EndDisabled();
ImGui::BeginDisabled(isFramesDestination);
ImGui::BeginDisabled(isFramesDestination || isItemsDestination);
ImGui::Checkbox(localize.get(LABEL_ROOT), &isRoot);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CHANGE_ALL_ROOT));
ImGui::SameLine();
@@ -418,33 +541,34 @@ namespace anm2ed::imgui::wizard
isTintB || isTintA || isColorOffsetR || isColorOffsetG || isColorOffsetB || isRegion ||
isVisibleSet || isInterpolationSet || isFlipXSet || isFlipYSet;
bool isDestinationValid = isFramesDestination ? isSelectedFramesAvailable
: isSelectedAnimationsAvailable && (isRoot || isLayers || isNulls);
: isItemsDestination ? isSelectedItemsAvailable
: isSelectedAnimationsAvailable && (isRoot || isLayers || isNulls);
auto rowWidgetSize = widget_size_with_row_get(5);
ImGui::BeginDisabled(!isAnyProperty || !isDestinationValid);
if (ImGui::Button(localize.get(LABEL_ADJUST), rowWidgetSize)) frame_change(anm2::ADJUST);
if (ImGui::Button(localize.get(LABEL_ADJUST), rowWidgetSize)) frame_change(ChangeType::ADJUST);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ADJUST));
ImGui::SameLine();
if (ImGui::Button(localize.get(BASIC_ADD), rowWidgetSize)) frame_change(anm2::ADD);
if (ImGui::Button(localize.get(BASIC_ADD), rowWidgetSize)) frame_change(ChangeType::ADD);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ADD_VALUES));
ImGui::SameLine();
if (ImGui::Button(localize.get(LABEL_SUBTRACT), rowWidgetSize)) frame_change(anm2::SUBTRACT);
if (ImGui::Button(localize.get(LABEL_SUBTRACT), rowWidgetSize)) frame_change(ChangeType::SUBTRACT);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_SUBTRACT_VALUES));
ImGui::SameLine();
if (ImGui::Button(localize.get(LABEL_MULTIPLY), rowWidgetSize)) frame_change(anm2::MULTIPLY);
if (ImGui::Button(localize.get(LABEL_MULTIPLY), rowWidgetSize)) frame_change(ChangeType::MULTIPLY);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_MULTIPLY_VALUES));
ImGui::SameLine();
if (ImGui::Button(localize.get(LABEL_DIVIDE), rowWidgetSize)) frame_change(anm2::DIVIDE);
if (ImGui::Button(localize.get(LABEL_DIVIDE), rowWidgetSize)) frame_change(ChangeType::DIVIDE);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_DIVIDE_VALUES));
ImGui::EndDisabled();