refactor Content
This commit is contained in:
+9
-41
@@ -12,62 +12,30 @@
|
||||
#include "../logic/scripting/scripting.hpp"
|
||||
|
||||
ContentIndices::ContentIndices(
|
||||
std::vector<Block*> blockDefs,
|
||||
std::vector<ItemDef*> itemDefs
|
||||
) : blockDefs(std::move(blockDefs)),
|
||||
itemDefs(std::move(itemDefs))
|
||||
std::vector<Block*> blocks,
|
||||
std::vector<ItemDef*> items
|
||||
) : blocks(std::move(blocks)),
|
||||
items(std::move(items))
|
||||
{}
|
||||
|
||||
Content::Content(
|
||||
std::unique_ptr<ContentIndices> indices,
|
||||
std::unique_ptr<DrawGroups> drawGroups,
|
||||
std::unordered_map<std::string, std::unique_ptr<Block>> blockDefs,
|
||||
std::unordered_map<std::string, std::unique_ptr<ItemDef>> itemDefs,
|
||||
ContentUnitDefs<Block> blocks,
|
||||
ContentUnitDefs<ItemDef> items,
|
||||
std::unordered_map<std::string, std::unique_ptr<ContentPackRuntime>> packs,
|
||||
std::unordered_map<std::string, std::unique_ptr<BlockMaterial>> blockMaterials
|
||||
) : blockDefs(std::move(blockDefs)),
|
||||
itemDefs(std::move(itemDefs)),
|
||||
indices(std::move(indices)),
|
||||
) : indices(std::move(indices)),
|
||||
packs(std::move(packs)),
|
||||
blockMaterials(std::move(blockMaterials)),
|
||||
blocks(std::move(blocks)),
|
||||
items(std::move(items)),
|
||||
drawGroups(std::move(drawGroups))
|
||||
{}
|
||||
|
||||
Content::~Content() {
|
||||
}
|
||||
|
||||
Block* Content::findBlock(const std::string& id) const {
|
||||
auto found = blockDefs.find(id);
|
||||
if (found == blockDefs.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return found->second.get();
|
||||
}
|
||||
|
||||
Block& Content::requireBlock(const std::string& id) const {
|
||||
auto found = blockDefs.find(id);
|
||||
if (found == blockDefs.end()) {
|
||||
throw std::runtime_error("missing block "+id);
|
||||
}
|
||||
return *found->second;
|
||||
}
|
||||
|
||||
ItemDef* Content::findItem(const std::string& id) const {
|
||||
auto found = itemDefs.find(id);
|
||||
if (found == itemDefs.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return found->second.get();
|
||||
}
|
||||
|
||||
ItemDef& Content::requireItem(const std::string& id) const {
|
||||
auto found = itemDefs.find(id);
|
||||
if (found == itemDefs.end()) {
|
||||
throw std::runtime_error("missing item "+id);
|
||||
}
|
||||
return *found->second;
|
||||
}
|
||||
|
||||
const BlockMaterial* Content::findBlockMaterial(const std::string& id) const {
|
||||
auto found = blockMaterials.find(id);
|
||||
if (found == blockMaterials.end()) {
|
||||
|
||||
Reference in New Issue
Block a user