-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.php
43 lines (32 loc) · 1001 Bytes
/
command.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
chdir(dirname(__FILE__));
if (php_sapi_name() !== 'cli') {
exit();
}
require_once('bootstrap.php');
CLI::checkColorConsoleSupport();
function renderHelp()
{
echo "\nPathbuilder 2e to Roll 20 VTT Command Line Tool\n";
echo "Usage: php command.php --input=file.json > roll20.json \n\n";
exit();
}
$options = getopt('i:o:h', [
"input:",
"help",
]);
if (empty($options) || isset($options['help']) || !isset($options['input'])) {
renderHelp();
}
if (!file_exists($options['input'])) {
CLI::fatal('Input File Doesn\'t Exist.');
}
$player = null;
$json = file_get_contents($options['input']);
try {
$player = \PBR20\Factory\Player::create($json);
} catch (Exception $e) {
CLI::fatal('Invalid JSON Struct.');
}
$struct = \PBR20\Services\Conversion::getInstance()->convert($player);
echo json_encode($struct, JSON_PRETTY_PRINT);