| 147 | } |
| 148 | |
| 149 | void AnimationCache::parseVersion2(const ValueMap& animations) |
| 150 | { |
| 151 | SpriteFrameCache* frameCache = SpriteFrameCache::getInstance(); |
| 152 | |
| 153 | for (const auto& anim : animations) |
| 154 | { |
| 155 | std::string name = anim.first; |
| 156 | ValueMap& animationDict = const_cast<ValueMap&>(anim.second.asValueMap()); |
| 157 | |
| 158 | const Value& loops = animationDict["loops"]; |
| 159 | bool restoreOriginalFrame = animationDict["restoreOriginalFrame"].asBool(); |
| 160 | |
| 161 | ValueVector& frameArray = animationDict["frames"].asValueVector(); |
| 162 | |
| 163 | if (frameArray.empty()) |
| 164 | { |
| 165 | AXLOGW( |
| 166 | "axmol:AnimationCache: Animation '{}' found in dictionary without any frames - cannot add to " |
| 167 | "animation cache.", |
| 168 | name); |
| 169 | continue; |
| 170 | } |
| 171 | |
| 172 | // Array of AnimationFrames |
| 173 | Vector<AnimationFrame*> array(static_cast<int>(frameArray.size())); |
| 174 | |
| 175 | for (auto&& obj : frameArray) |
| 176 | { |
| 177 | ValueMap& entry = obj.asValueMap(); |
| 178 | std::string spriteFrameName = entry["spriteframe"].asString(); |
| 179 | SpriteFrame* spriteFrame = frameCache->getSpriteFrameByName(spriteFrameName); |
| 180 | |
| 181 | if (!spriteFrame) |
| 182 | { |
| 183 | AXLOGW( |
| 184 | "axmol:AnimationCache: Animation '{}' refers to frame '{}' which is not currently in the " |
| 185 | "SpriteFrameCache. This frame will not be added to the animation.", |
| 186 | name, spriteFrameName); |
| 187 | |
| 188 | continue; |
| 189 | } |
| 190 | |
| 191 | float delayUnits = entry["delayUnits"].asFloat(); |
| 192 | Value& userInfo = entry["notification"]; |
| 193 | |
| 194 | AnimationFrame* animFrame = AnimationFrame::create( |
| 195 | spriteFrame, delayUnits, userInfo.getType() == Value::Type::MAP ? userInfo.asValueMap() : ValueMapNull); |
| 196 | |
| 197 | array.pushBack(animFrame); |
| 198 | } |
| 199 | |
| 200 | float delayPerUnit = animationDict["delayPerUnit"].asFloat(); |
| 201 | Animation* animation = |
| 202 | Animation::create(array, delayPerUnit, loops.getType() != Value::Type::NONE ? loops.asInt() : 1); |
| 203 | |
| 204 | animation->setRestoreOriginalFrame(restoreOriginalFrame); |
| 205 | |
| 206 | AnimationCache::getInstance()->addAnimation(animation, name); |
nothing calls this directly
no test coverage detected