X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FBlockTypeRegistry.hpp;h=23b183a1b1cf765a390d920bc9b41278f7500fd5;hb=b3c37033944671429f8db22c3754caef7add1695;hp=9d9597dde0716348245f8a3e4d0622b008b50d8c;hpb=9240fdf2e68ee014da0d0a89a7fb2f29ebf28e2d;p=blank.git diff --git a/src/world/BlockTypeRegistry.hpp b/src/world/BlockTypeRegistry.hpp index 9d9597d..23b183a 100644 --- a/src/world/BlockTypeRegistry.hpp +++ b/src/world/BlockTypeRegistry.hpp @@ -3,6 +3,8 @@ #include "BlockType.hpp" +#include +#include #include @@ -20,7 +22,9 @@ public: public: BlockTypeRegistry(); - Block::Type Add(const BlockType &); + /// register a new block type + /// this may throw if the name is already taken (names must be unique) + Block::Type Add(BlockType &&); size_t size() const noexcept { return types.size(); } @@ -29,14 +33,20 @@ public: iterator end() noexcept { return types.end(); } const_iterator end() const noexcept { return types.end(); } - BlockType &operator [](Block::Type id) { return types[id]; } - const BlockType &operator [](Block::Type id) const { return types[id]; } + /// lookup by ID + BlockType &operator [](Block::Type id) noexcept { return types[id]; } + const BlockType &operator [](Block::Type id) const noexcept { return types[id]; } - BlockType &Get(Block::Type id) { return types[id]; } - const BlockType &Get(Block::Type id) const { return types[id]; } + BlockType &Get(Block::Type id) noexcept { return types[id]; } + const BlockType &Get(Block::Type id) const noexcept { return types[id]; } + + /// lookup by name + BlockType &Get(const std::string &name); + const BlockType &Get(const std::string &name) const; private: std::vector types; + std::map names; };