Merge branch 'temp'
This commit is contained in:
commit
5ddc6c6c97
13 changed files with 61 additions and 14 deletions
|
@ -21,7 +21,7 @@ class World;
|
||||||
class Game : private sf::NonCopyable {
|
class Game : private sf::NonCopyable {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Game(sf::RenderWindow& window);
|
explicit Game(sf::RenderWindow& window);
|
||||||
~Game();
|
~Game();
|
||||||
|
|
||||||
void loop();
|
void loop();
|
||||||
|
|
|
@ -20,7 +20,7 @@ class Yaml;
|
||||||
class Character : public Sprite {
|
class Character : public Sprite {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Character(World& world, const Data& data, const Yaml& config);
|
explicit Character(World& world, const Data& data, const Yaml& config);
|
||||||
virtual ~Character() = 0;
|
virtual ~Character() = 0;
|
||||||
|
|
||||||
void onDamage(int damage);
|
void onDamage(int damage);
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
*/
|
*/
|
||||||
class Data {
|
class Data {
|
||||||
public:
|
public:
|
||||||
Data(const sf::Vector2f& position,
|
explicit Data(const sf::Vector2f& position,
|
||||||
Category category, unsigned short mask,
|
Category category, unsigned short mask,
|
||||||
const sf::Vector2f& direction = sf::Vector2f(0, 0));
|
const sf::Vector2f& direction = sf::Vector2f(0, 0));
|
||||||
const sf::Vector2f& position;
|
const sf::Vector2f& position;
|
||||||
|
@ -56,7 +56,7 @@ public:
|
||||||
|
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Sprite(const Data& data, const Yaml& config);
|
explicit Sprite(const Data& data, const Yaml& config);
|
||||||
virtual ~Sprite() = 0;
|
virtual ~Sprite() = 0;
|
||||||
|
|
||||||
sf::Vector2f getPosition() const;
|
sf::Vector2f getPosition() const;
|
||||||
|
|
|
@ -18,7 +18,7 @@ class Yaml;
|
||||||
class Bullet : public Particle {
|
class Bullet : public Particle {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Bullet(const sf::Vector2f& position, Sprite& shooter,
|
explicit Bullet(const sf::Vector2f& position, Sprite& shooter,
|
||||||
sf::Vector2f direction, const Yaml& config);
|
sf::Vector2f direction, const Yaml& config);
|
||||||
|
|
||||||
void onCollide(std::shared_ptr<Sprite> other);
|
void onCollide(std::shared_ptr<Sprite> other);
|
||||||
|
|
|
@ -27,7 +27,7 @@ class Particle;
|
||||||
class Weapon : public Emitter {
|
class Weapon : public Emitter {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Weapon(World& world, Sprite& holder, const Yaml& config);
|
explicit Weapon(World& world, Sprite& holder, const Yaml& config);
|
||||||
|
|
||||||
void pullTrigger();
|
void pullTrigger();
|
||||||
void releaseTrigger();
|
void releaseTrigger();
|
||||||
|
|
|
@ -17,7 +17,7 @@ class Sprite;
|
||||||
class Emitter {
|
class Emitter {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Emitter(World& world);
|
explicit Emitter(World& world);
|
||||||
virtual ~Emitter();
|
virtual ~Emitter();
|
||||||
|
|
||||||
// Protected functions.
|
// Protected functions.
|
||||||
|
|
|
@ -18,7 +18,7 @@ class Yaml;
|
||||||
class Particle : public Sprite {
|
class Particle : public Sprite {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Particle(const Yaml& config, const Data& data);
|
explicit Particle(const Yaml& config, const Data& data);
|
||||||
virtual ~Particle();
|
virtual ~Particle();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ class Yaml;
|
||||||
class Corpse : public Sprite {
|
class Corpse : public Sprite {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Corpse(const sf::Vector2f& position, const Yaml& config);
|
explicit Corpse(const sf::Vector2f& position, const Yaml& config);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DG_CORPSE_H_ */
|
#endif /* DG_CORPSE_H_ */
|
||||||
|
|
|
@ -16,7 +16,7 @@ class Yaml;
|
||||||
class Enemy : public Character {
|
class Enemy : public Character {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
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_ */
|
#endif /* DG_ENEMY_H_ */
|
||||||
|
|
|
@ -31,7 +31,7 @@ public:
|
||||||
|
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
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 setCrosshairPosition(const sf::Vector2f& position);
|
||||||
void pullTrigger();
|
void pullTrigger();
|
||||||
|
|
|
@ -32,7 +32,7 @@ public:
|
||||||
|
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
TileManager(World& world);
|
explicit TileManager(World& world);
|
||||||
|
|
||||||
void insertTile(const TilePosition& position, Type type);
|
void insertTile(const TilePosition& position, Type type);
|
||||||
void removeTile(const TilePosition& position);
|
void removeTile(const TilePosition& position);
|
||||||
|
@ -57,7 +57,7 @@ private:
|
||||||
class TileManager::Tile : public Sprite {
|
class TileManager::Tile : public Sprite {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Tile(Type type, const TilePosition& position);
|
explicit Tile(Type type, const TilePosition& position);
|
||||||
|
|
||||||
Type getType() const;
|
Type getType() const;
|
||||||
TilePosition getTilePosition() const;
|
TilePosition getTilePosition() const;
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
class Yaml {
|
class Yaml {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Yaml(const std::string& filename);
|
explicit Yaml(const std::string& filename);
|
||||||
~Yaml();
|
~Yaml();
|
||||||
|
|
||||||
std::string getFilename() const;
|
std::string getFilename() const;
|
||||||
|
|
47
source/util/Yaml.inl
Normal file
47
source/util/Yaml.inl
Normal 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;
|
||||||
|
}
|
||||||
|
};
|
Reference in a new issue