add block/item tags
This commit is contained in:
parent
d59a901ae0
commit
8bdf31d7bb
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
"texture": "coal_ore",
|
"texture": "coal_ore",
|
||||||
|
"tags": ["base:ore"],
|
||||||
"base:durability": 16.0
|
"base:durability": 16.0
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,5 +7,6 @@
|
|||||||
"obstacle": false,
|
"obstacle": false,
|
||||||
"selectable": false,
|
"selectable": false,
|
||||||
"replaceable": true,
|
"replaceable": true,
|
||||||
"translucent": true
|
"translucent": true,
|
||||||
|
"tags": ["base:liquid"]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,9 @@ std::unique_ptr<Content> ContentBuilder::build() {
|
|||||||
// Generating runtime info
|
// Generating runtime info
|
||||||
def.rt.id = blockDefsIndices.size();
|
def.rt.id = blockDefsIndices.size();
|
||||||
def.rt.emissive = *reinterpret_cast<uint32_t*>(def.emission);
|
def.rt.emissive = *reinterpret_cast<uint32_t*>(def.emission);
|
||||||
|
for (const auto& tag : def.tags) {
|
||||||
|
def.rt.tags.push_back(tags.add(tag));
|
||||||
|
}
|
||||||
|
|
||||||
if (def.variants) {
|
if (def.variants) {
|
||||||
for (auto& variant : def.variants->variants) {
|
for (auto& variant : def.variants->variants) {
|
||||||
|
|||||||
@ -62,6 +62,27 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct TagsIndices {
|
||||||
|
int nextIndex = 1;
|
||||||
|
std::unordered_map<std::string, int> map;
|
||||||
|
|
||||||
|
int add(const std::string& tag) {
|
||||||
|
const auto& found = map.find(tag);
|
||||||
|
if (found != map.end()) {
|
||||||
|
return found->second;
|
||||||
|
}
|
||||||
|
return map[tag] = nextIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
int indexOf(const std::string& tag) {
|
||||||
|
const auto& found = map.find(tag);
|
||||||
|
if (found == map.end()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return found->second;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class ContentBuilder {
|
class ContentBuilder {
|
||||||
UptrsMap<std::string, BlockMaterial> blockMaterials;
|
UptrsMap<std::string, BlockMaterial> blockMaterials;
|
||||||
UptrsMap<std::string, rigging::SkeletonConfig> skeletons;
|
UptrsMap<std::string, rigging::SkeletonConfig> skeletons;
|
||||||
@ -74,6 +95,7 @@ public:
|
|||||||
ContentUnitBuilder<GeneratorDef> generators {allNames, ContentType::GENERATOR};
|
ContentUnitBuilder<GeneratorDef> generators {allNames, ContentType::GENERATOR};
|
||||||
ResourceIndicesSet resourceIndices {};
|
ResourceIndicesSet resourceIndices {};
|
||||||
dv::value defaults = nullptr;
|
dv::value defaults = nullptr;
|
||||||
|
TagsIndices tags {};
|
||||||
|
|
||||||
~ContentBuilder();
|
~ContentBuilder();
|
||||||
|
|
||||||
|
|||||||
@ -89,6 +89,7 @@ template<> void ContentUnitLoader<Block>::loadUnit(
|
|||||||
) {
|
) {
|
||||||
auto root = io::read_json(file);
|
auto root = io::read_json(file);
|
||||||
process_properties(def, name, root);
|
process_properties(def, name, root);
|
||||||
|
process_tags(def, root);
|
||||||
|
|
||||||
if (root.has("parent")) {
|
if (root.has("parent")) {
|
||||||
const auto& parentName = root["parent"].asString();
|
const auto& parentName = root["parent"].asString();
|
||||||
|
|||||||
@ -21,3 +21,17 @@ inline void process_properties(T& def, const std::string& name, const dv::value&
|
|||||||
process_method(def.properties, suffix, field, value);
|
process_method(def.properties, suffix, field, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline void process_tags(T& def, const dv::value& root) {
|
||||||
|
if (!root.has("tags")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto& tags = root["tags"];
|
||||||
|
for (const auto& tagValue : tags) {
|
||||||
|
if (!tagValue.isString()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
def.tags.push_back(tagValue.asString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ template<> void ContentUnitLoader<ItemDef>::loadUnit(
|
|||||||
) {
|
) {
|
||||||
auto root = io::read_json(file);
|
auto root = io::read_json(file);
|
||||||
process_properties(def, name, root);
|
process_properties(def, name, root);
|
||||||
|
process_tags(def, root);
|
||||||
|
|
||||||
if (root.has("parent")) {
|
if (root.has("parent")) {
|
||||||
const auto& parentName = root["parent"].asString();
|
const auto& parentName = root["parent"].asString();
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "data/dv.hpp"
|
#include "data/dv.hpp"
|
||||||
#include "typedefs.hpp"
|
#include "typedefs.hpp"
|
||||||
@ -64,11 +65,15 @@ struct ItemDef {
|
|||||||
|
|
||||||
std::string scriptFile;
|
std::string scriptFile;
|
||||||
|
|
||||||
|
std::vector<std::string> tags;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
itemid_t id;
|
itemid_t id;
|
||||||
blockid_t placingBlock;
|
blockid_t placingBlock;
|
||||||
ItemFuncsSet funcsset {};
|
ItemFuncsSet funcsset {};
|
||||||
bool emissive = false;
|
bool emissive = false;
|
||||||
|
|
||||||
|
std::vector<int> tags;
|
||||||
} rt {};
|
} rt {};
|
||||||
|
|
||||||
ItemDef(const std::string& name);
|
ItemDef(const std::string& name);
|
||||||
|
|||||||
@ -261,6 +261,8 @@ public:
|
|||||||
|
|
||||||
std::unique_ptr<Variants> variants;
|
std::unique_ptr<Variants> variants;
|
||||||
|
|
||||||
|
std::vector<std::string> tags;
|
||||||
|
|
||||||
/// @brief Runtime indices (content indexing results)
|
/// @brief Runtime indices (content indexing results)
|
||||||
struct {
|
struct {
|
||||||
/// @brief block runtime integer id
|
/// @brief block runtime integer id
|
||||||
@ -285,6 +287,8 @@ public:
|
|||||||
itemid_t pickingItem = 0;
|
itemid_t pickingItem = 0;
|
||||||
|
|
||||||
blockid_t surfaceReplacement = 0;
|
blockid_t surfaceReplacement = 0;
|
||||||
|
|
||||||
|
std::vector<int> tags;
|
||||||
} rt {};
|
} rt {};
|
||||||
|
|
||||||
Block(const std::string& name);
|
Block(const std::string& name);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user