Prep for RP
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import { BlockVerifier } from "./BlockVerifier";
|
||||
import { BlockVerificationLevel } from "./BlockVerificationLevel";
|
||||
|
||||
export class StructureVerifier {
|
||||
constructor(instance) {
|
||||
this.instance = instance;
|
||||
this.blockVerificationLevels = {};
|
||||
this.statistics = {};
|
||||
this.initStatistics();
|
||||
}
|
||||
|
||||
async verifyStructure() {
|
||||
await this.runVerifier();
|
||||
this.parseStatistics();
|
||||
return this.statistics;
|
||||
}
|
||||
|
||||
async runVerifier() {
|
||||
return new Promise((resolve) => {
|
||||
this.verifyBlocks();
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
verifyBlocks() {
|
||||
for (const block of this.instance.getBlocks()) {
|
||||
const verificationLevel = this.verifyBlock(block.location);
|
||||
if (verificationLevel !== BlockVerificationLevel.isAir)
|
||||
this.blockVerificationLevels[JSON.stringify(block.location)] = verificationLevel;
|
||||
else
|
||||
this.statistics.correctlyAir++;
|
||||
}
|
||||
}
|
||||
|
||||
verifyBlock(location) {
|
||||
const worldBlock = this.instance.getDimension().getBlock(this.instance.toGlobalCoords(location));
|
||||
if (!worldBlock)
|
||||
throw new Error(`Block at ${JSON.stringify(location)} could not be accessed.`);
|
||||
const blockVerifier = new BlockVerifier(worldBlock, this.instance);
|
||||
return blockVerifier.verify();
|
||||
}
|
||||
|
||||
initStatistics() {
|
||||
for (const verificationlevel of Object.values(BlockVerificationLevel)) {
|
||||
this.statistics[verificationlevel] = 0;
|
||||
}
|
||||
this.statistics.percentages = {};
|
||||
this.statistics.correctlyAir = 0;
|
||||
}
|
||||
|
||||
parseStatistics() {
|
||||
for (const blockVerificationLevel of Object.values(BlockVerificationLevel)) {
|
||||
this.parseStatistic(blockVerificationLevel);
|
||||
}
|
||||
}
|
||||
|
||||
parseStatistic(blockVerificationLevel) {
|
||||
for (const verificationlevel of Object.values(this.blockVerificationLevels)) {
|
||||
if (blockVerificationLevel === verificationlevel) {
|
||||
this.statistics[verificationlevel]++;
|
||||
}
|
||||
}
|
||||
this.statistics.percentages[blockVerificationLevel] = this.statistics[blockVerificationLevel] / (this.instance.getTotalVolume() - this.statistics.correctlyAir) * 100;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user