Merge branch 'temp'

This commit is contained in:
Felix Ableitner 2013-03-31 15:34:23 +02:00
commit 5ddc6c6c97
13 changed files with 61 additions and 14 deletions

View file

@ -21,7 +21,7 @@ class World;
class Game : private sf::NonCopyable {
// Public functions.
public:
Game(sf::RenderWindow& window);
explicit Game(sf::RenderWindow& window);
~Game();
void loop();

View file

@ -20,7 +20,7 @@ class Yaml;
class Character : public Sprite {
// Public functions.
public:
Character(World& world, const Data& data, const Yaml& config);
explicit Character(World& world, const Data& data, const Yaml& config);
virtual ~Character() = 0;
void onDamage(int damage);

View file

@ -37,7 +37,7 @@ public:
*/
class Data {
public:
Data(const sf::Vector2f& position,
explicit Data(const sf::Vector2f& position,
Category category, unsigned short mask,
const sf::Vector2f& direction = sf::Vector2f(0, 0));
const sf::Vector2f& position;
@ -56,7 +56,7 @@ public:
// Public functions.
public:
Sprite(const Data& data, const Yaml& config);
explicit Sprite(const Data& data, const Yaml& config);
virtual ~Sprite() = 0;
sf::Vector2f getPosition() const;

View file

@ -18,7 +18,7 @@ class Yaml;
class Bullet : public Particle {
// Public functions.
public:
Bullet(const sf::Vector2f& position, Sprite& shooter,
explicit Bullet(const sf::Vector2f& position, Sprite& shooter,
sf::Vector2f direction, const Yaml& config);
void onCollide(std::shared_ptr<Sprite> other);

View file

@ -27,7 +27,7 @@ class Particle;
class Weapon : public Emitter {
// Public functions.
public:
Weapon(World& world, Sprite& holder, const Yaml& config);
explicit Weapon(World& world, Sprite& holder, const Yaml& config);
void pullTrigger();
void releaseTrigger();

View file

@ -17,7 +17,7 @@ class Sprite;
class Emitter {
// Public functions.
public:
Emitter(World& world);
explicit Emitter(World& world);
virtual ~Emitter();
// Protected functions.

View file

@ -18,7 +18,7 @@ class Yaml;
class Particle : public Sprite {
// Public functions.
public:
Particle(const Yaml& config, const Data& data);
explicit Particle(const Yaml& config, const Data& data);
virtual ~Particle();
};

View file

@ -15,7 +15,7 @@ class Yaml;
class Corpse : public Sprite {
// Public functions.
public:
Corpse(const sf::Vector2f& position, const Yaml& config);
explicit Corpse(const sf::Vector2f& position, const Yaml& config);
};
#endif /* DG_CORPSE_H_ */

View file

@ -16,7 +16,7 @@ class Yaml;
class Enemy : public Character {
// Public functions.
public:
Enemy(World& world, const sf::Vector2f& position, const Yaml& config);
explicit Enemy(World& world, const sf::Vector2f& position, const Yaml& config);
};
#endif /* DG_ENEMY_H_ */

View file

@ -31,7 +31,7 @@ public:
// Public functions.
public:
Player(World& world, const sf::Vector2f& position, const Yaml& config);
explicit Player(World& world, const sf::Vector2f& position, const Yaml& config);
void setCrosshairPosition(const sf::Vector2f& position);
void pullTrigger();

View file

@ -32,7 +32,7 @@ public:
// Public functions.
public:
TileManager(World& world);
explicit TileManager(World& world);
void insertTile(const TilePosition& position, Type type);
void removeTile(const TilePosition& position);
@ -57,7 +57,7 @@ private:
class TileManager::Tile : public Sprite {
// Public functions.
public:
Tile(Type type, const TilePosition& position);
explicit Tile(Type type, const TilePosition& position);
Type getType() const;
TilePosition getTilePosition() const;

View file

@ -23,7 +23,7 @@
class Yaml {
// Public functions.
public:
Yaml(const std::string& filename);
explicit Yaml(const std::string& filename);
~Yaml();
std::string getFilename() const;

47
source/util/Yaml.inl Normal file
View file

@ -0,0 +1,47 @@
/*
* Yaml.h
*
* Created on: 30.03.2013
* Author: Felix
*/
#include <SFML/System.hpp>
#include "Log.h"
/**
* Stream output operators to specialize Yaml::get for other types.
* Error handling is done in Yaml::get.
*/
namespace {
void operator>>(const YAML::Node& node, sf::Vector2i& vector) {
node[0] >> vector.x;
node[1] >> vector.y;
}
void operator>>(const YAML::Node& node, sf::Vector2f& vector) {
node[0] >> vector.x;
node[1] >> vector.y;
}
}
/**
* Gets a value of a specified type by key. Returns default value on error.
*
* @param key The string by which to select the return value.
* @tparam T The type of the return value.
* @return The value of the specified key.
*/
template <typename T>
T Yaml::get(const std::string& key, const T& defaultValue) const {
try {
const YAML::Node* node = mNode.FindValue(key);
T value;
*node >> value;
return value;
}
catch (YAML::InvalidScalar&) {
LOG_W("Failed to get key " << key << " from " << mFolder << mFilename);
return defaultValue;
}
};