mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 04:17:07 +00:00
Implement support for remappedPropertyValuesIndex schema format
This commit is contained in:
parent
dc5ddf1c1b
commit
1b3e50d0a3
8
composer.lock
generated
8
composer.lock
generated
@ -253,12 +253,12 @@
|
|||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/pmmp/BedrockData.git",
|
"url": "https://github.com/pmmp/BedrockData.git",
|
||||||
"reference": "607e4766c95f448b607c05a7e5170b43f9420ab0"
|
"reference": "1d96dd836a77996719ed09dced6e4bba99b0fc1e"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/pmmp/BedrockData/zipball/607e4766c95f448b607c05a7e5170b43f9420ab0",
|
"url": "https://api.github.com/repos/pmmp/BedrockData/zipball/1d96dd836a77996719ed09dced6e4bba99b0fc1e",
|
||||||
"reference": "607e4766c95f448b607c05a7e5170b43f9420ab0",
|
"reference": "1d96dd836a77996719ed09dced6e4bba99b0fc1e",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"type": "library",
|
"type": "library",
|
||||||
@ -271,7 +271,7 @@
|
|||||||
"issues": "https://github.com/pmmp/BedrockData/issues",
|
"issues": "https://github.com/pmmp/BedrockData/issues",
|
||||||
"source": "https://github.com/pmmp/BedrockData/tree/experimental/upgrade-tables"
|
"source": "https://github.com/pmmp/BedrockData/tree/experimental/upgrade-tables"
|
||||||
},
|
},
|
||||||
"time": "2022-02-09T19:48:12+00:00"
|
"time": "2022-02-09T21:52:48+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pocketmine/bedrock-protocol",
|
"name": "pocketmine/bedrock-protocol",
|
||||||
|
@ -35,6 +35,7 @@ use pocketmine\nbt\tag\Tag;
|
|||||||
use pocketmine\utils\Utils;
|
use pocketmine\utils\Utils;
|
||||||
use Webmozart\PathUtil\Path;
|
use Webmozart\PathUtil\Path;
|
||||||
use function array_map;
|
use function array_map;
|
||||||
|
use function count;
|
||||||
use function file_get_contents;
|
use function file_get_contents;
|
||||||
use function get_class;
|
use function get_class;
|
||||||
use function implode;
|
use function implode;
|
||||||
@ -43,6 +44,8 @@ use function is_object;
|
|||||||
use function is_string;
|
use function is_string;
|
||||||
use function json_decode;
|
use function json_decode;
|
||||||
use function ksort;
|
use function ksort;
|
||||||
|
use function str_pad;
|
||||||
|
use function strval;
|
||||||
use const JSON_THROW_ON_ERROR;
|
use const JSON_THROW_ON_ERROR;
|
||||||
use const SORT_NUMERIC;
|
use const SORT_NUMERIC;
|
||||||
|
|
||||||
@ -133,14 +136,22 @@ final class BlockStateUpgradeSchemaUtils{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$convertedRemappedValuesIndex = [];
|
||||||
|
foreach(Utils::stringifyKeys($model->remappedPropertyValuesIndex ?? []) as $mappingKey => $mappingValues){
|
||||||
|
foreach($mappingValues as $k => $oldNew){
|
||||||
|
$convertedRemappedValuesIndex[$mappingKey][$k] = new BlockStateUpgradeSchemaValueRemap(
|
||||||
|
self::jsonModelToTag($oldNew->old),
|
||||||
|
self::jsonModelToTag($oldNew->new)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach(Utils::stringifyKeys($model->remappedPropertyValues ?? []) as $blockName => $properties){
|
foreach(Utils::stringifyKeys($model->remappedPropertyValues ?? []) as $blockName => $properties){
|
||||||
foreach(Utils::stringifyKeys($properties) as $property => $mappedValuesKey){
|
foreach(Utils::stringifyKeys($properties) as $property => $mappedValuesKey){
|
||||||
foreach($mappedValuesKey as $oldNew){
|
if(!isset($convertedRemappedValuesIndex[$mappedValuesKey])){
|
||||||
$result->remappedPropertyValues[$blockName][$property][] = new BlockStateUpgradeSchemaValueRemap(
|
throw new \UnexpectedValueException("Missing key from schema values index $mappedValuesKey");
|
||||||
self::jsonModelToTag($oldNew->old),
|
|
||||||
self::jsonModelToTag($oldNew->new)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
$result->remappedPropertyValues[$blockName][$property] = $convertedRemappedValuesIndex[$mappedValuesKey];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,6 +168,64 @@ final class BlockStateUpgradeSchemaUtils{
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function buildRemappedValuesIndex(BlockStateUpgradeSchema $schema, BlockStateUpgradeSchemaModel $model) : void{
|
||||||
|
if(count($schema->remappedPropertyValues) === 0){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$dedupMapping = [];
|
||||||
|
$dedupTable = [];
|
||||||
|
$dedupTableMap = [];
|
||||||
|
$counter = 0;
|
||||||
|
|
||||||
|
foreach(Utils::stringifyKeys($schema->remappedPropertyValues) as $blockName => $remaps){
|
||||||
|
foreach(Utils::stringifyKeys($remaps) as $propertyName => $remappedValues){
|
||||||
|
$remappedValuesMap = [];
|
||||||
|
foreach($remappedValues as $oldNew){
|
||||||
|
$remappedValuesMap[$oldNew->old->toString()] = $oldNew;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(Utils::stringifyKeys($dedupTableMap) as $dedupName => $dedupValuesMap){
|
||||||
|
if(count($remappedValuesMap) !== count($dedupValuesMap)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(Utils::stringifyKeys($remappedValuesMap) as $oldHash => $remappedOldNew){
|
||||||
|
if(
|
||||||
|
!isset($dedupValuesMap[$oldHash]) ||
|
||||||
|
!$remappedOldNew->old->equals($dedupValuesMap[$oldHash]->old) ||
|
||||||
|
!$remappedOldNew->new->equals($dedupValuesMap[$oldHash]->new)
|
||||||
|
){
|
||||||
|
continue 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//we found a match
|
||||||
|
$dedupMapping[$blockName][$propertyName] = $dedupName;
|
||||||
|
continue 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
//no match, add the values to the table
|
||||||
|
$newDedupName = $propertyName . "_" . str_pad(strval($counter++), 2, "0", STR_PAD_LEFT);
|
||||||
|
$dedupTableMap[$newDedupName] = $remappedValuesMap;
|
||||||
|
$dedupTable[$newDedupName] = $remappedValues;
|
||||||
|
$dedupMapping[$blockName][$propertyName] = $newDedupName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$modelTable = [];
|
||||||
|
foreach(Utils::stringifyKeys($dedupTable) as $dedupName => $valuePairs){
|
||||||
|
foreach($valuePairs as $k => $pair){
|
||||||
|
$modelTable[$dedupName][$k] = new BlockStateUpgradeSchemaModelValueRemap(
|
||||||
|
BlockStateUpgradeSchemaUtils::tagToJsonModel($pair->old),
|
||||||
|
BlockStateUpgradeSchemaUtils::tagToJsonModel($pair->new),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$model->remappedPropertyValuesIndex = $modelTable;
|
||||||
|
$model->remappedPropertyValues = $dedupMapping;
|
||||||
|
}
|
||||||
|
|
||||||
public static function toJsonModel(BlockStateUpgradeSchema $schema) : BlockStateUpgradeSchemaModel{
|
public static function toJsonModel(BlockStateUpgradeSchema $schema) : BlockStateUpgradeSchemaModel{
|
||||||
$result = new BlockStateUpgradeSchemaModel();
|
$result = new BlockStateUpgradeSchemaModel();
|
||||||
$result->maxVersionMajor = $schema->maxVersionMajor;
|
$result->maxVersionMajor = $schema->maxVersionMajor;
|
||||||
@ -173,16 +242,7 @@ final class BlockStateUpgradeSchemaUtils{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(Utils::stringifyKeys($schema->remappedPropertyValues) as $blockName => $properties){
|
self::buildRemappedValuesIndex($schema, $result);
|
||||||
foreach(Utils::stringifyKeys($properties) as $property => $propertyValues){
|
|
||||||
foreach($propertyValues as $oldNew){
|
|
||||||
$result->remappedPropertyValues[$blockName][$property][] = new BlockStateUpgradeSchemaModelValueRemap(
|
|
||||||
self::tagToJsonModel($oldNew->old),
|
|
||||||
self::tagToJsonModel($oldNew->new)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach(Utils::stringifyKeys($schema->remappedStates) as $oldBlockName => $remaps){
|
foreach(Utils::stringifyKeys($schema->remappedStates) as $oldBlockName => $remaps){
|
||||||
foreach($remaps as $remap){
|
foreach($remaps as $remap){
|
||||||
|
@ -64,11 +64,17 @@ final class BlockStateUpgradeSchemaModel implements \JsonSerializable{
|
|||||||
public array $renamedProperties;
|
public array $renamedProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var BlockStateUpgradeSchemaModelValueRemap[][][]
|
* @var string[][]
|
||||||
* @phpstan-var array<string, array<string, list<BlockStateUpgradeSchemaModelValueRemap>>>
|
* @phpstan-var array<string, array<string, string>>
|
||||||
*/
|
*/
|
||||||
public array $remappedPropertyValues;
|
public array $remappedPropertyValues;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var BlockStateUpgradeSchemaModelValueRemap[][]
|
||||||
|
* @phpstan-var array<string, list<BlockStateUpgradeSchemaModelValueRemap>>
|
||||||
|
*/
|
||||||
|
public array $remappedPropertyValuesIndex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var BlockStateUpgradeSchemaModelBlockRemap[][]
|
* @var BlockStateUpgradeSchemaModelBlockRemap[][]
|
||||||
* @phpstan-var array<string, list<BlockStateUpgradeSchemaModelBlockRemap>>
|
* @phpstan-var array<string, list<BlockStateUpgradeSchemaModelBlockRemap>>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user