use explicit constructors

This commit is contained in:
Konstantin Käfer
2014-05-15 14:56:06 +02:00
parent 44f8c80d21
commit 27b695b068
2 changed files with 7 additions and 8 deletions

View File

@@ -16,7 +16,7 @@ class Map;
class SpritePosition {
public:
SpritePosition(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t pixelRatio = 1);
explicit SpritePosition(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t pixelRatio = 1);
uint16_t x = 0, y = 0;
uint16_t width = 0, height = 0;
@@ -25,8 +25,8 @@ public:
class ImagePosition {
public:
ImagePosition() {}
ImagePosition(const vec2<uint16_t>& size, vec2<float> tl, vec2<float> br);
explicit ImagePosition() {}
explicit ImagePosition(const vec2<uint16_t>& size, vec2<float> tl, vec2<float> br);
vec2<uint16_t> size = { 0, 0 };
vec2<float> tl = { 0, 0 };

View File

@@ -101,15 +101,14 @@ void Sprite::parseJSON(std::shared_ptr<Sprite> &sprite) {
if (value.HasMember("width")) width = value["width"].GetInt();
if (value.HasMember("height")) height = value["height"].GetInt();
if (value.HasMember("pixelRatio")) pixelRatio = value["pixelRatio"].GetInt();
sprite->pos.insert({ name, { x, y, width, height, pixelRatio } });
sprite->pos.emplace(name, SpritePosition { x, y, width, height, pixelRatio });
}
}
}
}
ImagePosition Sprite::getPosition(const std::string& name, bool repeating) {
if (!isLoaded()) return {};
if (!isLoaded()) return ImagePosition {};
// `repeating` indicates that the image will be used in a repeating pattern
// repeating pattern images are assumed to have a 1px padding that mirrors the opposite edge
@@ -117,10 +116,10 @@ ImagePosition Sprite::getPosition(const std::string& name, bool repeating) {
int8_t offset = repeating ? 1 : 0;
auto it = pos.find(name);
if (it == pos.end()) return {};
if (it == pos.end()) return ImagePosition {};
SpritePosition& pos = it->second;
return {
return ImagePosition {
{
pos.width,
pos.height