1 | <?php |
||
40 | class Entity implements EntityInterface |
||
41 | { |
||
42 | use MeshAttributes; |
||
43 | |||
44 | /** |
||
45 | * Array of used components |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $components = array(); |
||
50 | |||
51 | /** |
||
52 | * Array of used animations |
||
53 | * |
||
54 | * @var array |
||
55 | */ |
||
56 | protected $animations = array(); |
||
57 | |||
58 | /** |
||
59 | * Dom element attributes |
||
60 | * |
||
61 | * @var unknown |
||
62 | */ |
||
63 | protected $attrs = array(); |
||
64 | |||
65 | /** |
||
66 | * Children Factory |
||
67 | * |
||
68 | * @var \AframeVR\Core\Helpers\EntityChildrenFactory |
||
69 | */ |
||
70 | protected $childrenFactory; |
||
71 | |||
72 | /** |
||
73 | * Indent used when rendering formated outout |
||
74 | * |
||
75 | * @var unknown |
||
76 | */ |
||
77 | private $indentation = 0; |
||
78 | |||
79 | /** |
||
80 | * Constructor |
||
81 | * |
||
82 | * @param string $id |
||
83 | */ |
||
84 | public function __construct(string $id = '0') |
||
91 | 81 | ||
92 | /** |
||
93 | * Reset primitive default attributtes |
||
94 | * |
||
95 | * {@inheritdoc} |
||
96 | * |
||
97 | * @return void |
||
98 | */ |
||
99 | public function reset() |
||
106 | 76 | ||
107 | /** |
||
108 | * Child entity / primitive |
||
109 | * |
||
110 | * @return \AframeVR\Core\Helpers\EntityChildrenFactory |
||
111 | */ |
||
112 | public function child(): EntityChildrenFactory |
||
116 | |||
117 | 81 | /** |
|
118 | 81 | * Position component |
|
119 | * |
||
120 | * All entities inherently have the position component. |
||
121 | * |
||
122 | * @param int|float $x_axis |
||
123 | * @param int|float $y_axis |
||
124 | * @param int|float $z_axis |
||
125 | 6 | * @return \AframeVR\Interfaces\EntityInterface |
|
126 | */ |
||
127 | 6 | public function position(float $x_axis = 0, float $y_axis = 0, float $z_axis = 0): EntityInterface |
|
134 | |||
135 | /** |
||
136 | * Rotation component |
||
137 | * |
||
138 | * All entities inherently have the rotation component. |
||
139 | * |
||
140 | 4 | * @param int|float $roll |
|
141 | * @param int|float $pitch |
||
142 | 4 | * @param int|float $yaw |
|
143 | 4 | * @return \AframeVR\Interfaces\EntityInterface |
|
144 | 4 | */ |
|
145 | 4 | public function rotation(float $roll = 0, float $pitch = 0, float $yaw = 0): EntityInterface |
|
152 | |||
153 | /** |
||
154 | * Scale component |
||
155 | * |
||
156 | * All entities inherently have the scale component. |
||
157 | * |
||
158 | 4 | * @param int|float $scale_x |
|
159 | * @param int|float $scale_y |
||
160 | 4 | * @param int|float $scale_z |
|
161 | 4 | * @return \AframeVR\Interfaces\EntityInterface |
|
162 | 4 | */ |
|
163 | 4 | public function scale(float $scale_x = 1, float $scale_y = 1, float $scale_z = 1): EntityInterface |
|
170 | |||
171 | /** |
||
172 | * Animations |
||
173 | * |
||
174 | * @param mixed $name |
||
175 | * @return \AframeVR\Interfaces\AnimationInterface |
||
176 | 8 | */ |
|
177 | public function animation($name = '0'): AnimationInterface |
||
181 | 8 | ||
182 | /** |
||
183 | * Set mixin attribute |
||
184 | * |
||
185 | * @param string $id |
||
186 | * @return \AframeVR\Core\Entity |
||
187 | */ |
||
188 | public function mixin(string $id) |
||
193 | |||
194 | /** |
||
195 | * Load component for this entity or set it's attr |
||
196 | * |
||
197 | * @param string $component_name |
||
198 | * @param null|mixed $attr_data |
||
199 | * @throws \AframeVR\Core\Exceptions\BadComponentCallException |
||
200 | * @return object|null |
||
201 | 1 | */ |
|
202 | public function attr(string $component_name, $attr_data = null) |
||
220 | 81 | ||
221 | /** |
||
222 | 1 | * Handle entity components |
|
223 | * |
||
224 | * Since we might need to customize these to have |
||
225 | * custom components loaded as $this->methosd aswell therefore |
||
226 | 81 | * we have these placeholder magic methods here |
|
227 | * |
||
228 | * @param string $component_name |
||
229 | * @param array $args |
||
230 | */ |
||
231 | public function __call(string $component_name, array $args) |
||
235 | |||
236 | /** |
||
237 | * Create and add DOM element of the entity |
||
238 | * |
||
239 | 30 | * @param \DOMDocument $aframe_dom |
|
240 | * @return \DOMElement |
||
241 | 30 | */ |
|
242 | 30 | public function domElement(\DOMDocument &$aframe_dom): DOMElement |
|
261 | 13 | ||
262 | /** |
||
263 | 13 | * Append DOM attributes no set by components |
|
264 | * |
||
265 | * @param \DOMElement $a_entity |
||
266 | */ |
||
267 | private function appendAttributes(\DOMElement &$a_entity) |
||
275 | |||
276 | private function setAttribute(&$a_entity, $attr, $val) |
||
283 | |||
284 | 13 | /** |
|
285 | 13 | * Append childern to entities DOM element |
|
286 | * |
||
287 | 13 | * @param \DOMDocument $aframe_dom |
|
288 | * @param \DOMElement $a_entity |
||
289 | 13 | */ |
|
290 | private function appendChildren(\DOMDocument &$aframe_dom, \DOMElement &$a_entity) |
||
300 | |||
301 | /** |
||
302 | * Append childern to entities DOM element |
||
303 | 13 | * |
|
304 | * @param \DOMDocument $aframe_dom |
||
305 | 13 | * @param \DOMElement $a_entity |
|
306 | 2 | */ |
|
307 | 2 | private function appendAnimations(\DOMDocument &$aframe_dom, \DOMElement &$a_entity) |
|
315 | |||
316 | /** |
||
317 | * Add format comment |
||
318 | * |
||
319 | * @param \DOMDocument $aframe_dom |
||
320 | 13 | * @param \DOMElement $a_entity |
|
321 | * @param string $content |
||
322 | 13 | */ |
|
323 | 1 | private function addFormatComment(\DOMDocument &$aframe_dom, \DOMElement &$a_entity, string $content) |
|
330 | } |
||
331 |