/* * ===================================================================================== * * Filename: Registry.hpp * * Description: * * Created: 23/06/2018 22:32:51 * * Author: Quentin Bazin, * * ===================================================================================== */ #ifndef REGISTRY_HPP_ #define REGISTRY_HPP_ #include #include #include #include "Block.hpp" #include "Item.hpp" #include "Recipe.hpp" class Registry { public: void registerBlockFromTable(const sol::table &table); void registerItemFromTable(const sol::table &table); void registerCraftingRecipeFromTable(const sol::table &table); void registerSmeltingRecipeFromTable(const sol::table &table); const Block &getBlock(std::size_t id) const { return m_blocks.at(id); } const Item &getItem(std::size_t id) const { return m_items.at(id); } const Block &getBlock(const std::string &name); const Item &getItem(const std::string &name); const Recipe *getRecipe(const Inventory &inventory) const; static Registry &getInstance() { return *s_instance; } static void setInstance(Registry &instance) { s_instance = &instance; } private: Block ®isterBlock(u32 textureID, const std::string &name, const std::string &label); Item ®isterItem(u32 textureID, const std::string &name, const std::string &label); template auto registerRecipe(Args &&...args) -> typename std::enable_if::value, Recipe*>::type { return m_recipes.emplace_back(std::make_unique(std::forward(args)...)).get(); } static Registry *s_instance; std::vector m_blocks; std::vector m_items; std::vector> m_recipes; std::unordered_map m_blocksID; std::unordered_map m_itemsID; }; #endif // REGISTRY_HPP_