YHEffectDefiner::YHEffectDefiner(CCDictionary * dict)
{
	CCString * strPieces = dynamic_cast<CCString *>(dict->objectForKey("Pieces"));
	if (strPieces != NULL)
	{
		uint32 pieces = strPieces->uintValue();
		if (pieces == 2)
		{
			m_type = kEffectDefineType_Piece2;
		}
		else if (pieces == 4)
		{
			m_type = kEffectDefineType_Piece4;
		}
		else
		{
			m_type = kEffectDefineType_Piece1;
		}
	}
	else
	{
		m_type = kEffectDefineType_Piece1;
	}
	
	CCString * name = dynamic_cast<CCString *>(dict->objectForKey("PieceKey"));
	m_animationName = string(name->getCString());
	
	m_spriteDefiner = YHSpriteDefiner((CCDictionary *)dict->objectForKey("SpriteDefiner"));
}
uint32 uintValueFromDictionary(CCDictionary * dict, const string & key)
{
	CCString * result = dynamic_cast<CCString *>(dict->objectForKey(key));
	if (result != NULL)
	{
		return result->uintValue();
	}
	else
	{
		return 0;
	}
}
Esempio n. 3
0
bool GameDisplayNode::initWithDictionary(CCDictionary * tmpDict){
	
	CCNode * _displayNode = NULL;
	if (tmpDict) {
		CCString * strValue = (CCString *)tmpDict->objectForKey(KStrType);
		uint32_t typeValue = strValue->uintValue();
		strValue = (CCString *)tmpDict->objectForKey(KStrFile);
		switch (typeValue) {
			case GameObject::K_SPRITE_FRAME:
			{
				_displayNode = CCSprite::createWithSpriteFrameName(strValue->getCString());
				this->addChild(_displayNode);
				_defaultFrame = strValue->getCString();
			}
				break;
			case GameObject::K_SPRITE_FILE:
			{
				_displayNode = CCSprite::create(strValue->getCString());
				this->addChild(_displayNode);
				_defaultFrame = strValue->getCString();
			}
				break;
			case GameObject::K_CCBI_FILE:
			{
				//动画加载
				CC_SAFE_RELEASE_NULL(_animationManager);
				string ccbifile = strValue->getCString();
				CCNodeLoaderLibrary *ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
				CCBReader * ccBReader = new CCBReader(ccNodeLoaderLibrary);
				_displayNode = ccBReader->readNodeGraphFromFile(ccbifile.c_str(),this,&_animationManager);
				_animationManager->retain();
				_animationManager->setDelegate(this);
				this->addChild(_displayNode);
				CC_SAFE_RELEASE_NULL(ccBReader);
				
				CCString * default_frame = (CCString *)tmpDict->objectForKey(KStrDefaultFrame);
				if (default_frame) {
					_defaultFrame = default_frame->getCString();
				}
				
				CCString * default_anim=(CCString *)tmpDict->objectForKey(KStrDefaultAnim);
				if (default_anim) {
					_defaultAnimation = default_anim->getCString();
				}
			}
				break;
			default:
				break;
		}
	}
	return true;
}
YHAnimationFrameDefiner::YHAnimationFrameDefiner(CCDictionary * dict)
{
	// index
	CCString * strIndex = dynamic_cast<CCString *>(dict->objectForKey("Index"));
	m_index = strIndex->uintValue();
	
	// Delay units
	CCString * strDelayUnits = dynamic_cast<CCString *>(dict->objectForKey("DelayUnits"));
	m_delayUnit = strDelayUnits != NULL ? strDelayUnits->floatValue() : 1.0f;
	
	// UserData
	m_userInfo = dynamic_cast<CCDictionary *>(dict->objectForKey("UserInfo"));
	CC_SAFE_RETAIN(m_userInfo);
}
Price createPriceWithDictionary(CCDictionary * dict)
{
	Price::CoinType coinType;
	uint32 value;
	
	CCString * strType = (CCString *)dict->objectForKey(PRICE_TYPE_KEY);
	if (strType->compare(PRICE_COIN) == 0)
	{
		coinType = Price::kCoinType_Coin;
	}
	else if (strType->compare(PRICE_GEM) == 0)
	{
		coinType = Price::kCoinType_Gem;
	}
	else
	{
		coinType = Price::kCoinType_Unknown;
	}
	
	CCString * strNumber = (CCString *)dict->objectForKey(PRICE_VALUE_KEY);
	value = strNumber->uintValue();
	return Price(coinType, value);
}