diff --git a/source/abstract/Character.cpp b/source/abstract/Character.cpp index 5e89bcb..8d11f6e 100644 --- a/source/abstract/Character.cpp +++ b/source/abstract/Character.cpp @@ -20,7 +20,7 @@ std::vector Character::mCharacterInstances = std::vector */ Character::Character(const Instances& instances, const String& texturePath, const PhysicalData& data, const Yaml& config) : - Sprite(texturePath, data), + Sprite(config, data), mMaxHealth(config.get(KEY_HEALTH)), mCurrentHealth(mMaxHealth), mInstances(instances) { diff --git a/source/abstract/Sprite.cpp b/source/abstract/Sprite.cpp index de8e5ce..f264161 100644 --- a/source/abstract/Sprite.cpp +++ b/source/abstract/Sprite.cpp @@ -10,14 +10,17 @@ #include "../util/Loader.h" #include "../util/ResourceManager.h" +const String Sprite::KEY_TEXTURE = "texture"; + /** * Loads sprite from ResourceManager, sets world position. * * @param texturePath Relative path to the texture file in the resource folder. */ -Sprite::Sprite(const String& texturePath, const PhysicalData& data) : +Sprite::Sprite(const Yaml& config, const PhysicalData& data) : Physical(data), - mTexture(ResourceManager::i().acquire(Loader::i().fromFile(texturePath))), + mTexture(ResourceManager::i().acquire(Loader::i() + .fromFile(config.get(KEY_TEXTURE)))), mSize(data.size) { } diff --git a/source/abstract/Sprite.h b/source/abstract/Sprite.h index c0b8f7d..b7bdd7e 100644 --- a/source/abstract/Sprite.h +++ b/source/abstract/Sprite.h @@ -13,10 +13,12 @@ #include #include "Physical.h" -#include "../util/Vector.h" #include "../util/String.h" +#include "../util/Vector.h" +#include "../util/Yaml.h" class Physical; +class Yaml; /** * Represents a drawable object. @@ -26,7 +28,7 @@ class Physical; class Sprite : public sf::Drawable, public Physical { // Public functions. public: - Sprite(const String& texturePath, const PhysicalData& data); + Sprite(const Yaml& config, const PhysicalData& data); Sprite(const std::shared_ptr& texture, const PhysicalData& data); virtual ~Sprite() = 0; @@ -36,6 +38,8 @@ protected: // Private variables. private: + static const String KEY_TEXTURE; + std::shared_ptr mTexture; Vector2i mSize; }; diff --git a/source/sprite/Body.cpp b/source/sprite/Body.cpp index bf6d052..13ce3c9 100755 --- a/source/sprite/Body.cpp +++ b/source/sprite/Body.cpp @@ -8,7 +8,7 @@ #include "Body.h" Body::Body(b2World& world, const Vector2f& position, const Yaml& config) : - Sprite("body.png", PhysicalData(position, Vector2i(50, 50), world, + Sprite(config, PhysicalData(position, Vector2i(50, 50), world, CATEGORY_NONSOLID, MASK_NONE, false)) { } diff --git a/source/sprite/Cover.cpp b/source/sprite/Cover.cpp index 4b91a52..2488f95 100755 --- a/source/sprite/Cover.cpp +++ b/source/sprite/Cover.cpp @@ -8,6 +8,6 @@ #include "Cover.h" Cover::Cover(const Vector2f& position, const Vector2i& size, b2World& world, const Yaml& config) : - Sprite("cover.png", PhysicalData(position, size, world, CATEGORY_WORLD, MASK_ALL, false)) { + Sprite(config, PhysicalData(position, size, world, CATEGORY_WORLD, MASK_ALL, false)) { }