add content issues (WIP)
This commit is contained in:
parent
3dda512468
commit
c1ef4dbe9f
@ -24,15 +24,15 @@ namespace rigging {
|
||||
class SkeletonConfig;
|
||||
}
|
||||
|
||||
constexpr const char* contenttype_name(contenttype type) {
|
||||
constexpr const char* contenttype_name(ContentType type) {
|
||||
switch (type) {
|
||||
case contenttype::none:
|
||||
case ContentType::NONE:
|
||||
return "none";
|
||||
case contenttype::block:
|
||||
case ContentType::BLOCK:
|
||||
return "block";
|
||||
case contenttype::item:
|
||||
case ContentType::ITEM:
|
||||
return "item";
|
||||
case contenttype::entity:
|
||||
case ContentType::ENTITY:
|
||||
return "entity";
|
||||
default:
|
||||
return "unknown";
|
||||
@ -40,13 +40,13 @@ constexpr const char* contenttype_name(contenttype type) {
|
||||
}
|
||||
|
||||
class namereuse_error : public std::runtime_error {
|
||||
contenttype type;
|
||||
ContentType type;
|
||||
public:
|
||||
namereuse_error(const std::string& msg, contenttype type)
|
||||
namereuse_error(const std::string& msg, ContentType type)
|
||||
: std::runtime_error(msg), type(type) {
|
||||
}
|
||||
|
||||
inline contenttype getType() const {
|
||||
inline ContentType getType() const {
|
||||
return type;
|
||||
}
|
||||
};
|
||||
|
||||
@ -12,8 +12,8 @@
|
||||
|
||||
template <class T>
|
||||
class ContentUnitBuilder {
|
||||
std::unordered_map<std::string, contenttype>& allNames;
|
||||
contenttype type;
|
||||
std::unordered_map<std::string, ContentType>& allNames;
|
||||
ContentType type;
|
||||
|
||||
void checkIdentifier(const std::string& id) {
|
||||
const auto& found = allNames.find(id);
|
||||
@ -28,7 +28,7 @@ public:
|
||||
std::vector<std::string> names;
|
||||
|
||||
ContentUnitBuilder(
|
||||
std::unordered_map<std::string, contenttype>& allNames, contenttype type
|
||||
std::unordered_map<std::string, ContentType>& allNames, ContentType type
|
||||
)
|
||||
: allNames(allNames), type(type) {
|
||||
}
|
||||
@ -62,11 +62,11 @@ class ContentBuilder {
|
||||
UptrsMap<std::string, BlockMaterial> blockMaterials;
|
||||
UptrsMap<std::string, rigging::SkeletonConfig> skeletons;
|
||||
UptrsMap<std::string, ContentPackRuntime> packs;
|
||||
std::unordered_map<std::string, contenttype> allNames;
|
||||
std::unordered_map<std::string, ContentType> allNames;
|
||||
public:
|
||||
ContentUnitBuilder<Block> blocks {allNames, contenttype::block};
|
||||
ContentUnitBuilder<ItemDef> items {allNames, contenttype::item};
|
||||
ContentUnitBuilder<EntityDef> entities {allNames, contenttype::entity};
|
||||
ContentUnitBuilder<Block> blocks {allNames, ContentType::BLOCK};
|
||||
ContentUnitBuilder<ItemDef> items {allNames, ContentType::ITEM};
|
||||
ContentUnitBuilder<EntityDef> entities {allNames, ContentType::ENTITY};
|
||||
ResourceIndicesSet resourceIndices {};
|
||||
|
||||
~ContentBuilder();
|
||||
|
||||
@ -12,11 +12,13 @@
|
||||
#include "Content.hpp"
|
||||
|
||||
ContentLUT::ContentLUT(
|
||||
const ContentIndices* indices, size_t blocksCount, size_t itemsCount
|
||||
const ContentIndices* indices,
|
||||
size_t blocksCount,
|
||||
size_t itemsCount
|
||||
)
|
||||
: blocks(blocksCount, indices->blocks, BLOCK_VOID, contenttype::block),
|
||||
items(itemsCount, indices->items, ITEM_VOID, contenttype::item) {
|
||||
}
|
||||
: blocks(blocksCount, indices->blocks, BLOCK_VOID, ContentType::BLOCK),
|
||||
items(itemsCount, indices->items, ITEM_VOID, ContentType::ITEM)
|
||||
{}
|
||||
|
||||
template <class T>
|
||||
static constexpr size_t get_entries_count(
|
||||
@ -47,6 +49,7 @@ std::shared_ptr<ContentLUT> ContentLUT::create(
|
||||
|
||||
lut->blocks.setup(blocklist.get(), content->blocks);
|
||||
lut->items.setup(itemlist.get(), content->items);
|
||||
lut->buildIssues();
|
||||
|
||||
if (lut->hasContentReorder() || lut->hasMissingContent()) {
|
||||
return lut;
|
||||
@ -55,8 +58,31 @@ std::shared_ptr<ContentLUT> ContentLUT::create(
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<contententry> ContentLUT::getMissingContent() const {
|
||||
std::vector<contententry> entries;
|
||||
template<class T, class U>
|
||||
static void build_issues(
|
||||
std::vector<ContentIssue>& issues,
|
||||
const ContentUnitLUT<T, U>& lut
|
||||
) {
|
||||
auto type = lut.getContentType();
|
||||
if (lut.hasContentReorder()) {
|
||||
issues.push_back(ContentIssue {ContentIssueType::REORDER, type});
|
||||
}
|
||||
if (lut.hasMissingContent()) {
|
||||
issues.push_back(ContentIssue {ContentIssueType::MISSING, type});
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLUT::buildIssues() {
|
||||
build_issues(issues, blocks);
|
||||
build_issues(issues, items);
|
||||
}
|
||||
|
||||
const std::vector<ContentIssue>& ContentLUT::getIssues() const {
|
||||
return issues;
|
||||
}
|
||||
|
||||
std::vector<ContentEntry> ContentLUT::getMissingContent() const {
|
||||
std::vector<ContentEntry> entries;
|
||||
blocks.getMissingContent(entries);
|
||||
items.getMissingContent(entries);
|
||||
return entries;
|
||||
|
||||
@ -12,8 +12,18 @@
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
struct contententry {
|
||||
contenttype type;
|
||||
enum class ContentIssueType {
|
||||
REORDER,
|
||||
MISSING,
|
||||
};
|
||||
|
||||
struct ContentIssue {
|
||||
ContentIssueType issueType;
|
||||
ContentType contentType;
|
||||
};
|
||||
|
||||
struct ContentEntry {
|
||||
ContentType type;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
@ -26,13 +36,13 @@ class ContentUnitLUT {
|
||||
bool missingContent = false;
|
||||
bool reorderContent = false;
|
||||
T missingValue;
|
||||
contenttype type;
|
||||
ContentType type;
|
||||
public:
|
||||
ContentUnitLUT(
|
||||
size_t count,
|
||||
const ContentUnitIndices<U>& unitIndices,
|
||||
T missingValue,
|
||||
contenttype type
|
||||
ContentType type
|
||||
)
|
||||
: missingValue(missingValue), type(type) {
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
@ -57,11 +67,11 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
void getMissingContent(std::vector<contententry>& entries) const {
|
||||
void getMissingContent(std::vector<ContentEntry>& entries) const {
|
||||
for (size_t i = 0; i < count(); i++) {
|
||||
if (indices[i] == missingValue) {
|
||||
auto& name = names[i];
|
||||
entries.push_back(contententry {type, name});
|
||||
entries.push_back(ContentEntry {type, name});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -80,6 +90,9 @@ public:
|
||||
reorderContent = true;
|
||||
}
|
||||
}
|
||||
inline ContentType getContentType() const {
|
||||
return type;
|
||||
}
|
||||
inline size_t count() const {
|
||||
return indices.size();
|
||||
}
|
||||
@ -99,7 +112,13 @@ public:
|
||||
ContentUnitLUT<blockid_t, Block> blocks;
|
||||
ContentUnitLUT<itemid_t, ItemDef> items;
|
||||
|
||||
ContentLUT(const ContentIndices* indices, size_t blocks, size_t items);
|
||||
std::vector<ContentIssue> issues;
|
||||
|
||||
ContentLUT(
|
||||
const ContentIndices* indices,
|
||||
size_t blocks,
|
||||
size_t items
|
||||
);
|
||||
|
||||
static std::shared_ptr<ContentLUT> create(
|
||||
const std::shared_ptr<WorldFiles>& worldFiles,
|
||||
@ -113,6 +132,8 @@ public:
|
||||
inline bool hasMissingContent() const {
|
||||
return blocks.hasMissingContent() || items.hasMissingContent();
|
||||
}
|
||||
void buildIssues();
|
||||
|
||||
std::vector<contententry> getMissingContent() const;
|
||||
const std::vector<ContentIssue>& getIssues() const;
|
||||
std::vector<ContentEntry> getMissingContent() const;
|
||||
};
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
class Content;
|
||||
class ContentPackRuntime;
|
||||
|
||||
enum class contenttype { none, block, item, entity };
|
||||
enum class ContentType { NONE, BLOCK, ITEM, ENTITY };
|
||||
|
||||
enum class ResourceType : size_t { CAMERA, LAST = CAMERA };
|
||||
|
||||
|
||||
@ -109,6 +109,7 @@ static void write_indices(
|
||||
|
||||
void WorldFiles::writeIndices(const ContentIndices* indices) {
|
||||
dynamic::Map root;
|
||||
root.put("region-version", REGION_FORMAT_VERSION);
|
||||
write_indices(indices->blocks, root.putList("blocks"));
|
||||
write_indices(indices->items, root.putList("items"));
|
||||
write_indices(indices->entities, root.putList("entities"));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user