| 84 | } |
| 85 | |
| 86 | void AnimationCache::parseVersion1(const ValueMap& animations) |
| 87 | { |
| 88 | SpriteFrameCache* frameCache = SpriteFrameCache::getInstance(); |
| 89 | |
| 90 | for (const auto& anim : animations) |
| 91 | { |
| 92 | const ValueMap& animationDict = anim.second.asValueMap(); |
| 93 | const ValueVector& frameNames = animationDict.at("frames").asValueVector(); |
| 94 | float delay = animationDict.at("delay").asFloat(); |
| 95 | Animation* animation = nullptr; |
| 96 | |
| 97 | if (frameNames.empty()) |
| 98 | { |
| 99 | AXLOGW( |
| 100 | "axmol: AnimationCache: Animation '{}' found in dictionary without any frames - cannot add to " |
| 101 | "animation cache.", |
| 102 | anim.first); |
| 103 | continue; |
| 104 | } |
| 105 | |
| 106 | ssize_t frameNameSize = frameNames.size(); |
| 107 | Vector<AnimationFrame*> frames(frameNameSize); |
| 108 | |
| 109 | for (auto&& frameName : frameNames) |
| 110 | { |
| 111 | SpriteFrame* spriteFrame = frameCache->getSpriteFrameByName(frameName.asString()); |
| 112 | |
| 113 | if (!spriteFrame) |
| 114 | { |
| 115 | AXLOGW( |
| 116 | "axmol:AnimationCache: Animation '{}' refers to frame '{}' which is not currently in the " |
| 117 | "SpriteFrameCache. This frame will not be added to the animation.", |
| 118 | anim.first, frameName.asString()); |
| 119 | |
| 120 | continue; |
| 121 | } |
| 122 | |
| 123 | AnimationFrame* animFrame = AnimationFrame::create(spriteFrame, 1, ValueMap()); |
| 124 | frames.pushBack(animFrame); |
| 125 | } |
| 126 | |
| 127 | if (frames.empty()) |
| 128 | { |
| 129 | AXLOGW( |
| 130 | "axmol:AnimationCache: None of the frames for animation '{}' were found in the SpriteFrameCache. " |
| 131 | "Animation is not being added to the Animation Cache.", |
| 132 | anim.first); |
| 133 | continue; |
| 134 | } |
| 135 | else if (frames.size() != frameNameSize) |
| 136 | { |
| 137 | AXLOGW( |
| 138 | "axmol:AnimationCache: An animation in your dictionary refers to a frame which is not in the " |
| 139 | "SpriteFrameCache. Some or all of the frames for the animation '{}' may be missing.", |
| 140 | anim.first); |
| 141 | } |
| 142 | |
| 143 | animation = Animation::create(frames, delay, 1); |
nothing calls this directly
no test coverage detected