change rigs role from assets to content units
This commit is contained in:
+16
-5
@@ -8,6 +8,7 @@
|
||||
#include "../voxels/Block.hpp"
|
||||
#include "../items/ItemDef.hpp"
|
||||
#include "../objects/EntityDef.hpp"
|
||||
#include "../objects/rigging.hpp"
|
||||
|
||||
#include "ContentPack.hpp"
|
||||
#include "../logic/scripting/scripting.hpp"
|
||||
@@ -27,20 +28,30 @@ Content::Content(
|
||||
ContentUnitDefs<Block> blocks,
|
||||
ContentUnitDefs<ItemDef> items,
|
||||
ContentUnitDefs<EntityDef> entities,
|
||||
std::unordered_map<std::string, std::unique_ptr<ContentPackRuntime>> packs,
|
||||
std::unordered_map<std::string, std::unique_ptr<BlockMaterial>> blockMaterials
|
||||
UptrsMap<std::string, ContentPackRuntime> packs,
|
||||
UptrsMap<std::string, BlockMaterial> blockMaterials,
|
||||
UptrsMap<std::string, rigging::RigConfig> rigs
|
||||
) : indices(std::move(indices)),
|
||||
packs(std::move(packs)),
|
||||
blockMaterials(std::move(blockMaterials)),
|
||||
rigs(std::move(rigs)),
|
||||
blocks(std::move(blocks)),
|
||||
items(std::move(items)),
|
||||
entities(std::move(entities)),
|
||||
drawGroups(std::move(drawGroups))
|
||||
drawGroups(std::move(drawGroups))
|
||||
{}
|
||||
|
||||
Content::~Content() {
|
||||
}
|
||||
|
||||
const rigging::RigConfig* Content::getRig(const std::string& id) const {
|
||||
auto found = rigs.find(id);
|
||||
if (found == rigs.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return found->second.get();
|
||||
}
|
||||
|
||||
const BlockMaterial* Content::findBlockMaterial(const std::string& id) const {
|
||||
auto found = blockMaterials.find(id);
|
||||
if (found == blockMaterials.end()) {
|
||||
@@ -57,10 +68,10 @@ const ContentPackRuntime* Content::getPackRuntime(const std::string& id) const {
|
||||
return found->second.get();
|
||||
}
|
||||
|
||||
const std::unordered_map<std::string, std::unique_ptr<BlockMaterial>>& Content::getBlockMaterials() const {
|
||||
const UptrsMap<std::string, BlockMaterial>& Content::getBlockMaterials() const {
|
||||
return blockMaterials;
|
||||
}
|
||||
|
||||
const std::unordered_map<std::string, std::unique_ptr<ContentPackRuntime>>& Content::getPacks() const {
|
||||
const UptrsMap<std::string, ContentPackRuntime>& Content::getPacks() const {
|
||||
return packs;
|
||||
}
|
||||
|
||||
+17
-8
@@ -11,6 +11,8 @@
|
||||
#include <set>
|
||||
|
||||
using DrawGroups = std::set<ubyte>;
|
||||
template<class K, class V>
|
||||
using UptrsMap = std::unordered_map<K, std::unique_ptr<V>>;
|
||||
|
||||
class Block;
|
||||
struct BlockMaterial;
|
||||
@@ -19,6 +21,10 @@ struct EntityDef;
|
||||
class Content;
|
||||
class ContentPackRuntime;
|
||||
|
||||
namespace rigging {
|
||||
class RigConfig;
|
||||
}
|
||||
|
||||
enum class contenttype {
|
||||
none, block, item, entity
|
||||
};
|
||||
@@ -83,9 +89,9 @@ public:
|
||||
|
||||
template<class T>
|
||||
class ContentUnitDefs {
|
||||
std::unordered_map<std::string, std::unique_ptr<T>> defs;
|
||||
UptrsMap<std::string, T> defs;
|
||||
public:
|
||||
ContentUnitDefs(std::unordered_map<std::string, std::unique_ptr<T>> defs)
|
||||
ContentUnitDefs(UptrsMap<std::string, T> defs)
|
||||
: defs(std::move(defs)) {
|
||||
}
|
||||
|
||||
@@ -108,8 +114,9 @@ public:
|
||||
/// @brief Content is a definitions repository
|
||||
class Content {
|
||||
std::unique_ptr<ContentIndices> indices;
|
||||
std::unordered_map<std::string, std::unique_ptr<ContentPackRuntime>> packs;
|
||||
std::unordered_map<std::string, std::unique_ptr<BlockMaterial>> blockMaterials;
|
||||
UptrsMap<std::string, ContentPackRuntime> packs;
|
||||
UptrsMap<std::string, BlockMaterial> blockMaterials;
|
||||
UptrsMap<std::string, rigging::RigConfig> rigs;
|
||||
public:
|
||||
ContentUnitDefs<Block> blocks;
|
||||
ContentUnitDefs<ItemDef> items;
|
||||
@@ -122,8 +129,9 @@ public:
|
||||
ContentUnitDefs<Block> blocks,
|
||||
ContentUnitDefs<ItemDef> items,
|
||||
ContentUnitDefs<EntityDef> entities,
|
||||
std::unordered_map<std::string, std::unique_ptr<ContentPackRuntime>> packs,
|
||||
std::unordered_map<std::string, std::unique_ptr<BlockMaterial>> blockMaterials
|
||||
UptrsMap<std::string, ContentPackRuntime> packs,
|
||||
UptrsMap<std::string, BlockMaterial> blockMaterials,
|
||||
UptrsMap<std::string, rigging::RigConfig> rigs
|
||||
);
|
||||
~Content();
|
||||
|
||||
@@ -131,11 +139,12 @@ public:
|
||||
return indices.get();
|
||||
}
|
||||
|
||||
const rigging::RigConfig* getRig(const std::string& id) const;
|
||||
const BlockMaterial* findBlockMaterial(const std::string& id) const;
|
||||
const ContentPackRuntime* getPackRuntime(const std::string& id) const;
|
||||
|
||||
const std::unordered_map<std::string, std::unique_ptr<BlockMaterial>>& getBlockMaterials() const;
|
||||
const std::unordered_map<std::string, std::unique_ptr<ContentPackRuntime>>& getPacks() const;
|
||||
const UptrsMap<std::string, BlockMaterial>& getBlockMaterials() const;
|
||||
const UptrsMap<std::string, ContentPackRuntime>& getPacks() const;
|
||||
};
|
||||
|
||||
#endif // CONTENT_CONTENT_HPP_
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
#include "ContentBuilder.hpp"
|
||||
|
||||
#include "../objects/rigging.hpp"
|
||||
|
||||
ContentBuilder::~ContentBuilder() {}
|
||||
|
||||
void ContentBuilder::add(std::unique_ptr<ContentPackRuntime> pack) {
|
||||
packs[pack->getId()] = std::move(pack);
|
||||
}
|
||||
|
||||
void ContentBuilder::add(std::unique_ptr<rigging::RigConfig> rig) {
|
||||
rigs[rig->getName()] = std::move(rig);
|
||||
}
|
||||
|
||||
BlockMaterial& ContentBuilder::createBlockMaterial(const std::string& id) {
|
||||
blockMaterials[id] = std::make_unique<BlockMaterial>();
|
||||
auto& material = *blockMaterials[id];
|
||||
@@ -68,7 +74,8 @@ std::unique_ptr<Content> ContentBuilder::build() {
|
||||
items.build(),
|
||||
entities.build(),
|
||||
std::move(packs),
|
||||
std::move(blockMaterials)
|
||||
std::move(blockMaterials),
|
||||
std::move(rigs)
|
||||
);
|
||||
|
||||
// Now, it's time to resolve foreign keys
|
||||
|
||||
@@ -23,7 +23,7 @@ class ContentUnitBuilder {
|
||||
}
|
||||
}
|
||||
public:
|
||||
std::unordered_map<std::string, std::unique_ptr<T>> defs;
|
||||
UptrsMap<std::string, T> defs;
|
||||
std::vector<std::string> names;
|
||||
|
||||
ContentUnitBuilder(
|
||||
@@ -49,8 +49,9 @@ public:
|
||||
};
|
||||
|
||||
class ContentBuilder {
|
||||
std::unordered_map<std::string, std::unique_ptr<BlockMaterial>> blockMaterials;
|
||||
std::unordered_map<std::string, std::unique_ptr<ContentPackRuntime>> packs;
|
||||
UptrsMap<std::string, BlockMaterial> blockMaterials;
|
||||
UptrsMap<std::string, rigging::RigConfig> rigs;
|
||||
UptrsMap<std::string, ContentPackRuntime> packs;
|
||||
std::unordered_map<std::string, contenttype> allNames;
|
||||
public:
|
||||
ContentUnitBuilder<Block> blocks {allNames, contenttype::block};
|
||||
@@ -60,6 +61,7 @@ public:
|
||||
~ContentBuilder();
|
||||
|
||||
void add(std::unique_ptr<ContentPackRuntime> pack);
|
||||
void add(std::unique_ptr<rigging::RigConfig> rig);
|
||||
|
||||
BlockMaterial& createBlockMaterial(const std::string& id);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "../debug/Logger.hpp"
|
||||
#include "../files/files.hpp"
|
||||
#include "../items/ItemDef.hpp"
|
||||
#include "../objects/rigging.hpp"
|
||||
#include "../logic/scripting/scripting.hpp"
|
||||
#include "../typedefs.hpp"
|
||||
#include "../util/listutil.hpp"
|
||||
@@ -458,4 +459,14 @@ void ContentLoader::load() {
|
||||
loadBlockMaterial(builder.createBlockMaterial(name), file);
|
||||
}
|
||||
}
|
||||
|
||||
fs::path rigsDir = folder / fs::u8path("rigs");
|
||||
if (fs::is_directory(rigsDir)) {
|
||||
for (const auto& entry : fs::directory_iterator(rigsDir)) {
|
||||
const fs::path& file = entry.path();
|
||||
std::string name = pack->id+":"+file.stem().u8string();
|
||||
std::string text = files::read_string(file);
|
||||
builder.add(rigging::RigConfig::parse(text, file.u8string(), name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user