forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParameter.php
More file actions
118 lines (92 loc) · 3.49 KB
/
Copy pathParameter.php
File metadata and controls
118 lines (92 loc) · 3.49 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
class Parameter
{
public $processor;
public $name; // rect, copy, etc
public $types = []; // an array containing all possible types it can be: string, number, etc
public $help = [];
public $optional = false;
public $default = null; // assigned value is the default value
public $debug = '';
public function __construct($processor, $line)
{
$this->processor = $processor;
preg_match("/.*(@param)\s?{(\S*)} (\S*)( - ?)?(.*)/", $line, $output);
// $this->processor->log("Parameter count: " . count($output));
if (count($output) > 2)
{
// $this->processor->log("parsePhaser parameter");
$this->parsePhaser($output);
}
else
{
preg_match("/(@param)\s(\S*)\s{(\S*)}\s?(.*)?/", $line, $output);
$this->processor->log("parsePixi parameter - " . count($output));
if (count($output) > 0)
{
$this->parsePixi($output);
}
}
}
public function parsePhaser($output)
{
$name = $output[3];
$this->processor->log("parameter: $name");
if ($name[0] === '[')
{
$this->optional = true;
$name = substr($name, 1, -1);
// Default?
$equals = strpos($name, '=');
if ($equals > 0)
{
$this->default = (string) substr($name, $equals + 1);
$name = substr($name, 0, $equals);
}
}
$this->name = $name;
// Remove optional braces
if (substr($output[2], 0, 1) === "(")
{
$output[2] = substr($output[2], 1, -1);
}
$this->types = explode('|', $output[2]);
// @param {number[]|string[]} frames - An array of numbers or strings indicating which frames to play in which order.
// @param {(number[]|...number)} points - An array of 2d vectors that form the convex or concave polygon.
// Either [[0,0], [0,1],...] or a flat array of numbers that will be interpreted as [x,y, x,y, ...],
// or the arguments passed can be flat x,y values e.g. `setPolygon(options, x,y, x,y, x,y, ...)` where `x` and `y` are numbers.
foreach ($this->types as $key => $type)
{
if (substr($type, -2) === "[]")
{
$this->types[$key] = "Array " . substr($type, 0, -2);
}
}
$this->help[] = $output[5];
}
public function parsePixi($output)
{
$this->name = $output[2];
$this->types[] = $output[3];
$this->processor->log("parameter: $this->name");
if (isset($output[4]))
{
$this->help[] = $output[4];
}
}
public function getArray()
{
return array(
'name' => $this->name,
'type' => $this->types,
'help' => implode('\n', $this->help),
'optional' => $this->optional,
'default' => $this->default
);
}
public function getJSON()
{
return json_encode($this->getArray());
}
}
?>