From c71c48d303fe944d21b18a8a86fc63b4c1f00d43 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 28 Mar 2024 12:16:28 +0100 Subject: [PATCH] [cpp] inhert timeline parsing in SkeletonJson --- .../spine-cpp/src/spine/SkeletonJson.cpp | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp b/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp index 92c2903dc..c1eb5a2a7 100644 --- a/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp +++ b/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -171,7 +172,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { int bonesCount = 0; for (boneMap = bones->_child, i = 0; boneMap; boneMap = boneMap->_next, ++i) { BoneData *data; - const char *transformMode; + const char *inherit; BoneData *parent = 0; const char *parentName = Json::getString(boneMap, "parent", 0); @@ -194,16 +195,16 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { data->_scaleY = Json::getFloat(boneMap, "scaleY", 1); data->_shearX = Json::getFloat(boneMap, "shearX", 0); data->_shearY = Json::getFloat(boneMap, "shearY", 0); - transformMode = Json::getString(boneMap, "inherit", "normal"); + inherit = Json::getString(boneMap, "inherit", "normal"); data->_inherit = Inherit_Normal; - if (strcmp(transformMode, "normal") == 0) data->_inherit = Inherit_Normal; - else if (strcmp(transformMode, "onlyTranslation") == 0) + if (strcmp(inherit, "normal") == 0) data->_inherit = Inherit_Normal; + else if (strcmp(inherit, "onlyTranslation") == 0) data->_inherit = Inherit_OnlyTranslation; - else if (strcmp(transformMode, "noRotationOrReflection") == 0) + else if (strcmp(inherit, "noRotationOrReflection") == 0) data->_inherit = Inherit_NoRotationOrReflection; - else if (strcmp(transformMode, "noScale") == 0) + else if (strcmp(inherit, "noScale") == 0) data->_inherit = Inherit_NoScale; - else if (strcmp(transformMode, "noScaleOrReflection") == 0) + else if (strcmp(inherit, "noScaleOrReflection") == 0) data->_inherit = Inherit_NoScaleOrReflection; data->_skinRequired = Json::getBoolean(boneMap, "skin", false); @@ -1085,7 +1086,27 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { ShearYTimeline *timeline = new (__FILE__, __LINE__) ShearYTimeline(frames, frames, boneIndex); timelines.add(readTimeline(timelineMap->_child, timeline, 0, 1)); - } else { + } else if (strcmp(timelineMap->_name, "inherit") == 0) { + InheritTimeline *timeline = new (__FILE__, __LINE__) InheritTimeline(frames, boneIndex); + for (frame = 0;; frame++) { + float time = Json::getFloat(keyMap, "time", 0); + const char *value = Json::getString(keyMap, "value", "normal"); + Inherit inherit = Inherit_Normal; + if (strcmp(value, "normal") == 0) inherit = Inherit_Normal; + else if (strcmp(value, "onlyTranslation") == 0) + inherit = Inherit_OnlyTranslation; + else if (strcmp(value, "noRotationOrReflection") == 0) + inherit = Inherit_NoRotationOrReflection; + else if (strcmp(value, "noScale") == 0) + inherit = Inherit_NoScale; + else if (strcmp(value, "noScaleOrReflection") == 0) + inherit = Inherit_NoScaleOrReflection; + timeline->setFrame(frame, time, inherit); + nextMap = keyMap->_next; + if (!nextMap) break; + } + timelines.add(timeline); + }else { ContainerUtil::cleanUpVectorOfPointers(timelines); setError(NULL, "Invalid timeline type for a bone: ", timelineMap->_name); return NULL;