Reduce the size of block_factory_consistency_check.json by improving the storage format

this reduces the size by 65%, but more importantly, doesn't cause several pages of flooding in git diff.
This commit is contained in:
Dylan K. Taylor 2022-07-06 23:20:13 +01:00
parent ae70c63798
commit 8886a023f1
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 17 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@ -45,7 +45,12 @@ if(file_exists($oldTablePath)){
if(!is_array($oldTable)){ if(!is_array($oldTable)){
throw new \pocketmine\utils\AssumptionFailedError("Old table should be array{knownStates: array<string, string>, stateDataBits: int}"); throw new \pocketmine\utils\AssumptionFailedError("Old table should be array{knownStates: array<string, string>, stateDataBits: int}");
} }
$old = $oldTable["knownStates"]; $old = [];
foreach($oldTable["knownStates"] as $name => $stateIds){
foreach($stateIds as $stateId){
$old[$stateId] = $name;
}
}
$oldStateDataSize = $oldTable["stateDataBits"]; $oldStateDataSize = $oldTable["stateDataBits"];
$oldStateDataMask = ~(~0 << $oldStateDataSize); $oldStateDataMask = ~(~0 << $oldStateDataSize);
@ -72,15 +77,23 @@ if(file_exists($oldTablePath)){
echo "Name changed ($newId:$newStateData) " . $old[$reconstructedK] . " -> " . $name . "\n"; echo "Name changed ($newId:$newStateData) " . $old[$reconstructedK] . " -> " . $name . "\n";
} }
} }
} }
}else{ }else{
echo "WARNING: Unable to calculate diff, no previous consistency check file found\n"; echo "WARNING: Unable to calculate diff, no previous consistency check file found\n";
} }
$newTable = [];
foreach($new as $stateId => $name){
$newTable[$name][] = $stateId;
}
ksort($newTable, SORT_STRING);
foreach($newTable as &$stateIds){
sort($stateIds, SORT_NUMERIC);
}
file_put_contents(__DIR__ . '/block_factory_consistency_check.json', json_encode( file_put_contents(__DIR__ . '/block_factory_consistency_check.json', json_encode(
[ [
"knownStates" => $new, "knownStates" => $newTable,
"stateDataBits" => Block::INTERNAL_STATE_DATA_BITS "stateDataBits" => Block::INTERNAL_STATE_DATA_BITS
], ],
JSON_THROW_ON_ERROR JSON_THROW_ON_ERROR