Per attachment color.

This commit is contained in:
NathanSweet 2014-04-27 22:02:44 +02:00
parent 55c98fc7f1
commit cf9a3a4109
4 changed files with 17 additions and 5 deletions

View File

@ -38,7 +38,7 @@ extern "C" {
struct spSlot;
typedef enum {
ATTACHMENT_REGION, ATTACHMENT_REGION_SEQUENCE, ATTACHMENT_BOUNDING_BOX
ATTACHMENT_REGION, ATTACHMENT_BOUNDING_BOX
} spAttachmentType;
typedef struct spAttachment spAttachment;

View File

@ -47,6 +47,7 @@ typedef struct spRegionAttachment spRegionAttachment;
struct spRegionAttachment {
spAttachment super;
float x, y, scaleX, scaleY, rotation, width, height;
float r, g, b, a;
void* rendererObject;
int regionOffsetX, regionOffsetY; /* Pixels stripped from the bottom left, unrotated. */

View File

@ -43,6 +43,10 @@ spRegionAttachment* spRegionAttachment_create (const char* name) {
spRegionAttachment* self = NEW(spRegionAttachment);
self->scaleX = 1;
self->scaleY = 1;
self->r = 1;
self->g = 1;
self->b = 1;
self->a = 1;
_spAttachment_init(SUPER(self), name, ATTACHMENT_REGION, _spRegionAttachment_dispose);
return self;
}

View File

@ -414,6 +414,7 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
spAttachment* attachment;
const char* skinAttachmentName = attachmentMap->name;
const char* attachmentName = Json_getString(attachmentMap, "name", skinAttachmentName);
const char* color;
const char* typeString = Json_getString(attachmentMap, "type", "region");
spAttachmentType type;
@ -421,8 +422,6 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
type = ATTACHMENT_REGION;
else if (strcmp(typeString, "boundingbox") == 0)
type = ATTACHMENT_BOUNDING_BOX;
else if (strcmp(typeString, "regionsequence") == 0)
type = ATTACHMENT_REGION_SEQUENCE;
else {
spSkeletonData_dispose(skeletonData);
_spSkeletonJson_setError(self, root, "Unknown attachment type: ", typeString);
@ -440,8 +439,7 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
}
switch (attachment->type) {
case ATTACHMENT_REGION:
case ATTACHMENT_REGION_SEQUENCE: {
case ATTACHMENT_REGION: {
spRegionAttachment* regionAttachment = (spRegionAttachment*)attachment;
regionAttachment->x = Json_getFloat(attachmentMap, "x", 0) * self->scale;
regionAttachment->y = Json_getFloat(attachmentMap, "y", 0) * self->scale;
@ -450,6 +448,15 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
regionAttachment->rotation = Json_getFloat(attachmentMap, "rotation", 0);
regionAttachment->width = Json_getFloat(attachmentMap, "width", 32) * self->scale;
regionAttachment->height = Json_getFloat(attachmentMap, "height", 32) * self->scale;
color = Json_getString(slotMap, "color", 0);
if (color) {
regionAttachment->r = toColor(color, 0);
regionAttachment->g = toColor(color, 1);
regionAttachment->b = toColor(color, 2);
regionAttachment->a = toColor(color, 3);
}
spRegionAttachment_updateOffset(regionAttachment);
break;
}