mirror of
https://github.com/pmmp/BedrockProtocol.git
synced 2024-11-23 13:46:18 +00:00
98 lines
2.6 KiB
PHP
98 lines
2.6 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of BedrockProtocol.
|
|
* Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
|
|
*
|
|
* BedrockProtocol is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace pocketmine\network\mcpe\protocol\tools\generate_command_parameter_types;
|
|
|
|
use function count;
|
|
use function dirname;
|
|
use function fclose;
|
|
use function file_get_contents;
|
|
use function fopen;
|
|
use function fwrite;
|
|
use function is_array;
|
|
use function json_decode;
|
|
use function strtoupper;
|
|
use function uasort;
|
|
|
|
if(count($argv) !== 2){
|
|
echo "Usage: php generate-command-parameter-types.php <input-file> \n";
|
|
echo "Hint: Input file is a JSON file like command_arg_types.json in pmmp/BedrockData\n";
|
|
exit(1);
|
|
}
|
|
|
|
$jsonRaw = file_get_contents($argv[1]);
|
|
if($jsonRaw === false){
|
|
echo "Failed to read input file $argv[1]\n";
|
|
exit(1);
|
|
}
|
|
|
|
$list = json_decode($jsonRaw, true, flags: JSON_THROW_ON_ERROR);
|
|
if(!is_array($list)){
|
|
echo "Failed to decode input file $argv[1], expected a JSON object\n";
|
|
exit(1);
|
|
}
|
|
|
|
$output = fopen(dirname(__DIR__) . "/src/types/command/CommandParameterTypes.php", "wb");
|
|
if($output === false){
|
|
throw new \RuntimeException("Failed to open output file");
|
|
}
|
|
|
|
fwrite($output, <<<'CODE'
|
|
<?php
|
|
|
|
/*
|
|
* This file is part of BedrockProtocol.
|
|
* Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
|
|
*
|
|
* BedrockProtocol is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace pocketmine\network\mcpe\protocol\types\command;
|
|
|
|
/**
|
|
* This file is automatically generated; do NOT edit it by hand.
|
|
* Regenerate it by running tools/generate-command-parameter-types.php
|
|
*/
|
|
final class CommandParameterTypes{
|
|
|
|
private function __construct(){
|
|
//NOOP
|
|
}
|
|
|
|
|
|
CODE);
|
|
|
|
uasort($list, function(array $left, array $right) : int{
|
|
return $left["id"] <=> $right["id"];
|
|
});
|
|
|
|
foreach($list as $name => $properties){
|
|
if($properties["description"] === "unknown"){
|
|
echo "Skipping $name - description unknown, assuming internal type\n";
|
|
continue;
|
|
}
|
|
|
|
fwrite($output, "\tpublic const " . strtoupper($name) . " = " . $properties["id"] . "; // " . $properties["description"] . "\n");
|
|
}
|
|
|
|
fwrite($output, "}\n");
|
|
fclose($output);
|
|
|
|
echo "Done. Don't forget to run CS fixer after generating code.\n";
|