/* * ===================================================================================== * * 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).get(); } const Item &getItem(std::size_t id) const { return *m_items.at(id).get(); } const Recipe *getRecipe(const Inventory &inventory) const; static Registry &getInstance() { return *s_instance; } static void setInstance(Registry &instance) { s_instance = &instance; } private: template auto registerBlock(Args &&...args) -> typename std::enable_if::value, Block*>::type { return m_blocks.emplace_back(std::make_unique(std::forward(args)...)).get(); } template auto registerItem(Args &&...args) -> typename std::enable_if::value, Item*>::type { return m_items.emplace_back(std::make_unique(std::forward(args)...)).get(); } 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; }; #endif // REGISTRY_HPP_