Added Yaml config to Sprite (for texture file).

This commit is contained in:
Felix Ableitner 2012-10-12 20:59:33 +02:00
parent c93a6b0c9e
commit d7013ce63a
5 changed files with 14 additions and 7 deletions

View file

@ -20,7 +20,7 @@ std::vector<Character*> Character::mCharacterInstances = std::vector<Character*>
*/
Character::Character(const Instances& instances, const String& texturePath,
const PhysicalData& data, const Yaml& config) :
Sprite(texturePath, data),
Sprite(config, data),
mMaxHealth(config.get<int>(KEY_HEALTH)),
mCurrentHealth(mMaxHealth),
mInstances(instances) {

View file

@ -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<sf::Texture>(texturePath))),
mTexture(ResourceManager::i().acquire(Loader::i()
.fromFile<sf::Texture>(config.get<String>(KEY_TEXTURE)))),
mSize(data.size) {
}

View file

@ -13,10 +13,12 @@
#include <Thor/Resources.hpp>
#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<sf::Texture>& texture, const PhysicalData& data);
virtual ~Sprite() = 0;
@ -36,6 +38,8 @@ protected:
// Private variables.
private:
static const String KEY_TEXTURE;
std::shared_ptr<sf::Texture> mTexture;
Vector2i mSize;
};

View file

@ -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)) {
}

View file

@ -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)) {
}