Example #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);
    }
}
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;
}
Example #3
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 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());
	//}
}
Example #5
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 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;
}
Example #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);
        }
    }
}
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;
}