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 | 82 | public function __construct(string $id = '0') |
|
91 | |||
92 | /** |
||
93 | * Reset primitive default attributtes |
||
94 | * |
||
95 | * {@inheritdoc} |
||
96 | * |
||
97 | * @return void |
||
98 | */ |
||
99 | 78 | public function reset() |
|
106 | |||
107 | /** |
||
108 | * Child entity / primitive |
||
109 | * |
||
110 | * @return \AframeVR\Core\Helpers\EntityChildrenFactory |
||
111 | */ |
||
112 | 7 | public function el(): EntityChildrenFactory |
|
113 | { |
||
114 | 7 | return $this->childrenFactory ?? $this->childrenFactory = new EntityChildrenFactory(); |
|
115 | } |
||
116 | |||
117 | /** |
||
118 | * 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 | * @return \AframeVR\Interfaces\EntityInterface |
||
126 | */ |
||
127 | 4 | 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 | * @param int|float $roll |
||
141 | * @param int|float $pitch |
||
142 | * @param int|float $yaw |
||
143 | * @return \AframeVR\Interfaces\EntityInterface |
||
144 | */ |
||
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 | * @param int|float $scale_x |
||
159 | * @param int|float $scale_y |
||
160 | * @param int|float $scale_z |
||
161 | * @return \AframeVR\Interfaces\EntityInterface |
||
162 | */ |
||
163 | 8 | 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 | */ |
||
177 | 2 | public function animation($name = '0'): AnimationInterface |
|
181 | |||
182 | /** |
||
183 | * Set mixin attribute |
||
184 | * |
||
185 | * @param string $id |
||
186 | * @return \AframeVR\Core\Entity |
||
187 | */ |
||
188 | 1 | 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 | */ |
||
202 | 82 | public function attr(string $component_name, $attr_data = null) |
|
220 | |||
221 | /** |
||
222 | * Handle entity components |
||
223 | * |
||
224 | * Since we might need to customize these to have |
||
225 | * custom components loaded as $this->methosd aswell therefore |
||
226 | * we have these placeholder magic methods here |
||
227 | * |
||
228 | * @param string $component_name |
||
229 | * @param array $args |
||
230 | */ |
||
231 | 30 | public function __call(string $component_name, array $args) |
|
235 | |||
236 | /** |
||
237 | * Create and add DOM element of the entity |
||
238 | * |
||
239 | * @param \DOMDocument $aframe_dom |
||
240 | * @return \DOMElement |
||
241 | */ |
||
242 | 14 | public function domElement(\DOMDocument &$aframe_dom): DOMElement |
|
261 | |||
262 | /** |
||
263 | * Append DOM attributes no set by components |
||
264 | * |
||
265 | * @param \DOMElement $a_entity |
||
266 | */ |
||
267 | 14 | private function appendAttributes(\DOMElement &$a_entity) |
|
268 | { |
||
269 | 14 | foreach ($this->attrs as $attr => $val) { |
|
270 | 14 | if(is_bool($val)) |
|
271 | 1 | $val = $val ? '' : 'false'; |
|
272 | 14 | $this->setAttribute($a_entity, $attr, $val); |
|
273 | } |
||
274 | 14 | } |
|
275 | |||
276 | 14 | private function setAttribute(&$a_entity, $attr, $val) |
|
283 | |||
284 | /** |
||
285 | * Append childern to entities DOM element |
||
286 | * |
||
287 | * @param \DOMDocument $aframe_dom |
||
288 | * @param \DOMElement $a_entity |
||
289 | */ |
||
290 | 14 | private function appendChildren(\DOMDocument &$aframe_dom, \DOMElement &$a_entity) |
|
300 | |||
301 | /** |
||
302 | * Append childern to entities DOM element |
||
303 | * |
||
304 | * @param \DOMDocument $aframe_dom |
||
305 | * @param \DOMElement $a_entity |
||
306 | */ |
||
307 | 14 | private function appendAnimations(\DOMDocument &$aframe_dom, \DOMElement &$a_entity) |
|
315 | |||
316 | /** |
||
317 | * Add format comment |
||
318 | * |
||
319 | * @param \DOMDocument $aframe_dom |
||
320 | * @param \DOMElement $a_entity |
||
321 | * @param string $content |
||
322 | */ |
||
323 | 4 | private function addFormatComment(\DOMDocument &$aframe_dom, \DOMElement &$a_entity, string $content) |
|
330 | } |
||
331 |