Skip to content
Snippets Groups Projects
Commit 94e7f7d9 authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

entity/token system from hexboard

parent 9e4e0b1d
No related branches found
No related tags found
No related merge requests found
...@@ -22,12 +22,67 @@ ...@@ -22,12 +22,67 @@
#include <map> #include <map>
#include <set> #include <set>
#include <optional> #include <optional>
#include <utility>
#include "fggl/grid/hexagon.hpp" #include "fggl/grid/hexagon.hpp"
#include "fggl/math/types.hpp" #include "fggl/math/types.hpp"
namespace fggl::grid { namespace fggl::grid {
class TokenType {
public:
using PropType = int64_t;
inline void setProperty(util::GUID name, PropType newVal) {
m_properties[name] = newVal;
}
[[nodiscard]]
inline PropType getProperty(util::GUID name, PropType unsetVal=0) const {
try {
return m_properties.at(name);
} catch ( std::out_of_range& e ) {
return unsetVal;
}
}
private:
std::map<util::GUID, PropType> m_properties;
std::map<util::GUID, uint64_t> m_cost;
};
class Token {
public:
Token() = default;
explicit Token(std::shared_ptr<TokenType> type) : m_type(std::move(type)) {}
inline void setProperty(util::GUID name, TokenType::PropType newVal) {
m_properties[name] = newVal;
}
[[nodiscard]]
inline TokenType::PropType getProperty(util::GUID name, TokenType::PropType unsetVal=0) const {
try {
auto prop = m_properties.at(name);
return prop;
} catch ( std::out_of_range& ex) {
return m_type->getProperty(name, unsetVal);
}
}
[[nodiscard]]
inline TokenType::PropType getPropertyDirect(util::GUID name, TokenType::PropType unsetVal=0) const {
try {
auto prop = m_properties.at(name);
return prop;
} catch ( std::out_of_range& ex) {
return unsetVal;
}
}
private:
std::shared_ptr<TokenType> m_type;
std::map<util::GUID, TokenType::PropType> m_properties;
};
struct MaterialData { struct MaterialData {
std::string name; std::string name;
math::vec3 colour; math::vec3 colour;
...@@ -39,6 +94,7 @@ namespace fggl::grid { ...@@ -39,6 +94,7 @@ namespace fggl::grid {
struct HexTile { struct HexTile {
std::shared_ptr<MaterialData> terrain; std::shared_ptr<MaterialData> terrain;
std::vector< std::shared_ptr<Token> > m_tokens;
[[nodiscard]] [[nodiscard]]
inline std::optional<const MaterialData> data() const { inline std::optional<const MaterialData> data() const {
...@@ -46,10 +102,11 @@ namespace fggl::grid { ...@@ -46,10 +102,11 @@ namespace fggl::grid {
{} {}
} }
return *terrain.get(); return *terrain;
} }
}; };
class HexGrid { class HexGrid {
public: public:
inline bool isValidPos(const IntHex& pos) const { inline bool isValidPos(const IntHex& pos) const {
...@@ -82,6 +139,7 @@ namespace fggl::grid { ...@@ -82,6 +139,7 @@ namespace fggl::grid {
private: private:
std::map<IntHex, HexTile> m_tiles; std::map<IntHex, HexTile> m_tiles;
std::map<uint64_t, std::shared_ptr<Token>> m_tokens;
}; };
} // namespace fggl::grid } // namespace fggl::grid
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment