disallow changing an existing Sprite's size

This commit is contained in:
Konstantin Käfer
2015-06-26 12:17:35 +02:00
parent 086e72afe3
commit aa2dcf1968
2 changed files with 38 additions and 7 deletions

View File

@@ -17,15 +17,21 @@ void SpriteStore::setSprite(const std::string& name, std::shared_ptr<const Sprit
void SpriteStore::_setSprite(const std::string& name,
const std::shared_ptr<const SpriteImage>& sprite) {
if (sprite) {
if (sprite->pixelRatio == pixelRatio) {
sprites.emplace(name, sprite);
dirty.emplace(name, sprite);
return;
} else {
if (sprite->pixelRatio != pixelRatio) {
Log::Warning(Event::Sprite, "Sprite image has wrong pixel ratio");
return;
}
}
if (sprites.erase(name) > 0) {
auto it = sprites.find(name);
if (it != sprites.end() &&
(it->second->width != sprite->width || it->second->height != sprite->height)) {
Log::Warning(Event::Sprite, "Can't change sprite dimensions");
return;
}
sprites.emplace_hint(it, name, sprite);
dirty.emplace(name, sprite);
} else if (sprites.erase(name) > 0) {
dirty.emplace(name, nullptr);
}
}