From fe4ff3325b91121531eded2a8d4c7a066db50bb5 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 7 Jun 2022 19:05:49 +0100 Subject: [PATCH] Add tool to dump JSON specification for block palettes this makes for easier reading to determine available properties. --- tools/generate-block-palette-spec.php | 70 +++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tools/generate-block-palette-spec.php diff --git a/tools/generate-block-palette-spec.php b/tools/generate-block-palette-spec.php new file mode 100644 index 000000000..f8365f86a --- /dev/null +++ b/tools/generate-block-palette-spec.php @@ -0,0 +1,70 @@ +getStates() as $state){ + $name = $state->getName(); + foreach($state->getStates() as $propertyName => $value){ + if($value instanceof IntTag || $value instanceof StringTag){ + $rawValue = $value->getValue(); + }elseif($value instanceof ByteTag){ + $rawValue = match($value->getValue()){ + 0 => false, + 1 => true, + default => throw new AssumptionFailedError("Unexpected ByteTag value for $name -> $propertyName ($value)") + }; + }else{ + throw new AssumptionFailedError("Unexpected tag type for $name -> $propertyName ($value)"); + } + $reportMap[$name][$propertyName][get_class($value) . ":" . $value->getValue()] = $rawValue; + } +} + +foreach($reportMap as $blockName => $propertyList){ + foreach($propertyList as $propertyName => $propertyValues){ + ksort($reportMap[$blockName][$propertyName]); + $reportMap[$blockName][$propertyName] = array_values($propertyValues); + } +} +ksort($reportMap, SORT_STRING); + +file_put_contents($argv[2], json_encode($reportMap, JSON_PRETTY_PRINT)); + +