fix: add integrity check if burg is linked to removed state (1.88.01)

This commit is contained in:
Azgaar 2022-12-04 14:51:27 +03:00
parent 4a96c24cf3
commit 0b1a2048a7
3 changed files with 14 additions and 7 deletions

View file

@ -439,7 +439,7 @@ async function parseLoadedData(data) {
const cells = pack.cells;
if (pack.cells.i.length !== pack.cells.state.length) {
const message = "Data Integrity Check. Striping issue. To fix edit the heightmap in erase mode";
const message = "Data Integrity Check. Striping issue detected. To fix edit the heightmap in erase mode";
ERROR && console.error(message);
}
@ -482,11 +482,13 @@ async function parseLoadedData(data) {
ERROR && console.error("Data Integrity Check. Invalid feature", f, "is assigned to cells", invalidCells);
});
const invalidBurgs = [...new Set(cells.burg)].filter(b => b && (!pack.burgs[b] || pack.burgs[b].removed));
invalidBurgs.forEach(b => {
const invalidCells = cells.i.filter(i => cells.burg[i] === b);
const invalidBurgs = [...new Set(cells.burg)].filter(
burgId => burgId && (!pack.burgs[burgId] || pack.burgs[burgId].removed)
);
invalidBurgs.forEach(burgId => {
const invalidCells = cells.i.filter(i => cells.burg[i] === burgId);
invalidCells.forEach(i => (cells.burg[i] = 0));
ERROR && console.error("Data Integrity Check. Invalid burg", b, "is assigned to cells", invalidCells);
ERROR && console.error("Data Integrity Check. Invalid burg", burgId, "is assigned to cells", invalidCells);
});
const invalidRivers = [...new Set(cells.r)].filter(r => r && !pack.rivers.find(river => river.i === r));
@ -524,6 +526,11 @@ async function parseLoadedData(data) {
burg.state = 0;
}
if (burg.state && pack.states[burg.state].removed) {
ERROR && console.error("Data Integrity Check. Burg", burg.i, "is linked to removed state", burg.state);
burg.state = 0;
}
if (burg.state === undefined) {
ERROR && console.error("Data Integrity Check. Burg", burg.i, "has no state data");
burg.state = 0;