tools/generate-blockstate-upgrade-schema: added support for generating newFlattenedName with value transforms

as seen in pmmp/BedrockBlockUpgradeSchema@ebd768e5b2, this enables use of newFlattenedName in more places (by allowing the flattened values to be transformed before building the new ID), as well as reducing the number of remappedStates in general by compacting stuff which was partially transformed like color silver -> light_gray.
This commit is contained in:
Dylan K. Taylor
2024-04-05 17:13:38 +01:00
parent e30e27dd57
commit 16f29c775e
5 changed files with 149 additions and 36 deletions

View File

@ -23,7 +23,9 @@ declare(strict_types=1);
namespace pocketmine\data\bedrock\block\upgrade\model;
final class BlockStateUpgradeSchemaModelFlattenedName{
use function count;
final class BlockStateUpgradeSchemaModelFlattenedName implements \JsonSerializable{
/** @required */
public string $prefix;
@ -31,10 +33,31 @@ final class BlockStateUpgradeSchemaModelFlattenedName{
public string $flattenedProperty;
/** @required */
public string $suffix;
/**
* @var string[]
* @phpstan-var array<string, string>
*/
public array $flattenedValueRemaps;
public function __construct(string $prefix, string $flattenedProperty, string $suffix){
/**
* @param string[] $flattenedValueRemaps
* @phpstan-param array<string, string> $flattenedValueRemaps
*/
public function __construct(string $prefix, string $flattenedProperty, string $suffix, array $flattenedValueRemaps){
$this->prefix = $prefix;
$this->flattenedProperty = $flattenedProperty;
$this->suffix = $suffix;
$this->flattenedValueRemaps = $flattenedValueRemaps;
}
/**
* @return mixed[]
*/
public function jsonSerialize() : array{
$result = (array) $this;
if(count($this->flattenedValueRemaps) === 0){
unset($result["flattenedValueRemaps"]);
}
return $result;
}
}