From 3af35555a9e1044a4c481d27c6fa5a56e167e32e Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Mon, 14 Jun 2021 14:50:07 +0200 Subject: [PATCH] [c][cpp] Expose colors on bones, attachments. Closes #1823 --- spine-c/spine-c/include/spine/BoneData.h | 2 + .../include/spine/BoundingBoxAttachment.h | 1 + .../include/spine/ClippingAttachment.h | 1 + .../spine-c/include/spine/PathAttachment.h | 1 + spine-c/spine-c/include/spine/SkeletonData.h | 3 ++ spine-c/spine-c/src/spine/SkeletonBinary.c | 32 +++++++++++---- spine-c/spine-c/src/spine/SkeletonData.c | 2 + spine-c/spine-c/src/spine/SkeletonJson.c | 39 ++++++++++++++++--- spine-cpp/spine-cpp/include/spine/BoneData.h | 4 ++ .../include/spine/BoundingBoxAttachment.h | 6 +++ .../include/spine/ClippingAttachment.h | 4 ++ .../spine-cpp/include/spine/PathAttachment.h | 4 ++ .../spine-cpp/include/spine/PointAttachment.h | 4 ++ spine-cpp/spine-cpp/src/spine/BoneData.cpp | 7 +++- .../src/spine/BoundingBoxAttachment.cpp | 6 ++- .../src/spine/ClippingAttachment.cpp | 6 ++- .../spine-cpp/src/spine/PathAttachment.cpp | 6 ++- .../spine-cpp/src/spine/PointAttachment.cpp | 6 ++- .../spine-cpp/src/spine/SkeletonBinary.cpp | 19 ++++----- .../spine-cpp/src/spine/SkeletonJson.cpp | 25 ++++++------ 20 files changed, 136 insertions(+), 42 deletions(-) diff --git a/spine-c/spine-c/include/spine/BoneData.h b/spine-c/spine-c/include/spine/BoneData.h index 727a03076..6ed33d84c 100644 --- a/spine-c/spine-c/include/spine/BoneData.h +++ b/spine-c/spine-c/include/spine/BoneData.h @@ -31,6 +31,7 @@ #define SPINE_BONEDATA_H_ #include +#include #ifdef __cplusplus extern "C" { @@ -53,6 +54,7 @@ struct spBoneData { float x, y, rotation, scaleX, scaleY, shearX, shearY; spTransformMode transformMode; int/*bool*/ skinRequired; + spColor color; }; SP_API spBoneData *spBoneData_create(int index, const char *name, spBoneData *parent); diff --git a/spine-c/spine-c/include/spine/BoundingBoxAttachment.h b/spine-c/spine-c/include/spine/BoundingBoxAttachment.h index e86b002dc..39c2af34a 100644 --- a/spine-c/spine-c/include/spine/BoundingBoxAttachment.h +++ b/spine-c/spine-c/include/spine/BoundingBoxAttachment.h @@ -42,6 +42,7 @@ extern "C" { typedef struct spBoundingBoxAttachment { spVertexAttachment super; + spColor color; } spBoundingBoxAttachment; SP_API spBoundingBoxAttachment *spBoundingBoxAttachment_create(const char *name); diff --git a/spine-c/spine-c/include/spine/ClippingAttachment.h b/spine-c/spine-c/include/spine/ClippingAttachment.h index 38c84fa92..8bbb5efd3 100644 --- a/spine-c/spine-c/include/spine/ClippingAttachment.h +++ b/spine-c/spine-c/include/spine/ClippingAttachment.h @@ -43,6 +43,7 @@ extern "C" { typedef struct spClippingAttachment { spVertexAttachment super; spSlotData *endSlot; + spColor color; } spClippingAttachment; SP_API void _spClippingAttachment_dispose(spAttachment *self); diff --git a/spine-c/spine-c/include/spine/PathAttachment.h b/spine-c/spine-c/include/spine/PathAttachment.h index a12e929bf..3713be90f 100644 --- a/spine-c/spine-c/include/spine/PathAttachment.h +++ b/spine-c/spine-c/include/spine/PathAttachment.h @@ -45,6 +45,7 @@ typedef struct spPathAttachment { int lengthsLength; float *lengths; int/*bool*/ closed, constantSpeed; + spColor color; } spPathAttachment; SP_API spPathAttachment *spPathAttachment_create(const char *name); diff --git a/spine-c/spine-c/include/spine/SkeletonData.h b/spine-c/spine-c/include/spine/SkeletonData.h index 35aba2b48..8c2aa1ed8 100644 --- a/spine-c/spine-c/include/spine/SkeletonData.h +++ b/spine-c/spine-c/include/spine/SkeletonData.h @@ -48,6 +48,9 @@ typedef struct spSkeletonData { const char *version; const char *hash; float x, y, width, height; + float fps; + const char *imagesPath; + const char *audioPath; int stringsCount; char **strings; diff --git a/spine-c/spine-c/src/spine/SkeletonBinary.c b/spine-c/spine-c/src/spine/SkeletonBinary.c index 9a903f054..2918bd9f2 100644 --- a/spine-c/spine-c/src/spine/SkeletonBinary.c +++ b/spine-c/spine-c/src/spine/SkeletonBinary.c @@ -1002,7 +1002,10 @@ spAttachment *spSkeletonBinary_readAttachment(spSkeletonBinary *self, _dataInput int vertexCount = readVarint(input, 1); spAttachment *attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, 0); _readVertices(self, input, SUB_CAST(spVertexAttachment, attachment), vertexCount); - if (nonessential) readInt(input); /* Skip color. */ + if (nonessential) { + spBoundingBoxAttachment *bbox = SUB_CAST(spBoundingBoxAttachment, attachment); + readColor(input, &bbox->color.r, &bbox->color.g, &bbox->color.b, &bbox->color.a); + } spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); return attachment; } @@ -1079,7 +1082,9 @@ spAttachment *spSkeletonBinary_readAttachment(spSkeletonBinary *self, _dataInput for (i = 0; i < path->lengthsLength; ++i) { path->lengths[i] = readFloat(input) * self->scale; } - if (nonessential) readInt(input); /* Skip color. */ + if (nonessential) { + readColor(input, &path->color.r, &path->color.g, &path->color.b, &path->color.a); + } spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); return attachment; } @@ -1102,7 +1107,9 @@ spAttachment *spSkeletonBinary_readAttachment(spSkeletonBinary *self, _dataInput spAttachment *attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, 0); spClippingAttachment *clip = SUB_CAST(spClippingAttachment, attachment); _readVertices(self, input, SUB_CAST(spVertexAttachment, attachment), vertexCount); - if (nonessential) readInt(input); /* Skip color. */ + if (nonessential) { + readColor(input, &clip->color.r, &clip->color.g, &clip->color.b, &clip->color.a); + } clip->endSlot = skeletonData->slots[endSlotIndex]; spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); return attachment; @@ -1201,10 +1208,17 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const nonessential = readBoolean(input); if (nonessential) { - /* Skip images path & fps */ - readFloat(input); - FREE(readString(input)); - FREE(readString(input)); + skeletonData->fps = readFloat(input); + skeletonData->imagesPath = readString(input); + if (!strlen(skeletonData->imagesPath)) { + FREE(skeletonData->imagesPath); + skeletonData->imagesPath = 0; + } + skeletonData->audioPath = readString(input); + if (!strlen(skeletonData->audioPath)) { + FREE(skeletonData->audioPath); + skeletonData->audioPath = 0; + } } skeletonData->stringsCount = n = readVarint(input, 1); @@ -1251,7 +1265,9 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const break; } data->skinRequired = readBoolean(input); - if (nonessential) readInt(input); /* Skip bone color. */ + if (nonessential) { + readColor(input, &data->color.r, &data->color.g, &data->color.b, &data->color.a); + } skeletonData->bones[i] = data; } diff --git a/spine-c/spine-c/src/spine/SkeletonData.c b/spine-c/spine-c/src/spine/SkeletonData.c index 5ba417027..a350965df 100644 --- a/spine-c/spine-c/src/spine/SkeletonData.c +++ b/spine-c/spine-c/src/spine/SkeletonData.c @@ -76,6 +76,8 @@ void spSkeletonData_dispose(spSkeletonData *self) { FREE(self->hash); FREE(self->version); + FREE(self->imagesPath); + FREE(self->audioPath); FREE(self); } diff --git a/spine-c/spine-c/src/spine/SkeletonJson.c b/spine-c/spine-c/src/spine/SkeletonJson.c index 7035679ee..5520d7147 100644 --- a/spine-c/spine-c/src/spine/SkeletonJson.c +++ b/spine-c/spine-c/src/spine/SkeletonJson.c @@ -902,16 +902,15 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char if (skeleton) { MALLOC_STR(skeletonData->hash, Json_getString(skeleton, "hash", 0)); MALLOC_STR(skeletonData->version, Json_getString(skeleton, "spine", 0)); - if (strcmp(skeletonData->version, "3.8.75") == 0) { - spSkeletonData_dispose(skeletonData); - _spSkeletonJson_setError(self, root, - "Unsupported skeleton data, please export with a newer version of Spine.", ""); - return 0; - } skeletonData->x = Json_getFloat(skeleton, "x", 0); skeletonData->y = Json_getFloat(skeleton, "y", 0); skeletonData->width = Json_getFloat(skeleton, "width", 0); skeletonData->height = Json_getFloat(skeleton, "height", 0); + skeletonData->fps = Json_getFloat(skeleton, "fps", 30); + skeletonData->imagesPath = Json_getString(skeleton, "images", 0); + if (skeletonData->imagesPath) skeletonData->imagesPath = strdup(skeletonData->imagesPath); + skeletonData->audioPath = Json_getString(skeleton, "audio", 0); + if (skeletonData->audioPath) skeletonData->audioPath = strdup(skeletonData->audioPath); } /* Bones. */ @@ -920,6 +919,7 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char for (boneMap = bones->child, i = 0; boneMap; boneMap = boneMap->next, ++i) { spBoneData *data; const char *transformMode; + const char *color; spBoneData *parent = 0; const char *parentName = Json_getString(boneMap, "parent", 0); @@ -952,6 +952,9 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char data->transformMode = SP_TRANSFORMMODE_NOSCALEORREFLECTION; data->skinRequired = Json_getInt(boneMap, "skin", 0) ? 1 : 0; + color = Json_getString(boneMap, "color", 0); + if (color) toColor2(&data->color, color, -1); + skeletonData->bones[i] = data; skeletonData->bonesCount++; } @@ -1370,6 +1373,14 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char int vertexCount = Json_getInt(attachmentMap, "vertexCount", 0) << 1; _readVertices(self, attachmentMap, SUPER(box), vertexCount); box->super.verticesCount = vertexCount; + color = Json_getString(attachmentMap, "color", 0); + if (color) { + spColor_setFromFloats(&box->color, + toColor(color, 0), + toColor(color, 1), + toColor(color, 2), + toColor(color, 3)); + } spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); break; } @@ -1387,6 +1398,14 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char curves = Json_getItem(attachmentMap, "lengths"); for (curves = curves->child, ii = 0; curves; curves = curves->next, ++ii) pathAttachment->lengths[ii] = curves->valueFloat * self->scale; + color = Json_getString(attachmentMap, "color", 0); + if (color) { + spColor_setFromFloats(&pathAttachment->color, + toColor(color, 0), + toColor(color, 1), + toColor(color, 2), + toColor(color, 3)); + } break; } case SP_ATTACHMENT_POINT: { @@ -1415,6 +1434,14 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char } vertexCount = Json_getInt(attachmentMap, "vertexCount", 0) << 1; _readVertices(self, attachmentMap, SUPER(clip), vertexCount); + color = Json_getString(attachmentMap, "color", 0); + if (color) { + spColor_setFromFloats(&clip->color, + toColor(color, 0), + toColor(color, 1), + toColor(color, 2), + toColor(color, 3)); + } spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); break; } diff --git a/spine-cpp/spine-cpp/include/spine/BoneData.h b/spine-cpp/spine-cpp/include/spine/BoneData.h index 9fa05020a..d2c650773 100644 --- a/spine-cpp/spine-cpp/include/spine/BoneData.h +++ b/spine-cpp/spine-cpp/include/spine/BoneData.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace spine { class SP_API BoneData : public SpineObject { @@ -122,6 +123,8 @@ namespace spine { void setSkinRequired(bool inValue); + Color &getColor(); + private: const int _index; const String _name; @@ -130,6 +133,7 @@ namespace spine { float _x, _y, _rotation, _scaleX, _scaleY, _shearX, _shearY; TransformMode _transformMode; bool _skinRequired; + Color _color; }; } diff --git a/spine-cpp/spine-cpp/include/spine/BoundingBoxAttachment.h b/spine-cpp/spine-cpp/include/spine/BoundingBoxAttachment.h index 934a56406..367fe4bbf 100644 --- a/spine-cpp/spine-cpp/include/spine/BoundingBoxAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/BoundingBoxAttachment.h @@ -31,6 +31,7 @@ #define Spine_BoundingBoxAttachment_h #include +#include #include namespace spine { @@ -38,9 +39,14 @@ namespace spine { class SP_API BoundingBoxAttachment : public VertexAttachment { RTTI_DECL + public: explicit BoundingBoxAttachment(const String &name); + Color &getColor(); + virtual Attachment *copy(); + private: + Color _color; }; } diff --git a/spine-cpp/spine-cpp/include/spine/ClippingAttachment.h b/spine-cpp/spine-cpp/include/spine/ClippingAttachment.h index e3b959051..05db2d2a2 100644 --- a/spine-cpp/spine-cpp/include/spine/ClippingAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/ClippingAttachment.h @@ -31,6 +31,7 @@ #define Spine_ClippingAttachment_h #include +#include namespace spine { class SlotData; @@ -51,10 +52,13 @@ namespace spine { void setEndSlot(SlotData *inValue); + Color &getColor(); + virtual Attachment *copy(); private: SlotData *_endSlot; + Color _color; }; } diff --git a/spine-cpp/spine-cpp/include/spine/PathAttachment.h b/spine-cpp/spine-cpp/include/spine/PathAttachment.h index 3a6ffbdc8..6ab1e99c9 100644 --- a/spine-cpp/spine-cpp/include/spine/PathAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/PathAttachment.h @@ -31,6 +31,7 @@ #define Spine_PathAttachment_h #include +#include namespace spine { class SP_API PathAttachment : public VertexAttachment { @@ -54,12 +55,15 @@ namespace spine { void setConstantSpeed(bool inValue); + Color &getColor(); + virtual Attachment *copy(); private: Vector _lengths; bool _closed; bool _constantSpeed; + Color _color; }; } diff --git a/spine-cpp/spine-cpp/include/spine/PointAttachment.h b/spine-cpp/spine-cpp/include/spine/PointAttachment.h index bdc51757d..940cd7520 100644 --- a/spine-cpp/spine-cpp/include/spine/PointAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/PointAttachment.h @@ -31,6 +31,7 @@ #define Spine_PointAttachment_h #include +#include namespace spine { class Bone; @@ -67,10 +68,13 @@ namespace spine { void setRotation(float inValue); + Color &getColor(); + virtual Attachment *copy(); private: float _x, _y, _rotation; + Color _color; }; } diff --git a/spine-cpp/spine-cpp/src/spine/BoneData.cpp b/spine-cpp/spine-cpp/src/spine/BoneData.cpp index 36a322163..419ee4eec 100644 --- a/spine-cpp/spine-cpp/src/spine/BoneData.cpp +++ b/spine-cpp/spine-cpp/src/spine/BoneData.cpp @@ -50,7 +50,8 @@ BoneData::BoneData(int index, const String &name, BoneData *parent) : _shearX(0), _shearY(0), _transformMode(TransformMode_Normal), - _skinRequired(false) { + _skinRequired(false), + _color() { assert(index >= 0); assert(_name.length() > 0); } @@ -146,3 +147,7 @@ bool BoneData::isSkinRequired() { void BoneData::setSkinRequired(bool inValue) { _skinRequired = inValue; } + +Color &BoneData::getColor() { + return _color; +} diff --git a/spine-cpp/spine-cpp/src/spine/BoundingBoxAttachment.cpp b/spine-cpp/spine-cpp/src/spine/BoundingBoxAttachment.cpp index d081ca992..1b6d83781 100644 --- a/spine-cpp/spine-cpp/src/spine/BoundingBoxAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/BoundingBoxAttachment.cpp @@ -37,7 +37,11 @@ using namespace spine; RTTI_IMPL(BoundingBoxAttachment, VertexAttachment) -BoundingBoxAttachment::BoundingBoxAttachment(const String &name) : VertexAttachment(name) { +BoundingBoxAttachment::BoundingBoxAttachment(const String &name) : VertexAttachment(name), _color() { +} + +Color &BoundingBoxAttachment::getColor() { + return _color; } Attachment *BoundingBoxAttachment::copy() { diff --git a/spine-cpp/spine-cpp/src/spine/ClippingAttachment.cpp b/spine-cpp/spine-cpp/src/spine/ClippingAttachment.cpp index 67f1fe9f1..094552fa8 100644 --- a/spine-cpp/spine-cpp/src/spine/ClippingAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/ClippingAttachment.cpp @@ -39,7 +39,7 @@ using namespace spine; RTTI_IMPL(ClippingAttachment, VertexAttachment) -ClippingAttachment::ClippingAttachment(const String &name) : VertexAttachment(name), _endSlot(NULL) { +ClippingAttachment::ClippingAttachment(const String &name) : VertexAttachment(name), _endSlot(NULL), _color() { } SlotData *ClippingAttachment::getEndSlot() { @@ -50,6 +50,10 @@ void ClippingAttachment::setEndSlot(SlotData *inValue) { _endSlot = inValue; } +Color &ClippingAttachment::getColor() { + return _color; +} + Attachment *ClippingAttachment::copy() { ClippingAttachment *copy = new(__FILE__, __LINE__) ClippingAttachment(getName()); copyTo(copy); diff --git a/spine-cpp/spine-cpp/src/spine/PathAttachment.cpp b/spine-cpp/spine-cpp/src/spine/PathAttachment.cpp index 558ffde8b..428fbbf15 100644 --- a/spine-cpp/spine-cpp/src/spine/PathAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathAttachment.cpp @@ -37,7 +37,7 @@ using namespace spine; RTTI_IMPL(PathAttachment, VertexAttachment) -PathAttachment::PathAttachment(const String &name) : VertexAttachment(name), _closed(false), _constantSpeed(false) { +PathAttachment::PathAttachment(const String &name) : VertexAttachment(name), _closed(false), _constantSpeed(false), _color() { } Vector &PathAttachment::getLengths() { @@ -60,6 +60,10 @@ void PathAttachment::setConstantSpeed(bool inValue) { _constantSpeed = inValue; } +Color &PathAttachment::getColor() { + return _color; +} + Attachment *PathAttachment::copy() { PathAttachment *copy = new(__FILE__, __LINE__) PathAttachment(getName()); copyTo(copy); diff --git a/spine-cpp/spine-cpp/src/spine/PointAttachment.cpp b/spine-cpp/spine-cpp/src/spine/PointAttachment.cpp index 1d6804770..c49bd0000 100644 --- a/spine-cpp/spine-cpp/src/spine/PointAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/PointAttachment.cpp @@ -41,7 +41,7 @@ using namespace spine; RTTI_IMPL(PointAttachment, Attachment) -PointAttachment::PointAttachment(const String &name) : Attachment(name), _x(0), _y(0), _rotation(0) { +PointAttachment::PointAttachment(const String &name) : Attachment(name), _x(0), _y(0), _rotation(0), _color() { } void PointAttachment::computeWorldPosition(Bone &bone, float &ox, float &oy) { @@ -81,6 +81,10 @@ void PointAttachment::setRotation(float inValue) { _rotation = inValue; } +Color &PointAttachment::getColor() { + return _color; +} + Attachment *PointAttachment::copy() { PointAttachment *copy = new(__FILE__, __LINE__) PointAttachment(getName()); copy->_x = _x; diff --git a/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp b/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp index aea726574..57ebcb973 100644 --- a/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp +++ b/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp @@ -127,7 +127,6 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons nonessential = readBoolean(input); if (nonessential) { - /* Skip images path, audio path & fps */ skeletonData->_fps = readFloat(input); skeletonData->_imagesPath.own(readString(input)); skeletonData->_audioPath.own(readString(input)); @@ -154,7 +153,9 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons data->_length = readFloat(input) * _scale; data->_transformMode = static_cast(readVarint(input, true)); data->_skinRequired = readBoolean(input); - if (nonessential) readInt(input); /* Skip bone color. */ + if (nonessential) { + readColor(input, data->getColor()); + } skeletonData->_bones[i] = data; } @@ -315,7 +316,7 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons eventData->_intValue = readVarint(input, false); eventData->_floatValue = readFloat(input); eventData->_stringValue.own(readString(input)); - eventData->_audioPath.own(readString(input)); // skip audio path + eventData->_audioPath.own(readString(input)); if (!eventData->_audioPath.isEmpty()) { eventData->_volume = readFloat(input); eventData->_balance = readFloat(input); @@ -515,8 +516,7 @@ Attachment *SkeletonBinary::readAttachment(DataInput *input, Skin *skin, int slo } readVertices(input, static_cast(box), vertexCount); if (nonessential) { - /* Skip color. */ - readInt(input); + readColor(input, box->getColor()); } _attachmentLoader->configureAttachment(box); return box; @@ -591,8 +591,7 @@ Attachment *SkeletonBinary::readAttachment(DataInput *input, Skin *skin, int slo path->_lengths[i] = readFloat(input) * _scale; } if (nonessential) { - /* Skip color. */ - readInt(input); + readColor(input, path->getColor()); } _attachmentLoader->configureAttachment(path); return path; @@ -608,8 +607,7 @@ Attachment *SkeletonBinary::readAttachment(DataInput *input, Skin *skin, int slo point->_y = readFloat(input) * _scale; if (nonessential) { - /* Skip color. */ - readInt(input); + readColor(input, point->getColor()); } _attachmentLoader->configureAttachment(point); return point; @@ -625,8 +623,7 @@ Attachment *SkeletonBinary::readAttachment(DataInput *input, Skin *skin, int slo readVertices(input, static_cast(clip), vertexCount); clip->_endSlot = skeletonData->_slots[endSlotIndex]; if (nonessential) { - /* Skip color. */ - readInt(input); + readColor(input, clip->getColor()); } _attachmentLoader->configureAttachment(clip); return clip; diff --git a/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp b/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp index aba1b4f67..b40bf4bcb 100644 --- a/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp +++ b/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp @@ -205,6 +205,9 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { data->_transformMode = TransformMode_NoScaleOrReflection; data->_skinRequired = Json::getBoolean(boneMap, "skin", false); + const char* color = Json::getString(boneMap, "color", NULL); + if (color) toColor(data->getColor(), color, true); + skeletonData->_bones[i] = data; bonesCount++; } @@ -548,12 +551,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { region->_height = Json::getFloat(attachmentMap, "height", 32) * _scale; color = Json::getString(attachmentMap, "color", 0); - if (color) { - region->getColor().r = toColor(color, 0); - region->getColor().g = toColor(color, 1); - region->getColor().b = toColor(color, 2); - region->getColor().a = toColor(color, 3); - } + if (color) toColor(region->getColor(), color, true); region->updateOffset(); _attachmentLoader->configureAttachment(region); @@ -573,12 +571,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { mesh->_path = attachmentPath; color = Json::getString(attachmentMap, "color", 0); - if (color) { - mesh->getColor().r = toColor(color, 0); - mesh->getColor().g = toColor(color, 1); - mesh->getColor().b = toColor(color, 2); - mesh->getColor().a = toColor(color, 3); - } + if (color) toColor(mesh->getColor(), color, true); mesh->_width = Json::getFloat(attachmentMap, "width", 32) * _scale; mesh->_height = Json::getFloat(attachmentMap, "height", 32) * _scale; @@ -633,6 +626,8 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { int vertexCount = Json::getInt(attachmentMap, "vertexCount", 0) << 1; readVertices(attachmentMap, box, vertexCount); + color = Json::getString(attachmentMap, "color", NULL); + if (color) toColor(box->getColor(), color, true); _attachmentLoader->configureAttachment(attachment); break; } @@ -654,6 +649,8 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { curves = Json::getItem(attachmentMap, "lengths"); for (curves = curves->_child, ii = 0; curves; curves = curves->_next, ++ii) pathAttatchment->_lengths[ii] = curves->_valueFloat * _scale; + color = Json::getString(attachmentMap, "color", NULL); + if (color) toColor(pathAttatchment->getColor(), color, true); _attachmentLoader->configureAttachment(attachment); break; } @@ -665,6 +662,8 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { point->_x = Json::getFloat(attachmentMap, "x", 0) * _scale; point->_y = Json::getFloat(attachmentMap, "y", 0) * _scale; point->_rotation = Json::getFloat(attachmentMap, "rotation", 0); + color = Json::getString(attachmentMap, "color", NULL); + if (color) toColor(point->getColor(), color, true); _attachmentLoader->configureAttachment(attachment); break; } @@ -678,6 +677,8 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { if (end) clip->_endSlot = skeletonData->findSlot(end); vertexCount = Json::getInt(attachmentMap, "vertexCount", 0) << 1; readVertices(attachmentMap, clip, vertexCount); + color = Json::getString(attachmentMap, "color", NULL); + if (color) toColor(clip->getColor(), color, true); _attachmentLoader->configureAttachment(attachment); break; }