implement blocks data conversion
This commit is contained in:
@@ -56,11 +56,40 @@ std::shared_ptr<ContentReport> ContentReport::create(
|
||||
indices, blocks_c, items_c, regionsVersion);
|
||||
report->blocks.setup(blocklist, content->blocks);
|
||||
report->items.setup(itemlist, content->items);
|
||||
|
||||
for (const auto& [name, map] : root["blocks-data"].asObject()) {
|
||||
data::StructLayout layout;
|
||||
layout.deserialize(map);
|
||||
auto def = content->blocks.find(name);
|
||||
if (def == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (def->dataStruct == nullptr) {
|
||||
ContentIssue issue {ContentIssueType::BLOCK_DATA_LAYOUTS_UPDATE};
|
||||
report->issues.push_back(issue);
|
||||
report->dataLoss.push_back(name+": discard data");
|
||||
continue;
|
||||
}
|
||||
auto incapatibility = layout.checkCompatibility(*def->dataStruct);
|
||||
if (!incapatibility.empty()) {
|
||||
ContentIssue issue {ContentIssueType::BLOCK_DATA_LAYOUTS_UPDATE};
|
||||
report->issues.push_back(issue);
|
||||
for (const auto& error : incapatibility) {
|
||||
report->dataLoss.push_back(
|
||||
"[" + name + "] field " + error.name + " - " +
|
||||
data::to_string(error.type)
|
||||
);
|
||||
}
|
||||
}
|
||||
report->blocksDataLayouts[name] = std::move(layout);
|
||||
}
|
||||
|
||||
report->buildIssues();
|
||||
|
||||
if (report->isUpgradeRequired() ||
|
||||
report->hasContentReorder() ||
|
||||
report->hasMissingContent()) {
|
||||
report->hasMissingContent() ||
|
||||
report->hasDataLoss()) {
|
||||
return report;
|
||||
} else {
|
||||
return nullptr;
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "constants.hpp"
|
||||
#include "data/dv.hpp"
|
||||
#include "typedefs.hpp"
|
||||
#include "Content.hpp"
|
||||
#include "data/StructLayout.hpp"
|
||||
#include "files/world_regions_fwd.hpp"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
@@ -17,6 +19,7 @@ enum class ContentIssueType {
|
||||
REORDER,
|
||||
MISSING,
|
||||
REGION_FORMAT_UPDATE,
|
||||
BLOCK_DATA_LAYOUTS_UPDATE,
|
||||
};
|
||||
|
||||
struct ContentIssue {
|
||||
@@ -121,7 +124,9 @@ public:
|
||||
ContentUnitLUT<itemid_t, ItemDef> items;
|
||||
uint regionsVersion;
|
||||
|
||||
std::unordered_map<std::string, data::StructLayout> blocksDataLayouts;
|
||||
std::vector<ContentIssue> issues;
|
||||
std::vector<std::string> dataLoss;
|
||||
|
||||
ContentReport(
|
||||
const ContentIndices* indices,
|
||||
@@ -136,6 +141,10 @@ public:
|
||||
const Content* content
|
||||
);
|
||||
|
||||
inline const std::vector<std::string>& getDataLoss() const {
|
||||
return dataLoss;
|
||||
}
|
||||
|
||||
inline bool hasContentReorder() const {
|
||||
return blocks.hasContentReorder() || items.hasContentReorder();
|
||||
}
|
||||
@@ -145,6 +154,9 @@ public:
|
||||
inline bool isUpgradeRequired() const {
|
||||
return regionsVersion < REGION_FORMAT_VERSION;
|
||||
}
|
||||
inline bool hasDataLoss() const {
|
||||
return !dataLoss.empty();
|
||||
}
|
||||
void buildIssues();
|
||||
|
||||
const std::vector<ContentIssue>& getIssues() const;
|
||||
|
||||
Reference in New Issue
Block a user