1
|
|
|
<?php |
2
|
|
|
/** @formatter:off |
3
|
|
|
* ****************************************************************** |
4
|
|
|
* Created by Marko Kungla on Jul 5, 2016 - 3:05:38 AM |
5
|
|
|
* Contact [email protected] |
6
|
|
|
* @copyright 2016 Marko Kungla - https://github.com/mkungla |
7
|
|
|
* @license The MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* @category AframeVR |
10
|
|
|
* @package aframe-php |
11
|
|
|
* |
12
|
|
|
* Lang PHP (php version >= 7) |
13
|
|
|
* Encoding UTF-8 |
14
|
|
|
* File EntityChildrenFactory.php |
15
|
|
|
* Code format PSR-2 and 12 |
16
|
|
|
* @link https://github.com/mkungla/aframe-php |
17
|
|
|
* @issues https://github.com/mkungla/aframe-php/issues |
18
|
|
|
* ******************************************************************** |
19
|
|
|
* Contributors: |
20
|
|
|
* @author Marko Kungla <[email protected]> |
21
|
|
|
* ******************************************************************** |
22
|
|
|
* Comments: |
23
|
|
|
* @formatter:on */ |
24
|
|
|
namespace AframeVR\Core\Helpers; |
25
|
|
|
|
26
|
|
|
use \AframeVR\Core\Entity; |
27
|
|
|
use \AframeVR\Core\Exceptions\BadPrimitiveCallException; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* |
31
|
|
|
* @method \AframeVR\Extras\Primitives\Box box(string $id = 'untitled') |
32
|
|
|
* @method \AframeVR\Extras\Primitives\Camera camera(string $id = 'untitled') |
33
|
|
|
* @method \AframeVR\Extras\Primitives\Circle circle(string $id = 'untitled') |
34
|
|
|
* @method \AframeVR\Extras\Primitives\Colladamodel colladamodel(string $id = 'untitled') |
35
|
|
|
* @method \AframeVR\Extras\Primitives\Cone cone(string $id = 'untitled') |
36
|
|
|
* @method \AframeVR\Extras\Primitives\Cursor cursor(string $id = 'untitled') |
37
|
|
|
* @method \AframeVR\Extras\Primitives\Curvedimage curvedimage(string $id = 'untitled') |
38
|
|
|
* @method \AframeVR\Extras\Primitives\Cylinder cylinder(string $id = 'untitled') |
39
|
|
|
* @method \AframeVR\Extras\Primitives\Image image(string $id = 'untitled') |
40
|
|
|
* @method \AframeVR\Extras\Primitives\Light light(string $id = 'untitled') |
41
|
|
|
* @method \AframeVR\Extras\Primitives\Objmodel objmodel(string $id = 'untitled') |
42
|
|
|
* @method \AframeVR\Extras\Primitives\Plane plane(string $id = 'untitled') |
43
|
|
|
* @method \AframeVR\Extras\Primitives\Ring ring(string $id = 'untitled') |
44
|
|
|
* @method \AframeVR\Extras\Primitives\Sky sky(string $id = 'untitled') |
45
|
|
|
* @method \AframeVR\Extras\Primitives\Sphere sphere(string $id = 'untitled') |
46
|
|
|
* @method \AframeVR\Extras\Primitives\Torus torus(string $id = 'untitled') |
47
|
|
|
* @method \AframeVR\Extras\Primitives\Video video(string $id = 'untitled') |
48
|
|
|
* @method \AframeVR\Extras\Primitives\Videosphere videosphere(string $id = 'untitled') |
49
|
|
|
*/ |
50
|
|
|
class EntityChildrenFactory |
51
|
|
|
{ |
52
|
|
|
/** |
53
|
|
|
* Child entities |
54
|
|
|
* |
55
|
|
|
* @var array |
56
|
|
|
*/ |
57
|
|
|
protected $childrens = array(); |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Entity |
61
|
|
|
* |
62
|
|
|
* @api |
63
|
|
|
* |
64
|
|
|
* @param string $id |
65
|
|
|
* @return \AframeVR\Core\Entity |
66
|
|
|
*/ |
67
|
5 |
|
public function entity(string $id = 'untitled'): Entity |
68
|
|
|
{ |
69
|
5 |
|
return $this->childrens[$id] ?? $this->childrens[$id] = new Entity($id); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Call |
74
|
|
|
* |
75
|
|
|
* @param string $method |
76
|
|
|
* @param array $args |
77
|
|
|
* @throws BadShaderCallException |
78
|
|
|
* @return Entity|\AframeVR\Interfaces\ComponentInterface |
79
|
|
|
*/ |
80
|
4 |
|
public function __call(string $method, array $args) |
81
|
|
|
{ |
82
|
4 |
|
$id = $args[0] ?? 'untitled'; |
83
|
|
|
|
84
|
4 |
|
$primitive = sprintf('\AframeVR\Extras\Primitives\%s', ucfirst($method)); |
85
|
|
|
|
86
|
4 |
|
if (class_exists($primitive)) { |
87
|
3 |
|
return $this->childrens[$id] ?? $this->childrens[$id] = new $primitive($id); |
88
|
|
|
} else { |
89
|
1 |
|
throw new BadPrimitiveCallException($method); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
2 |
|
public function getChildern() |
94
|
|
|
{ |
95
|
2 |
|
return $this->childrens; |
96
|
|
|
} |
97
|
|
|
} |