static void readCurve (CurveTimeline* timeline, int frameIndex, Json* frame) { Json* curve = Json_getItem(frame, "curve"); if (!curve) return; if (curve->type == Json_String && kdStrcmp(curve->valuestring, "stepped") == 0) CurveTimeline_setStepped(timeline, frameIndex); else if (curve->type == Json_Array) { CurveTimeline_setCurve(timeline, frameIndex, Json_getItemAt(curve, 0)->valuefloat, Json_getItemAt(curve, 1)->valuefloat, Json_getItemAt(curve, 2)->valuefloat, Json_getItemAt(curve, 3)->valuefloat); } }
void BaoZangView::delayParseInvite(float _time){ string info = CCUserDefault::sharedUserDefault()->getStringForKey("inviteFriends", ""); GlobalData::shared()->inviteFriendsInfo = info; if(GlobalData::shared()->inviteFriendsInfo!=""){ string friends = GlobalData::shared()->inviteFriendsInfo; CCLOG(" inviteFriendsInfo =%s",friends.c_str()); Json* fjson = Json_create(friends.c_str()); if( fjson == NULL ) return; int size = Json_getSize(fjson); for (int i=0; i<size; i++) { Json *item = Json_getItemAt(fjson, i); string name = Json_getString(item,"name",""); string id = Json_getString(item,"id",""); string url = ""; Json *picture =Json_getItem(item,"picture"); if(picture!=NULL){ Json *pictureData =Json_getItem(picture,"data"); if(pictureData!=NULL){ url = Json_getString(pictureData,"url",""); } } CCDictionary* friendInfo = CCDictionary::create(); friendInfo->setObject(CCString::create(id.c_str()), "id"); friendInfo->setObject(CCString::create(name.c_str()), "name"); friendInfo->setObject(CCString::create(url.c_str()), "picture"); friendInfo->setObject(CCString::create("0"), "flag"); m_inviteDatas->addObject(friendInfo); } Json_dispose(fjson); } }
void AllianceFightInfo::parseInfo(string info){ m_role = 0; m_selfIsAtt = false; Json* jReport = Json_create(info.c_str()); if( !jReport ) return; m_time = Json_getFloat(jReport,"time",0); m_win = Json_getInt(jReport,"win",0); m_type = Json_getInt(jReport,"type",0); m_count = Json_getInt(jReport, "frequency", 0); Json* att = Json_getItem(jReport,"att"); m_reward = ""; if (att!=NULL) { m_attackName = Json_getString(att,"name",""); m_attackAlliance = Json_getString(att,"asn",""); m_attackAID = Json_getString(att,"aid",""); m_attAsn = Json_getString(att,"asn",""); m_role = Json_getInt(att,"role",0); m_monsterId = Json_getString(att,"monsterId",""); if(m_attackAID==GlobalData::shared()->playerInfo.allianceInfo.uid){ m_selfIsAtt = true; } Json *res=Json_getItem(att,"res"); if(res){ int size = Json_getSize(res); for (int i=0; i<size; i++) { Json *item = Json_getItemAt(res, i); int itemType = Json_getInt(item,"t",-1); int itemV = Json_getInt(item,"v",-1); if(itemType!=-1 && itemV>0){ m_reward += RewardController::getInstance()->getNameByType(itemType,itemV); m_reward += ":"; m_reward += CC_CMDITOA(itemV); if(i!=(size-1)){ m_reward += ","; } } } } } if(m_reward==""){ m_reward = "0"; } Json* def = Json_getItem(jReport,"def"); if (def!=NULL) { m_defName = Json_getString(def,"name",""); m_defAlliance = Json_getString(def,"asn",""); m_defkill = Json_getInt(def,"kill",0); m_defAID = Json_getString(def,"defAID",""); m_defAsn = Json_getString(def,"asn",""); } Json_dispose(jReport); }
CCArray *CCJson::parseArray(Json *pJson) { int arrayLength = Json_getSize(pJson); CCArray *array = CCArray::create(); for (int i = 0; i < arrayLength; i++) { Json *item = Json_getItemAt(pJson, i); CCObject *object = parseValue(item); if (object) { array->addObject(object); } } return array; }
void SJArcScene::loadActors() { //Value& actorList = m_jsonValue["Actors"]; //int count = actorList.IsNull() ? 0 : actorList.Size(); //for (int i = 0; i < count; i++) //{ // CCLog("enter loadactors"); // Value& data = actorList[i]; // const char* res = data["res"].GetString(); // float height = data["height"].GetDouble(); // float rotate = data["speedcoef"].GetDouble(); // float ownAngle = data["ownangle"].GetDouble(); // SJActor* actor = SJActor::createActor(res, height, rotate); // actor->setRotation(data["angle"].GetDouble()); // actor->setOrigAngle(data["angle"].GetDouble()); // actor->setFlipX(data["flip"].GetBool()); // actor->setOwnAngle(ownAngle); // actor->setType(data["type"].GetString()); // setActorName(actor, data["name"].IsNull() ? NULL : data["name"].GetString()); // addActor(actor, data["z"].GetInt(), m_actorCount); //} Json*array = Json_getItem(m_jsonRoot,"Actors"); int count = Json_getSize(array); for(int i = 0; i < count; i++) { Json*object = Json_getItemAt(array,i); const char* res = Json_getString(object,"res",""); float height = Json_getFloat(object,"height",0); float rotate = Json_getFloat(object,"speedcoef",0); float ownAngle = Json_getFloat(object,"ownangle",0); SJActor* actor = SJActor::createActor(res, height, rotate); actor->setRotation(Json_getFloat(object,"angle",0)); actor->setOrigAngle(Json_getFloat(object,"angle",0)); actor->setFlipX(Json_getBool(object,"flip",false)); actor->setOwnAngle(ownAngle); actor->setType(Json_getString(object,"type",0)); setActorName(actor, Json_getString(object,"name",NULL)); addActor(actor, Json_getInt(object,"z",0), m_actorCount); } //for(int i = 0;i < m_saveNames.size();i++) //{ // CCArmatureDataManager::sharedArmatureDataManager()->removeArmatureFileInfo(m_saveNames[i].c_str()); //} }
void Level::loadMap() { char mapPath[200]; int chapter = ((this->level - 1) / CONFIG_LEVELS_PER_CHAPTER) + 1; int chapterLevel = ((this->level - 1) % CONFIG_LEVELS_PER_CHAPTER) + 1; sprintf(mapPath, DOC_MAP, this->getLevelIndex(chapter, chapterLevel)); // load water holes Json* root; log("begin read file"); string fileData = CStringUtil::readFile(mapPath, false, true, false); root = Json_create(fileData.data()); if (root) { Json* data = Json_getItem(root, "data"); Json* data_platform = Json_getItem(data, "data_platform"); Json* platform = Json_getItem(data_platform, "platform"); if (platform != NULL) { int size = platform->size; for (int i = 0; i < size; i++) { Json* item = Json_getItemAt(platform, i); int instructionIndex = atoi(Json_getString(item, "_id", "")); int positionIndex = atoi(Json_getString(item, "position", "")); Leaf* leaf = new Leaf(); leaf->setInstructionIndex(instructionIndex); leaf->setPositionIndex(positionIndex); this->leaves->setObject(leaf, positionIndex); } } } // load frog this->frog = new Frog(); CC_SAFE_RETAIN(this->frog); this->frog->setPosition(Point(0, 0)); // place leaves this->placeLeaves(); // place frog this->placeFrog(); }
void SJArcScene::loadData(const char* name) { CCLog("begin load data %s",name); //m_isLoadingComplete = false; //unsigned long size = 0; //const char* content = (const char*)SJTxtFile::openFile(name, &size); //m_jsonValue.Parse<0>(content); //m_curAngle = 0; //m_sceneLength = m_jsonValue["Length"].GetDouble() / 2; //loadResources(m_jsonValue["Resources"]); //CCLog("the load file json length is %s",m_jsonValue["Length"].GetString()); //CCLog("the load file json is %s",m_jsonValue["Resources"].GetString()); //loadResAsync(0); m_isLoadingComplete = false; unsigned long size = 0; const char* content = (const char*)SJTxtFile::openFile(name, &size); m_jsonRoot=Json_create(content); Json*resources = Json_getItem(m_jsonRoot,"Resources"); m_sceneLength = Json_getFloat(m_jsonRoot,"Length",0) / 2; if(resources) { int count = Json_getSize(resources); for(int i = 0;i<count; i++) { const char* resName = Json_getItemAt(resources,i)->name; m_resNames.push_back(resName); std::string str = "Res/Animations/Actors/"; str.append(resName); m_resNamesVec.push_back(CCString::createWithFormat("%s0.png", str.c_str())->getCString()); m_saveNames.push_back(str.append(".ExportJson")); //CCLog("C++ json key is%s",Json_getItemAt(resources,i)->name); } }else { CCLog("json resources is null"); } delete content; loadResAsync(0); }
void FacebookInviteView::initData(){ string friends = GlobalData::shared()->inviteFriendsInfo; if(friends!=""){ CCLOG(" friends =%s",friends.c_str()); Json* fjson = Json_create(friends.c_str()); if( !fjson ) return; int size = Json_getSize(fjson); for (int i=0; i<size; i++) { Json *item = Json_getItemAt(fjson, i); string name = Json_getString(item,"name",""); string id = Json_getString(item,"id",""); string url = ""; Json *picture =Json_getItem(item,"picture"); if(picture!=NULL){ Json *pictureData =Json_getItem(picture,"data"); if(pictureData!=NULL){ url = Json_getString(pictureData,"url",""); } } CCDictionary* friendInfo = CCDictionary::create(); friendInfo->setObject(CCString::create(id.c_str()), "id"); friendInfo->setObject(CCString::create(name.c_str()), "name"); friendInfo->setObject(CCString::create(url.c_str()), "picture"); friendInfo->setObject(CCString::create("0"), "flag"); m_srcData->addObject(friendInfo); } Json_dispose(fjson); m_data->removeAllObjects(); int num = m_srcData->count(); if(num>=50){ num = 50; } for (int i=0; i<num; i++) { CCDictionary* dic = _dict(m_srcData->objectAtIndex(i)); dic->setObject(CCString::create("1"), "flag"); m_data->addObject(dic); } } }
SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* json) { SkeletonData* skeletonData; Json *root, *bones; int i, ii, iii, boneCount; Json* slots; Json* skinsMap; Json* animations; FREE(self->error); CONST_CAST(char*, self->error) = 0; root = Json_create(json); if (!root) { _SkeletonJson_setError(self, 0, "Invalid skeleton JSON: ", Json_getError()); return 0; } skeletonData = SkeletonData_create(); bones = Json_getItem(root, "bones"); boneCount = Json_getSize(bones); skeletonData->bones = MALLOC(BoneData*, boneCount); for (i = 0; i < boneCount; ++i) { Json* boneMap = Json_getItemAt(bones, i); BoneData* boneData; const char* boneName = Json_getString(boneMap, "name", 0); BoneData* parent = 0; const char* parentName = Json_getString(boneMap, "parent", 0); if (parentName) { parent = SkeletonData_findBone(skeletonData, parentName); if (!parent) { SkeletonData_dispose(skeletonData); _SkeletonJson_setError(self, root, "Parent bone not found: ", parentName); return 0; } } boneData = BoneData_create(boneName, parent); boneData->length = Json_getFloat(boneMap, "length", 0) * self->scale; boneData->x = Json_getFloat(boneMap, "x", 0) * self->scale; boneData->y = Json_getFloat(boneMap, "y", 0) * self->scale; boneData->rotation = Json_getFloat(boneMap, "rotation", 0); boneData->scaleX = Json_getFloat(boneMap, "scaleX", 1); boneData->scaleY = Json_getFloat(boneMap, "scaleY", 1); skeletonData->bones[i] = boneData; skeletonData->boneCount++; } slots = Json_getItem(root, "slots"); if (slots) { int slotCount = Json_getSize(slots); skeletonData->slots = MALLOC(SlotData*, slotCount); for (i = 0; i < slotCount; ++i) { SlotData* slotData; const char* color; Json *attachmentItem; Json* slotMap = Json_getItemAt(slots, i); const char* slotName = Json_getString(slotMap, "name", 0); const char* boneName = Json_getString(slotMap, "bone", 0); BoneData* boneData = SkeletonData_findBone(skeletonData, boneName); if (!boneData) { SkeletonData_dispose(skeletonData); _SkeletonJson_setError(self, root, "Slot bone not found: ", boneName); return 0; } slotData = SlotData_create(slotName, boneData); color = Json_getString(slotMap, "color", 0); if (color) { slotData->r = toColor(color, 0); slotData->g = toColor(color, 1); slotData->b = toColor(color, 2); slotData->a = toColor(color, 3); } attachmentItem = Json_getItem(slotMap, "attachment"); if (attachmentItem) SlotData_setAttachmentName(slotData, attachmentItem->valuestring); skeletonData->slots[i] = slotData; skeletonData->slotCount++; } } skinsMap = Json_getItem(root, "skins"); if (skinsMap) { int skinCount = Json_getSize(skinsMap); skeletonData->skins = MALLOC(Skin*, skinCount); for (i = 0; i < skinCount; ++i) { Json* slotMap = Json_getItemAt(skinsMap, i); const char* skinName = slotMap->name; Skin *skin = Skin_create(skinName); int slotNameCount; skeletonData->skins[i] = skin; skeletonData->skinCount++; if (kdStrcmp(skinName, "default") == 0) skeletonData->defaultSkin = skin; slotNameCount = Json_getSize(slotMap); for (ii = 0; ii < slotNameCount; ++ii) { Json* attachmentsMap = Json_getItemAt(slotMap, ii); const char* slotName = attachmentsMap->name; int slotIndex = SkeletonData_findSlotIndex(skeletonData, slotName); int attachmentCount = Json_getSize(attachmentsMap); for (iii = 0; iii < attachmentCount; ++iii) { Attachment* attachment; Json* attachmentMap = Json_getItemAt(attachmentsMap, iii); const char* skinAttachmentName = attachmentMap->name; const char* attachmentName = Json_getString(attachmentMap, "name", skinAttachmentName); const char* typeString = Json_getString(attachmentMap, "type", "region"); AttachmentType type; if (kdStrcmp(typeString, "region") == 0) type = ATTACHMENT_REGION; else if (kdStrcmp(typeString, "regionSequence") == 0) type = ATTACHMENT_REGION_SEQUENCE; else { SkeletonData_dispose(skeletonData); _SkeletonJson_setError(self, root, "Unknown attachment type: ", typeString); return 0; } attachment = AttachmentLoader_newAttachment(self->attachmentLoader, skin, type, attachmentName); if (!attachment) { if (self->attachmentLoader->error1) { SkeletonData_dispose(skeletonData); _SkeletonJson_setError(self, root, self->attachmentLoader->error1, self->attachmentLoader->error2); return 0; } continue; } if (attachment->type == ATTACHMENT_REGION || attachment->type == ATTACHMENT_REGION_SEQUENCE) { RegionAttachment* regionAttachment = (RegionAttachment*)attachment; regionAttachment->x = Json_getFloat(attachmentMap, "x", 0) * self->scale; regionAttachment->y = Json_getFloat(attachmentMap, "y", 0) * self->scale; regionAttachment->scaleX = Json_getFloat(attachmentMap, "scaleX", 1); regionAttachment->scaleY = Json_getFloat(attachmentMap, "scaleY", 1); 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; RegionAttachment_updateOffset(regionAttachment); } Skin_addAttachment(skin, slotIndex, skinAttachmentName, attachment); } } } } animations = Json_getItem(root, "animations"); if (animations) { int animationCount = Json_getSize(animations); skeletonData->animations = MALLOC(Animation*, animationCount); for (i = 0; i < animationCount; ++i) { Json* animationMap = Json_getItemAt(animations, i); _SkeletonJson_readAnimation(self, animationMap, skeletonData); } } Json_dispose(root); return skeletonData; }
static Animation* _SkeletonJson_readAnimation (SkeletonJson* self, Json* root, SkeletonData *skeletonData) { Animation* animation; Json* bones = Json_getItem(root, "bones"); int boneCount = bones ? Json_getSize(bones) : 0; Json* slots = Json_getItem(root, "slots"); int slotCount = slots ? Json_getSize(slots) : 0; int timelineCount = 0; int i, ii, iii; for (i = 0; i < boneCount; ++i) timelineCount += Json_getSize(Json_getItemAt(bones, i)); for (i = 0; i < slotCount; ++i) timelineCount += Json_getSize(Json_getItemAt(slots, i)); animation = Animation_create(root->name, timelineCount); animation->timelineCount = 0; skeletonData->animations[skeletonData->animationCount] = animation; skeletonData->animationCount++; for (i = 0; i < boneCount; ++i) { timelineCount = 0; Json* boneMap = Json_getItemAt(bones, i); const char* boneName = boneMap->name; int boneIndex = SkeletonData_findBoneIndex(skeletonData, boneName); if (boneIndex == -1) { Animation_dispose(animation); _SkeletonJson_setError(self, root, "Bone not found: ", boneName); return 0; } timelineCount = Json_getSize(boneMap); for (ii = 0; ii < timelineCount; ++ii) { float duration; Json* timelineArray = Json_getItemAt(boneMap, ii); int frameCount = Json_getSize(timelineArray); const char* timelineType = timelineArray->name; if (kdStrcmp(timelineType, "rotate") == 0) { RotateTimeline *timeline = RotateTimeline_create(frameCount); timeline->boneIndex = boneIndex; for (iii = 0; iii < frameCount; ++iii) { Json* frame = Json_getItemAt(timelineArray, iii); RotateTimeline_setFrame(timeline, iii, Json_getFloat(frame, "time", 0), Json_getFloat(frame, "angle", 0)); readCurve(SUPER(timeline), iii, frame); } animation->timelines[animation->timelineCount++] = (Timeline*)timeline; duration = timeline->frames[frameCount * 2 - 2]; if (duration > animation->duration) animation->duration = duration; } else { int isScale = kdStrcmp(timelineType, "scale") == 0; if (isScale || kdStrcmp(timelineType, "translate") == 0) { float scale = isScale ? 1 : self->scale; TranslateTimeline *timeline = isScale ? ScaleTimeline_create(frameCount) : TranslateTimeline_create(frameCount); timeline->boneIndex = boneIndex; for (iii = 0; iii < frameCount; ++iii) { Json* frame = Json_getItemAt(timelineArray, iii); TranslateTimeline_setFrame(timeline, iii, Json_getFloat(frame, "time", 0), Json_getFloat(frame, "x", 0) * scale, Json_getFloat(frame, "y", 0) * scale); readCurve(SUPER(timeline), iii, frame); } animation->timelines[animation->timelineCount++] = (Timeline*)timeline; duration = timeline->frames[frameCount * 3 - 3]; if (duration > animation->duration) animation->duration = duration; } else { Animation_dispose(animation); _SkeletonJson_setError(self, 0, "Invalid timeline type for a bone: ", timelineType); return 0; } } } } for (i = 0; i < slotCount; ++i) { timelineCount = 0; Json* slotMap = Json_getItemAt(slots, i); const char* slotName = slotMap->name; int slotIndex = SkeletonData_findSlotIndex(skeletonData, slotName); if (slotIndex == -1) { Animation_dispose(animation); _SkeletonJson_setError(self, root, "Slot not found: ", slotName); return 0; } timelineCount = Json_getSize(slotMap); for (ii = 0; ii < timelineCount; ++ii) { float duration; Json* timelineArray = Json_getItemAt(slotMap, ii); int frameCount = Json_getSize(timelineArray); const char* timelineType = timelineArray->name; if (kdStrcmp(timelineType, "color") == 0) { ColorTimeline *timeline = ColorTimeline_create(frameCount); timeline->slotIndex = slotIndex; for (iii = 0; iii < frameCount; ++iii) { Json* frame = Json_getItemAt(timelineArray, iii); const char* s = Json_getString(frame, "color", 0); ColorTimeline_setFrame(timeline, iii, Json_getFloat(frame, "time", 0), toColor(s, 0), toColor(s, 1), toColor(s, 2), toColor(s, 3)); readCurve(SUPER(timeline), iii, frame); } animation->timelines[animation->timelineCount++] = (Timeline*)timeline; duration = timeline->frames[frameCount * 5 - 5]; if (duration > animation->duration) animation->duration = duration; } else if (kdStrcmp(timelineType, "attachment") == 0) { AttachmentTimeline *timeline = AttachmentTimeline_create(frameCount); timeline->slotIndex = slotIndex; for (iii = 0; iii < frameCount; ++iii) { Json* frame = Json_getItemAt(timelineArray, iii); Json* name = Json_getItem(frame, "name"); AttachmentTimeline_setFrame(timeline, iii, Json_getFloat(frame, "time", 0), name->type == Json_NULL ? 0 : name->valuestring); } animation->timelines[animation->timelineCount++] = (Timeline*)timeline; duration = timeline->frames[frameCount - 1]; if (duration > animation->duration) animation->duration = duration; } else { Animation_dispose(animation); _SkeletonJson_setError(self, 0, "Invalid timeline type for a slot: ", timelineType); return 0; } } } return animation; }
void FightScene::checkSkl() { CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) std::vector<std::string>::const_iterator searchPathsIter = CCFileUtils::sharedFileUtils()->getSearchPaths().begin(); std::string root = *searchPathsIter; std::string dirRoot = root.substr(0, root.length() - 1); dirRoot += "\\bone\\*.equip"; WIN32_FIND_DATA FindFileData; size_t size = dirRoot.length(); wchar_t *buffer = new wchar_t[size+1]; memset(buffer,0,sizeof(wchar_t)*(size+1)); MultiByteToWideChar( CP_ACP, 0, dirRoot.c_str(), size, buffer, size * sizeof(wchar_t) ); buffer[size] = 0; // 确保以 '\0' 结尾 equipList->removeAllObjects(); HANDLE hFind = FindFirstFile(buffer, &FindFileData); if(hFind != INVALID_HANDLE_VALUE) { do { if(FindFileData.cFileName[0]=='.') continue; if(!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { char str[MAX_PATH]={0}; WideCharToMultiByte(CP_ACP, 0, FindFileData.cFileName, sizeof(FindFileData.cFileName) + 1, str, MAX_PATH, NULL, NULL); std::string fgg = std::string(str); if(fgg == "AvatarEquip_defultM.equip") { continue; } size_t last = 0; size_t index = fgg.find_first_of(".",last); while (index!=std::string::npos) { std::string fggg = fgg.substr(last,index-last); std::string path = CCBoneSpriteConfig::getBoneUrl() + fggg + ".equip"; std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(path.c_str()); unsigned long size; char* buffer = (char*)CCFileUtils::sharedFileUtils()->getFileData(fullPath.c_str(), "rt", &size); Json* root = Json_create(buffer); CC_SAFE_DELETE_ARRAY(buffer); int count = Json_getSize(root); for(int i = 0; i< count; i++) { Json *tmp = Json_getItemAt(root, i); std::string tmpString = tmp->name; if(tmpString == "full") { continue; } std::string ggg = fggg+"+"+tmpString; CCString *ff = CCString::create(ggg); CCLog(ff->getCString()); equipList->addObject(ff); } Json_dispose(root); break; } } } while(FindNextFile(hFind,&FindFileData) != 0); } delete []buffer; FindClose(hFind); #else equipList->removeAllObjects(); CCString *ff = CCString::create("weapon"); equipList->addObject(ff); ff = CCString::create("goldGlory_M"); equipList->addObject(ff); #endif }