#ifndef CONTENT_CONTENT_BUILDER_HPP_ #define CONTENT_CONTENT_BUILDER_HPP_ #include "../items/ItemDef.hpp" #include "../voxels/Block.hpp" #include "../objects/EntityDef.hpp" #include "../content/Content.hpp" #include "../content/ContentPack.hpp" #include #include #include template class ContentUnitBuilder { std::unordered_map& allNames; contenttype type; void checkIdentifier(const std::string& id) { const auto& found = allNames.find(id); if (found != allNames.end()) { throw namereuse_error("name "+id+" is already used", found->second); } } public: UptrsMap defs; std::vector names; ContentUnitBuilder( std::unordered_map& allNames, contenttype type ) : allNames(allNames), type(type) {} T& create(const std::string& id) { auto found = defs.find(id); if (found != defs.end()) { return *found->second; } checkIdentifier(id); allNames[id] = type; names.push_back(id); defs[id] = std::make_unique(id); return *defs[id]; } auto build() { return std::move(defs); } }; class ContentBuilder { UptrsMap blockMaterials; UptrsMap skeletons; UptrsMap packs; std::unordered_map allNames; public: ContentUnitBuilder blocks {allNames, contenttype::block}; ContentUnitBuilder items {allNames, contenttype::item}; ContentUnitBuilder entities {allNames, contenttype::entity}; ResourceIndicesSet resourceIndices {}; ~ContentBuilder(); void add(std::unique_ptr pack); void add(std::unique_ptr skeleton); BlockMaterial& createBlockMaterial(const std::string& id); std::unique_ptr build(); }; #endif // CONTENT_CONTENT_BUILDER_HPP_