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; }
MovementData *DataReaderHelper::decodeMovement(TiXmlElement *_movementXML, ArmatureData *_armatureData) { const char* _movName = _movementXML->Attribute(A_NAME); MovementData *_movementData = MovementData::create(); _movementData->setName(_movName); int _duration, _durationTo, _durationTween, _loop, _tweenEasing = 0; if( _movementXML->QueryIntAttribute(A_DURATION, &(_duration)) == TIXML_SUCCESS) { _movementData->setDuration(_duration); } if( _movementXML->QueryIntAttribute(A_DURATION_TO, &(_durationTo)) == TIXML_SUCCESS) { _movementData->setDurationTo(_durationTo); } if( _movementXML->QueryIntAttribute(A_DURATION_TWEEN, &(_durationTween)) == TIXML_SUCCESS) { _movementData->setDurationTween(_durationTween); } if( _movementXML->QueryIntAttribute(A_LOOP, &(_loop)) == TIXML_SUCCESS) { _movementData->setLoop((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)) == TIXML_SUCCESS) { _movementData->setTweenEasing((TweenType)_tweenEasing); } }else{ _movementData->setTweenEasing(TWEEN_EASING_MAX); } } TiXmlElement *_movBoneXml = _movementXML->FirstChildElement(BONE); while(_movBoneXml) { const char* _boneName = _movBoneXml->Attribute(A_NAME); if (_movementData->getMovementBoneData(_boneName)) { _movBoneXml = _movBoneXml->NextSiblingElement(); continue; } BoneData *_boneData = (BoneData*)_armatureData->getBoneData(_boneName); std::string _parentName = _boneData->m_strParent; TiXmlElement *_parentXML = NULL; if (_parentName.compare("") != 0) { _parentXML = _movementXML->FirstChildElement(BONE); while (_parentXML) { if (_parentName.compare(_parentXML->Attribute(A_NAME)) == 0) { break; } _parentXML = _parentXML->NextSiblingElement(BONE); } } MovementBoneData *_moveBoneData = decodeMovementBone(_movBoneXml, _parentXML, _boneData); _movementData->addMovementBoneData(NULL, _moveBoneData); _movBoneXml = _movBoneXml->NextSiblingElement(BONE); } 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; }