Render animation fixes, vs code tasks

This commit is contained in:
2026-03-15 13:22:53 -04:00
parent 1b5ba6b584
commit bbfafd7331
10 changed files with 102 additions and 16 deletions
+1 -1
View File
@@ -80,7 +80,7 @@ namespace anm2ed::anm2
bool animations_deserialize(const std::string&, int, std::set<int>&, std::string* = nullptr);
Item* item_get(int, Type, int = -1);
Reference layer_animation_add(Reference = {}, std::string = {}, int = 0,
Reference layer_animation_add(Reference = {}, int = -1, std::string = {}, int = 0,
types::destination::Type = types::destination::ALL);
Reference null_animation_add(Reference = {}, std::string = {}, bool = false,
types::destination::Type = types::destination::ALL);
+20 -6
View File
@@ -30,7 +30,7 @@ namespace anm2ed::anm2
return nullptr;
}
Reference Anm2::layer_animation_add(Reference reference, std::string name, int spritesheetID,
Reference Anm2::layer_animation_add(Reference reference, int insertBeforeID, std::string name, int spritesheetID,
destination::Type destination)
{
auto id = reference.itemID == -1 ? map::next_id_get(content.layers) : reference.itemID;
@@ -39,21 +39,35 @@ namespace anm2ed::anm2
layer.name = !name.empty() ? name : layer.name;
layer.spritesheetID = content.spritesheets.contains(spritesheetID) ? spritesheetID : 0;
auto add = [&](Animation* animation, int id)
auto add = [&](Animation* animation, int id, bool insertBeforeReference)
{
animation->layerAnimations[id] = Item();
if (insertBeforeReference && insertBeforeID != -1)
{
auto it = std::find(animation->layerOrder.begin(), animation->layerOrder.end(), insertBeforeID);
if (it != animation->layerOrder.end())
{
animation->layerOrder.insert(it, id);
return;
}
}
animation->layerOrder.push_back(id);
};
if (destination == destination::ALL)
{
for (auto& animation : animations.items)
if (!animation.layerAnimations.contains(id)) add(&animation, id);
for (size_t index = 0; index < animations.items.size(); ++index)
{
auto& animation = animations.items[index];
if (!animation.layerAnimations.contains(id)) add(&animation, id, true);
}
}
else if (destination == destination::THIS)
{
if (auto animation = animation_get(reference.animationIndex))
if (!animation->layerAnimations.contains(id)) add(animation, id);
if (!animation->layerAnimations.contains(id)) add(animation, id, true);
}
return {reference.animationIndex, LAYER, id};
@@ -82,4 +96,4 @@ namespace anm2ed::anm2
return {reference.animationIndex, NULL_, id};
}
}
}
+3 -2
View File
@@ -104,9 +104,10 @@ namespace anm2ed::anm2
{
bool noRegions = has_flag(flags, NO_REGIONS);
bool frameNoRegionValues = has_flag(flags, FRAME_NO_REGION_VALUES);
bool writeRegionValues = !frameNoRegionValues || noRegions;
bool hasValidRegion = !noRegions && regionID != -1;
bool writeRegionValues = !frameNoRegionValues || !hasValidRegion;
if (!noRegions && regionID != -1) element->SetAttribute("RegionId", regionID);
if (hasValidRegion) element->SetAttribute("RegionId", regionID);
element->SetAttribute("XPosition", position.x);
element->SetAttribute("YPosition", position.y);
if (writeRegionValues)