CCMovementData *CCDataReaderHelper::decodeMovement(cs::CSJsonDictionary &json) { CCMovementData *movementData = CCMovementData::create(); movementData->loop = json.getItemBoolvalue(A_LOOP, true); movementData->durationTween = json.getItemIntValue(A_DURATION_TWEEN, 0); movementData->durationTo = json.getItemIntValue(A_DURATION_TO, 0); movementData->duration = json.getItemIntValue(A_DURATION, 0); movementData->scale = json.getItemIntValue(A_MOVEMENT_SCALE, 1); movementData->tweenEasing = (CCTweenType)json.getItemIntValue(A_TWEEN_EASING, Linear); const char *name = json.getItemStringValue(A_NAME); if(name != NULL) { movementData->name = name; } int length = json.getArrayItemCount(MOVEMENT_BONE_DATA); for (int i = 0; i < length; i++) { cs::CSJsonDictionary *dic = json.getSubItemFromArray(MOVEMENT_BONE_DATA, i); movementData->addMovementBoneData(decodeMovementBone(*dic)); delete dic; } return movementData; }
CCMovementData *CCDataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML, CCArmatureData *armatureData) { const char *movName = movementXML->Attribute(A_NAME); CCMovementData *movementData = CCMovementData::create(); movementData->name = movName; int duration, durationTo, durationTween, loop, tweenEasing = 0; if( movementXML->QueryIntAttribute(A_DURATION, &(duration)) == tinyxml2::XML_SUCCESS) { movementData->duration = duration; } if( movementXML->QueryIntAttribute(A_DURATION_TO, &(durationTo)) == tinyxml2::XML_SUCCESS) { movementData->durationTo = durationTo; } if( movementXML->QueryIntAttribute(A_DURATION_TWEEN, &(durationTween)) == tinyxml2::XML_SUCCESS) { movementData->durationTween = durationTween; } if( movementXML->QueryIntAttribute(A_LOOP, &(loop)) == tinyxml2::XML_SUCCESS) { movementData->loop = (bool)loop; } const char *_easing = movementXML->Attribute(A_TWEEN_EASING); if(_easing != NULL) { std::string str = _easing; if(str.compare(FL_NAN) != 0) { if( movementXML->QueryIntAttribute(A_TWEEN_EASING, &(tweenEasing)) == tinyxml2::XML_SUCCESS) { movementData->tweenEasing = (CCTweenType)tweenEasing; } } else { movementData->tweenEasing = TWEEN_EASING_MAX; } } tinyxml2::XMLElement *movBoneXml = movementXML->FirstChildElement(BONE); while(movBoneXml) { const char *boneName = movBoneXml->Attribute(A_NAME); if (movementData->getMovementBoneData(boneName)) { movBoneXml = movBoneXml->NextSiblingElement(); continue; } CCBoneData *boneData = (CCBoneData *)armatureData->getBoneData(boneName); std::string parentName = boneData->parentName; tinyxml2::XMLElement *parentXml = NULL; if (parentName.length() != 0) { parentXml = movementXML->FirstChildElement(BONE); while (parentXml) { if (parentName.compare(parentXml->Attribute(A_NAME)) == 0) { break; } parentXml = parentXml->NextSiblingElement(BONE); } } CCMovementBoneData *_moveBoneData = decodeMovementBone(movBoneXml, parentXml, boneData); movementData->addMovementBoneData(_moveBoneData); movBoneXml = movBoneXml->NextSiblingElement(BONE); } return movementData; }