mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 09:46:02 +08:00
[cpp] Json parser fixes
This commit is contained in:
parent
5631eb9750
commit
96c8bcf07f
@ -187,6 +187,34 @@ namespace spine {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lastIndexOf(const char c) {
|
||||||
|
for (int i = length() - 1; i >= 0; i--) {
|
||||||
|
if (buffer()[i] == c) return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
String substring(int startIndex, int length) const {
|
||||||
|
if (startIndex < 0 || startIndex >= _length || length < 0 || startIndex + length > _length) {
|
||||||
|
return String();
|
||||||
|
}
|
||||||
|
char* subStr = SpineExtension::calloc<char>(length + 1, __FILE__, __LINE__);
|
||||||
|
memcpy(subStr, _buffer + startIndex, length);
|
||||||
|
subStr[length] = '\0';
|
||||||
|
return String(subStr, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
String substring(int startIndex) const {
|
||||||
|
if (startIndex < 0 || startIndex >= _length) {
|
||||||
|
return String();
|
||||||
|
}
|
||||||
|
int length = _length - startIndex;
|
||||||
|
char* subStr = SpineExtension::calloc<char>(length + 1, __FILE__, __LINE__);
|
||||||
|
memcpy(subStr, _buffer + startIndex, length);
|
||||||
|
subStr[length] = '\0';
|
||||||
|
return String(subStr, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
friend bool operator==(const String &a, const String &b) {
|
friend bool operator==(const String &a, const String &b) {
|
||||||
if (a._buffer == b._buffer) return true;
|
if (a._buffer == b._buffer) return true;
|
||||||
if (a._length != b._length) return false;
|
if (a._length != b._length) return false;
|
||||||
|
|||||||
@ -161,6 +161,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) {
|
|||||||
skeletonData->_y = Json::getFloat(skeleton, "y", 0);
|
skeletonData->_y = Json::getFloat(skeleton, "y", 0);
|
||||||
skeletonData->_width = Json::getFloat(skeleton, "width", 0);
|
skeletonData->_width = Json::getFloat(skeleton, "width", 0);
|
||||||
skeletonData->_height = Json::getFloat(skeleton, "height", 0);
|
skeletonData->_height = Json::getFloat(skeleton, "height", 0);
|
||||||
|
skeletonData->_referenceScale = Json::getFloat(skeleton, "referenceScale", 100) * _scale;
|
||||||
skeletonData->_fps = Json::getFloat(skeleton, "fps", 30);
|
skeletonData->_fps = Json::getFloat(skeleton, "fps", 30);
|
||||||
skeletonData->_audioPath = Json::getString(skeleton, "audio", 0);
|
skeletonData->_audioPath = Json::getString(skeleton, "audio", 0);
|
||||||
skeletonData->_imagesPath = Json::getString(skeleton, "images", 0);
|
skeletonData->_imagesPath = Json::getString(skeleton, "images", 0);
|
||||||
@ -211,6 +212,9 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) {
|
|||||||
const char *color = Json::getString(boneMap, "color", NULL);
|
const char *color = Json::getString(boneMap, "color", NULL);
|
||||||
if (color) toColor(data->getColor(), color, true);
|
if (color) toColor(data->getColor(), color, true);
|
||||||
|
|
||||||
|
data->_icon = Json::getString(boneMap, "icon", "");
|
||||||
|
data->_visible = Json::getBoolean(boneMap, "visible", true);
|
||||||
|
|
||||||
skeletonData->_bones[i] = data;
|
skeletonData->_bones[i] = data;
|
||||||
bonesCount++;
|
bonesCount++;
|
||||||
}
|
}
|
||||||
@ -235,7 +239,14 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = new (__FILE__, __LINE__) SlotData(i, Json::getString(slotMap, "name", 0), *boneData);
|
String pathName = "";
|
||||||
|
String slotName = String(Json::getString(slotMap, "name", 0));
|
||||||
|
int slash = slotName.lastIndexOf('/');
|
||||||
|
if (slash != -1) {
|
||||||
|
pathName = slotName.substring(0, slash);
|
||||||
|
slotName = slotName.substring(slash + 1);
|
||||||
|
}
|
||||||
|
data = new (__FILE__, __LINE__) SlotData(i, slotName, *boneData);
|
||||||
|
|
||||||
color = Json::getString(slotMap, "color", 0);
|
color = Json::getString(slotMap, "color", 0);
|
||||||
if (color) {
|
if (color) {
|
||||||
@ -267,7 +278,8 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) {
|
|||||||
else if (strcmp(item->_valueString, "screen") == 0)
|
else if (strcmp(item->_valueString, "screen") == 0)
|
||||||
data->_blendMode = BlendMode_Screen;
|
data->_blendMode = BlendMode_Screen;
|
||||||
}
|
}
|
||||||
|
data->_visible = Json::getBoolean(slotMap, "visible", true);
|
||||||
|
data->_path = pathName;
|
||||||
skeletonData->_slots[i] = data;
|
skeletonData->_slots[i] = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user