示例#1
0
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);
    }
}
示例#2
0
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);
}
void ComsumeController::getInfoContent()
{
    std::string post_command = NativeLauncher::getNWAdress() + "/get_message?type=10";
    std::string recv = Get_data(post_command.c_str());
    Json* json = Json_create(recv.c_str());
    if (json) {
        com_text_ext = Json_getString(json, "text", "");
        com_uri_ext = Json_getString(json, "apn", "");
        com_attend_ext = Json_getString(json, "attention", "");
        com_attend_type = Json_getInt(json, "attend_type", 0);
    }
    
    return;
}
示例#4
0
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);
}
示例#6
0
void EstateController::getEstateInfoContent()
{
    std::string post_command = NativeLauncher::getNWAdress() + "/get_message?type=8";
    std::string recv = Get_data(post_command.c_str());
    Json* json = Json_create(recv.c_str());
    if (json) {
        std::string text_ext = Json_getString(json, "text", "");
        std::string annualincome = Json_getString(json, "annualincome", "");
        std::string leisurecost = Json_getString(json, "leisurecost", "");
        std::string floorspace = Json_getString(json, "floorspace", "");
        std::string buildyear = Json_getString(json, "buildyear", "");
        std::string architect = Json_getString(json, "architect", "");
        std::string roomsnum = Json_getString(json, "roomsnum", "");
        std::string electype = Json_getString(json, "electype", "");
        std::string waterheater = Json_getString(json, "waterheater", "");
        std::string cookingdevice = Json_getString(json, "cookingdevice", "");
        int recommend = Json_getInt(json, "recommend", 0);
    }
    
    return;
}
示例#7
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);
        }
    }
}
示例#8
0
文件: CCJson.cpp 项目: ourgames/dc208
CCDictionary *CCJson::JSONObjectWithString(const char *jsonString) {
    return CCJson::dictionaryWithJson(Json_create(jsonString));
}
示例#9
0
bool GetChatRoomListCommand::handleRecieve(cocos2d::CCDictionary *dict){
    
    CCLOGFUNC("");
    if (dict->valueForKey("cmd")->compare(CHAT_ROOM_GET_LIST) != 0)
        return false;
    
    CCDictionary *params=_dict(dict->objectForKey("params"));
    if (!params) {
        CCLOGFUNC("params==NULL");
        return false;
    }
    
    CCArray* roomArray = dynamic_cast<CCArray*>(params->objectForKey("rooms")) ;
    if (roomArray==NULL || roomArray->count()<=0) {
        return false;
    }
    CCLOGFUNCF("roomArray count %d",roomArray->count());
    MailController::getInstance()->getChatRoomIdArray()->removeAllObjects();
    string groupId="";
    for (int i=0;i<roomArray->count(); i++) {
        CCArray* mailInfoArr=CCArray::create();
        CCDictionary* info=dynamic_cast<CCDictionary*>(roomArray->objectAtIndex(i));
        if (info) {
            
            groupId=info->valueForKey("id")->getCString();
            if (groupId!="") {
                MailController::getInstance()->getChatRoomIdArray()->addObject(CCString::create(groupId));
            }
            string roomName=info->valueForKey("name")->getCString();
            CCArray* members=dynamic_cast<CCArray*>(info->objectForKey("members"));
            if (members==NULL || members->count()<=0) {
                return false;
            }
            
            CCArray* memberUidArray=CCArray::create();
            memberUidArray->retain();
            
            for (int j=0; j<members->count(); j++) {
                CCDictionary* dic=dynamic_cast<CCDictionary*>(members->objectAtIndex(j));
                if (dic) {
                    string uid=dic->valueForKey("uid")->getCString();
                    memberUidArray->addObject(CCString::create(uid));
                }
            }
            
            auto search = GlobalData::shared()->mailList.find(groupId);
            bool isExistMail=(search != GlobalData::shared()->mailList.end() && groupId != "");
            
            CCString* jsonMsg=dynamic_cast<CCString*>(info->objectForKey("msg"));

            if (jsonMsg) {
                MailInfo* mailInfo=NULL;
                if (!isExistMail) {
                    mailInfo=MailInfo::create();
                    mailInfo->crGroupId=groupId;
//                    mailInfo->retain();
//                    mailInfo->crMemberUidArray =memberUidArray;
                    GlobalData::shared()->mailList[groupId]=mailInfo;
                }
                else
                {
                    mailInfo=dynamic_cast<MailInfo*>(search->second);
                }

                
                string jsonStr=jsonMsg->getCString();
                CCLOGFUNCF("jsonStr %s",jsonStr.c_str());
                Json* jsonObj = Json_create(jsonStr.c_str());
                if( !jsonObj )
                    continue;
                
                Json* jsonBody=Json_getItem(jsonObj, "body");
                if( !jsonBody )
                    continue;
                
                CCDictionary* dic=MailController::getInstance()->parseChatRoomJsonMsg(jsonObj,jsonBody);
                Json_dispose(jsonObj);
                if(dic!=NULL)
                {
                    MailDialogInfo* dialogInfo=MailController::getInstance()->parseChatRoomDic(dic,true,true);
                    if (dialogInfo) {
                        ChatMailInfo* info=ChatMailInfo::create(mailInfo,dialogInfo,false,CHANNEL_TYPE_CHATROOM);
                        mailInfoArr->addObject(info);
                    }
                }
                CCLOGFUNCF("roomName %s,mailInfoArr count %d",roomName.c_str(),mailInfoArr->count());
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
                if(ChatServiceCocos2dx::enableNativeMail && MailController::getInstance()->getChatRoomEnable() && mailInfoArr->count()>0)
                {
                    ChatServiceCocos2dx::postIsChatRoomMemberFlag(groupId,true);
                    MailController::getInstance()->notifyMailMsgToAndroid(mailInfoArr,groupId);
                }
#endif
            }
        }
    }
    
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    if (!ChatServiceCocos2dx::isChatShowing) {
        CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(MAIL_LIST_CHANGE);
        CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(MAIL_PERSON_CHAT_CHANGE);
    }
#else
    CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(MAIL_LIST_CHANGE);
    CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(MAIL_PERSON_CHAT_CHANGE);
#endif
    
    return true;
}
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;
}
示例#11
0
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
}
示例#12
0
void S65ShowVideo::DownLoadFinish()
{
    
    int nbegin=3;
	m_strUrlContent=m_strUrlContent.substr(nbegin,m_strUrlContent.length()-nbegin);
	CDataConvert dataConvert;
	m_strUrlContent=dataConvert.UTF8ToGB(m_strUrlContent.c_str());
    
    
	Json* root= Json_create(m_strUrlContent.c_str());
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    string detailClassName ="S"+PersonalApi::convertIntToString(AppDelegate::S1NaviSelected) +"ShowVideo";
    string currentClassName(detailClassName.c_str());
    string version = currentClassName+"version";
    string needUpDate = currentClassName+"needUpDate";
    string newVersion = currentClassName+"newVersion";
    string time = currentClassName+"time";
    
    Json* root_Version=Json_getItem(root,"version");
    
    if (root_Version)
	{
        string versionStr(root_Version->valuestring);
        
        
        if (CCUserDefault::sharedUserDefault()->getStringForKey(version.c_str()).compare(versionStr) == 0)
        {
            CCUserDefault::sharedUserDefault()->setBoolForKey(needUpDate.c_str(),false);
            
            
            AppDelegate::loadingLabel->setString("");
            //setButtonEnabel(false);
            
            setUpUpDateLabel(CCPointMake(130, 570),CCPointMake(900, 570),CCUserDefault::sharedUserDefault()->getStringForKey(time.c_str()),CCUserDefault::sharedUserDefault()->getBoolForKey(needUpDate.c_str()));
            
            
            return;
        }
        else
        {
            CCUserDefault::sharedUserDefault()->setBoolForKey(needUpDate.c_str(),true);
            CCUserDefault::sharedUserDefault()->setStringForKey(newVersion.c_str(), root_Version->valuestring);
        }
	}
    
    Json* root_time=Json_getItem(root,"time");
    if (root_time)
	{
        CCUserDefault::sharedUserDefault()->setStringForKey(time.c_str(), root_time->valuestring);
	}
    
    setUpUpDateLabel(CCPointMake(130, 570),CCPointMake(900, 570),CCUserDefault::sharedUserDefault()->getStringForKey(time.c_str()),CCUserDefault::sharedUserDefault()->getBoolForKey(needUpDate.c_str()));
    //setButtonEnabel(true);
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    
    
	//picture and title
	Json* root_smallpicture=Json_getItem(root,"video");
	if (root_smallpicture && root_smallpicture->type==Json_Array)
	{
		Json* json_child=root_smallpicture->child;
        map<string, string> valueMap;
        showPicMap.clear();
        showBigPicMap.clear();
        int i = 0;//smal image
        int k = 0;
        int j = 0;//big image
		while(json_child)
		{
			Json* child_pic_url=Json_getItem(json_child,"img");
            Json* child_video_url=Json_getItem(json_child,"video_url");
            
            if (i==0) {
                
                //self
                {
                    if (child_pic_url)
                    {
                        char szsamllpicname[512]={0};
                        sprintf(szsamllpicname, "S%d5ScrollBigPic%d.png",AppDelegate::S1NaviSelected,j+1);
                        string picNameStr(szsamllpicname);
                        showBigPicMap[PersonalApi::convertIntToString(j+1)] = picNameStr;
                        DownLoadFile(child_pic_url->valuestring,szsamllpicname);
                        
                        string valueStr = child_video_url->valuestring;
                        valueMap[PersonalApi::convertIntToString(j+1)] = valueStr;
                    }
                    j++;
                }
                
            }else if (i==1) {
                
                {
                    if (child_pic_url)
                    {
                        char szsamllpicname[512]={0};
                        sprintf(szsamllpicname, "S%d5ScrollPic%d.png",AppDelegate::S1NaviSelected,k+1);
                        string picNameStr(szsamllpicname);
                        showPicMap[PersonalApi::convertIntToString(k+1)] = picNameStr;
                        DownLoadFile(child_pic_url->valuestring,szsamllpicname);
                        
                        string valueStr = child_video_url->valuestring;
                        valueMap[PersonalApi::convertIntToString(k+1)] = valueStr;
                    }
                    k++;
                }
                
                {
                    if (child_pic_url)
                    {
                        char szsamllpicname[512]={0};
                        sprintf(szsamllpicname, "S%d5ScrollPic%d.png",AppDelegate::S1NaviSelected,k+1);
                        string picNameStr(szsamllpicname);
                        showPicMap[PersonalApi::convertIntToString(k+1)] = picNameStr;
                        DownLoadFile(child_pic_url->valuestring,szsamllpicname);
                        
                        string valueStr = child_video_url->valuestring;
                        valueMap[PersonalApi::convertIntToString(k+1)] = valueStr;
                    }
                    k++;
                }
                
                {
                    if (child_pic_url)
                    {
                        char szsamllpicname[512]={0};
                        sprintf(szsamllpicname, "S%d5ScrollPic%d.png",AppDelegate::S1NaviSelected,k+1);
                        string picNameStr(szsamllpicname);
                        showPicMap[PersonalApi::convertIntToString(k+1)] = picNameStr;
                        DownLoadFile(child_pic_url->valuestring,szsamllpicname);
                        
                        string valueStr = child_video_url->valuestring;
                        valueMap[PersonalApi::convertIntToString(k+1)] = valueStr;
                    }
                    k++;
                }
                
            }else if (i==3) {
                
                {
                    if (child_pic_url)
                    {
                        char szsamllpicname[512]={0};
                        sprintf(szsamllpicname, "S%d5ScrollPic%d.png",AppDelegate::S1NaviSelected,k+1);
                        string picNameStr(szsamllpicname);
                        showPicMap[PersonalApi::convertIntToString(k+1)] = picNameStr;
                        DownLoadFile(child_pic_url->valuestring,szsamllpicname);
                        
                        string valueStr = child_video_url->valuestring;
                        valueMap[PersonalApi::convertIntToString(k+1)] = valueStr;
                    }
                    k++;
                    
                }
                
                {
                    if (child_pic_url)
                    {
                        char szsamllpicname[512]={0};
                        sprintf(szsamllpicname, "S%d5ScrollPic%d.png",AppDelegate::S1NaviSelected,k+1);
                        string picNameStr(szsamllpicname);
                        showPicMap[PersonalApi::convertIntToString(k+1)] = picNameStr;
                        DownLoadFile(child_pic_url->valuestring,szsamllpicname);
                        
                        string valueStr = child_video_url->valuestring;
                        valueMap[PersonalApi::convertIntToString(k+1)] = valueStr;
                    }
                    k++;
                    
                }
                
                //self
                {
                    if (child_pic_url)
                    {
                        char szsamllpicname[512]={0};
                        sprintf(szsamllpicname, "S%d5ScrollPic%d.png",AppDelegate::S1NaviSelected,k+1);
                        string picNameStr(szsamllpicname);
                        showPicMap[PersonalApi::convertIntToString(k+1)] = picNameStr;
                        DownLoadFile(child_pic_url->valuestring,szsamllpicname);
                        
                        string valueStr = child_video_url->valuestring;
                        valueMap[PersonalApi::convertIntToString(k+1)] = valueStr;
                    }
                    k++;
                }
                
                
            }else{
                if(child_pic_url){
                    char szsamllpicname[512]={0};
                    sprintf(szsamllpicname, "S%d5ScrollPic%d.png",AppDelegate::S1NaviSelected,k+1);
                    string picNameStr(szsamllpicname);
                    showPicMap[PersonalApi::convertIntToString(k+1)] = picNameStr;
                    DownLoadFile(child_pic_url->valuestring,szsamllpicname);
                    
                    string valueStr = child_video_url->valuestring;
                    valueMap[PersonalApi::convertIntToString(k+1)] = valueStr;
                    
                }
                k++;
            }
            
            i++;
			json_child=json_child->next;
		}
        
        string str1 = "S"+PersonalApi::convertIntToString(AppDelegate::S1NaviSelected) +"5scrollPic";
        string str2 = "S"+PersonalApi::convertIntToString(AppDelegate::S1NaviSelected) +"5VideoIntro";
        
        PersonalApi::wirteVecToXml(showPicMap,str1);
        PersonalApi::wirteVecToXml(valueMap,str2);
        
	}
    
    checkPicDownLoading();
}
示例#13
0
Animation* SkeletonJson_readAnimation (SkeletonJson* self, const char* json, const SkeletonData *skeletonData) {
	FREE(self->error);
	CONST_CAST(char*, self->error) = 0;

	Json* root = Json_create(json);
	if (!root) {
		_SkeletonJson_setError(self, 0, "Invalid animation JSON: ", Json_getError());
		return 0;
	}

	Json* bones = Json_getItem(root, "bones");
	int boneCount = Json_getSize(bones);

	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 = Animation_create(timelineCount);
	animation->timelineCount = 0;

	for (i = 0; i < boneCount; ++i) {
		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;
		}

		int timelineCount = Json_getSize(boneMap);
		for (ii = 0; ii < timelineCount; ++ii) {
			Json* timelineArray = Json_getItemAt(boneMap, ii);
			int frameCount = Json_getSize(timelineArray);
			const char* timelineType = timelineArray->name;

			if (strcmp(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;
				float duration = timeline->frames[frameCount * 2 - 2];
				if (duration > animation->duration) animation->duration = duration;

			} else {
				int isScale = strcmp(timelineType, "scale") == 0;
				if (isScale || strcmp(timelineType, "translate") == 0) {
					TranslateTimeline *timeline = isScale ? ScaleTimeline_create(frameCount) : TranslateTimeline_create(frameCount);
					float scale = isScale ? 1 : self->scale;
					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;
					float 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;
				}
			}
		}
	}

	if (!slots) {
		for (i = 0; i < slotCount; ++i) {
			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;
			}

			int timelineCount = Json_getSize(slotMap);
			for (ii = 0; ii < timelineCount; ++ii) {
				Json* timelineArray = Json_getItemAt(slotMap, ii);
				int frameCount = Json_getSize(timelineArray);
				const char* timelineType = timelineArray->name;

				if (strcmp(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;
					float duration = timeline->frames[frameCount * 5 - 5];
				if (duration > animation->duration) animation->duration = duration;

				} else if (strcmp(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;
					float 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;
}