issue #2790: Uses non-const ValueMap for simplifying codes in CCAnimationCache.cpp.

This commit is contained in:
James Chen 2013-12-07 14:22:03 +08:00
parent d8061477c1
commit 0091ca2b6f
1 changed files with 9 additions and 9 deletions

View File

@ -141,12 +141,12 @@ void AnimationCache::parseVersion2(const ValueMap& animations)
for (auto iter = animations.cbegin(); iter != animations.cend(); ++iter) for (auto iter = animations.cbegin(); iter != animations.cend(); ++iter)
{ {
std::string name = iter->first; std::string name = iter->first;
const ValueMap& animationDict = iter->second.asValueMap(); ValueMap& animationDict = const_cast<ValueMap&>(iter->second.asValueMap());
const Value& loops = animationDict.at("loops"); const Value& loops = animationDict["loops"];
bool restoreOriginalFrame = animationDict.at("restoreOriginalFrame").asBool(); bool restoreOriginalFrame = animationDict["restoreOriginalFrame"].asBool();
const ValueVector& frameArray = animationDict.at("frames").asValueVector(); ValueVector& frameArray = animationDict["frames"].asValueVector();
if ( frameArray.empty() ) if ( frameArray.empty() )
{ {
@ -159,8 +159,8 @@ void AnimationCache::parseVersion2(const ValueMap& animations)
for (auto& obj : frameArray) for (auto& obj : frameArray)
{ {
const ValueMap& entry = obj.asValueMap(); ValueMap& entry = obj.asValueMap();
std::string spriteFrameName = entry.at("spriteframe").asString(); std::string spriteFrameName = entry["spriteframe"].asString();
SpriteFrame *spriteFrame = frameCache->getSpriteFrameByName(spriteFrameName); SpriteFrame *spriteFrame = frameCache->getSpriteFrameByName(spriteFrameName);
if( ! spriteFrame ) { if( ! spriteFrame ) {
@ -169,15 +169,15 @@ void AnimationCache::parseVersion2(const ValueMap& animations)
continue; continue;
} }
float delayUnits = entry.at("delayUnits").asFloat(); float delayUnits = entry["delayUnits"].asFloat();
const Value& userInfo = entry.at("notification"); Value& userInfo = entry["notification"];
AnimationFrame *animFrame = AnimationFrame::create(spriteFrame, delayUnits, userInfo.asValueMap()); AnimationFrame *animFrame = AnimationFrame::create(spriteFrame, delayUnits, userInfo.asValueMap());
array.pushBack(animFrame); array.pushBack(animFrame);
} }
float delayPerUnit = animationDict.at("delayPerUnit").asFloat(); float delayPerUnit = animationDict["delayPerUnit"].asFloat();
Animation *animation = Animation::create(array, delayPerUnit, loops.getType() != Value::Type::NONE ? loops.asInt() : 1); Animation *animation = Animation::create(array, delayPerUnit, loops.getType() != Value::Type::NONE ? loops.asInt() : 1);
animation->setRestoreOriginalFrame(restoreOriginalFrame); animation->setRestoreOriginalFrame(restoreOriginalFrame);