From 5ddbd64f29dcab544f9e6ed938694c841b168d7c Mon Sep 17 00:00:00 2001 From: Elia Sarti Date: Sat, 22 Jul 2023 22:48:35 +0100 Subject: [PATCH] Added interface to access calculated animation bounds. --- spriterengine/animation/animation.h | 9 ++++++++- spriterengine/entity/entity.cpp | 7 ++++++- spriterengine/entity/entity.h | 1 + .../loading/spriterdocumentloader.cpp | 20 +++++++++++++++++-- spriterengine/model/spritermodel.cpp | 5 +++++ spriterengine/model/spritermodel.h | 1 + 6 files changed, 39 insertions(+), 4 deletions(-) diff --git a/spriterengine/animation/animation.h b/spriterengine/animation/animation.h index 18fd10c..a52b625 100644 --- a/spriterengine/animation/animation.h +++ b/spriterengine/animation/animation.h @@ -32,6 +32,11 @@ namespace SpriterEngine std::string getName(); real getLength(); bool getIsLooping(); + + point getBoundsPosition() const { return boundsPosition; } + void setBoundsPosition(point position) { boundsPosition = position; } + point getBoundsSize() const { return boundsSize; } + void setBoundsSize(point size) { boundsSize = size; } void setupAnimationInstance(EntityInstance *entityInstance, EntityInstanceData *entityInstanceData, MainlineKeyInstanceVector *mainlineKeyInstances, TimelineInstanceVector *timelineInstances, real *length, bool *looping); @@ -58,7 +63,9 @@ namespace SpriterEngine TimelineVector tagTimelines; TimelineVector soundTimelines; TimelineVector triggerTimelines; - + + point boundsPosition; + point boundsSize; real animationLength; bool isLooping; }; diff --git a/spriterengine/entity/entity.cpp b/spriterengine/entity/entity.cpp index 015a392..2f59cf8 100644 --- a/spriterengine/entity/entity.cpp +++ b/spriterengine/entity/entity.cpp @@ -51,7 +51,12 @@ namespace SpriterEngine entityInstanceData->setTagInstance(THIS_ENTITY, ""); setupAnimationInstances(entityInstance, entityInstanceData); } - + + AnimationVector* Entity::getAnimations() + { + return &animations; + } + Object *Entity::setObject(std::string objectName, Object::ObjectType objectType) { switch (objectType) diff --git a/spriterengine/entity/entity.h b/spriterengine/entity/entity.h index 238100b..02e022d 100644 --- a/spriterengine/entity/entity.h +++ b/spriterengine/entity/entity.h @@ -39,6 +39,7 @@ namespace SpriterEngine EntityInstance *getNewEntityInstance(SpriterModel *model, ObjectFactory *objectFactory); void setupInstance(SpriterModel *model, EntityInstance *entityInstance, EntityInstanceData *entityInstanceData, ObjectFactory *objectFactory); + AnimationVector* getAnimations(); Animation *pushBackAnimation(std::string animationName, real length, bool looping); Object *setObject(std::string objectName, Object::ObjectType objectType); diff --git a/spriterengine/loading/spriterdocumentloader.cpp b/spriterengine/loading/spriterdocumentloader.cpp index 29506c4..69f395c 100644 --- a/spriterengine/loading/spriterdocumentloader.cpp +++ b/spriterengine/loading/spriterdocumentloader.cpp @@ -699,10 +699,10 @@ namespace SpriterEngine Animation *SpriterDocumentLoader::getNewAnimationFromAnimationElement(SpriterFileElementWrapper *animationElement, Entity *entity) { - Animation *newAnimation = 0; real animationLength = 0; bool animationLooping = true; SpriterFileAttributeWrapper *att = animationElement->getFirstAttribute("name"); + SpriterFileAttributeWrapper *att2 = nullptr; if (att->isValid()) { std::string animationName = att->getStringValue(); @@ -724,7 +724,23 @@ namespace SpriterEngine animationLooping = att->getStringValue() != "false"; } - return entity->pushBackAnimation(animationName, animationLength, animationLooping); + Animation *newAnimation = entity->pushBackAnimation(animationName, animationLength, animationLooping); + att = animationElement->getFirstAttribute("l"); + att2 = animationElement->getFirstAttribute("t"); + if (att->isValid() && att2->isValid()) + { + real l = att->getRealValue(), t = att2->getRealValue(); + newAnimation->setBoundsPosition({ l, t }); + + att = animationElement->getFirstAttribute("r"); + att2 = animationElement->getFirstAttribute("b"); + if (att->isValid() && att2->isValid()) + { + real r = att->getRealValue(), b = att2->getRealValue(); + newAnimation->setBoundsSize({ r - l, b - t }); + } + } + return newAnimation; } else { diff --git a/spriterengine/model/spritermodel.cpp b/spriterengine/model/spritermodel.cpp index 16cbd13..4817f45 100644 --- a/spriterengine/model/spritermodel.cpp +++ b/spriterengine/model/spritermodel.cpp @@ -121,6 +121,11 @@ namespace SpriterEngine fileReferences->push_back(new FileReference(it)); } } + + EntityVector* SpriterModel::getEntities() + { + return &entities; + } Entity *SpriterModel::pushBackEntity(std::string entityName) { diff --git a/spriterengine/model/spritermodel.h b/spriterengine/model/spritermodel.h index e42b409..f94f6e0 100644 --- a/spriterengine/model/spritermodel.h +++ b/spriterengine/model/spritermodel.h @@ -39,6 +39,7 @@ namespace SpriterEngine void appendEntityToInstanceByName(EntityInstance * entityInstance, std::string entityName); void setupFileReferences(FileReferenceVector *fileReferences); + EntityVector* getEntities(); Entity *pushBackEntity(std::string entityName); void pushBackImageFile(std::string initialFilePath, point initialDefaultPivot, atlasdata atlasData); void pushBackSoundFile(std::string initialFilePath);