1 | <?php |
||
34 | final class Scene |
||
35 | { |
||
36 | /* All scenes can use primitives */ |
||
37 | use Primitives; |
||
38 | |||
39 | /** |
||
40 | * Name with what you can retrieve this scene while working with multiple scenes |
||
41 | * |
||
42 | * @var string $name |
||
43 | */ |
||
44 | private $keyword; |
||
45 | |||
46 | /** |
||
47 | * Is scene prepared for rendering |
||
48 | * |
||
49 | * @var bool |
||
50 | */ |
||
51 | private $prepared; |
||
52 | |||
53 | /** |
||
54 | * Assets |
||
55 | * |
||
56 | * @var \AframeVR\Core\Assets |
||
57 | */ |
||
58 | protected $assets; |
||
59 | |||
60 | /** |
||
61 | * Aframe Document Object Model |
||
62 | * |
||
63 | * @var \AframeVR\Core\DOM\AframeDOMDocument |
||
64 | */ |
||
65 | protected $aframeDomObj; |
||
66 | |||
67 | /** |
||
68 | * Scene components |
||
69 | * |
||
70 | * @var array $components |
||
71 | */ |
||
72 | protected $components = array(); |
||
73 | |||
74 | /** |
||
75 | * Children Factory |
||
76 | * |
||
77 | * @var \AframeVR\Core\Helpers\EntityChildrenFactory |
||
78 | */ |
||
79 | protected $childrenFactory; |
||
80 | |||
81 | /** |
||
82 | * Scene constructor |
||
83 | * |
||
84 | * @param string $keyword |
||
85 | * @param Config $config |
||
86 | */ |
||
87 | 98 | public function __construct(string $keyword, Config $config) |
|
88 | { |
||
89 | 98 | $this->keyword = $keyword; |
|
90 | 98 | $this->aframeDomObj = new AframeDOMDocument($config); |
|
91 | 98 | $this->childrenFactory = new EntityChildrenFactory(); |
|
92 | /* Initialize assests manager */ |
||
93 | 98 | $this->asset($config); |
|
94 | 98 | } |
|
95 | |||
96 | /** |
||
97 | * Aframe Document Object Model |
||
98 | * |
||
99 | * @api |
||
100 | * |
||
101 | * @return \AframeVR\Core\DOM\AframeDOMDocument |
||
102 | */ |
||
103 | 2 | public function dom() |
|
104 | { |
||
105 | 2 | return $this->aframeDomObj; |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * Assets |
||
110 | * |
||
111 | * @api |
||
112 | * |
||
113 | * @param null|Config $config |
||
114 | * @return \AframeVR\Core\Assets |
||
115 | */ |
||
116 | 98 | public function asset(Config $config = null): Assets |
|
117 | { |
||
118 | 98 | return $this->assets ?? $this->assets = new Assets($config); |
|
|
|||
119 | } |
||
120 | |||
121 | /** |
||
122 | * Child entity / primitive |
||
123 | * |
||
124 | * @return \AframeVR\Core\Helpers\EntityChildrenFactory |
||
125 | */ |
||
126 | 77 | public function child(): EntityChildrenFactory |
|
127 | { |
||
128 | 77 | return $this->childrenFactory; |
|
129 | } |
||
130 | |||
131 | /** |
||
132 | * Render the A-Frame scene and return the HTML |
||
133 | * |
||
134 | * @api |
||
135 | * |
||
136 | * @param bool $only_scene |
||
137 | * @return string |
||
138 | */ |
||
139 | 19 | public function save($only_scene = false, string $file = null): string |
|
149 | |||
150 | /** |
||
151 | * Render the A-Frame scene and passthru HTML |
||
152 | * |
||
153 | * @api |
||
154 | * |
||
155 | * @param bool $only_scene |
||
156 | * @return void |
||
157 | */ |
||
158 | 1 | public function render($only_scene = false) |
|
162 | |||
163 | /** |
||
164 | * Alias of AframeDOMDocument::setTitle(string) |
||
165 | * |
||
166 | * Set <title> tag |
||
167 | * $this->dom()->setTitle(string); |
||
168 | * |
||
169 | * @api |
||
170 | * |
||
171 | * @param string $title |
||
172 | */ |
||
173 | 1 | public function title(string $title) |
|
177 | |||
178 | /** |
||
179 | * Alias of AframeDOMDocument::setDescription(string) |
||
180 | * |
||
181 | * Set <meta name="description"> tag |
||
182 | * $this->dom()->setDescription(string); |
||
183 | * |
||
184 | * @api |
||
185 | * |
||
186 | * @param string $description |
||
187 | */ |
||
188 | 1 | public function description(string $description) |
|
192 | |||
193 | /** |
||
194 | * Get scenes keyword |
||
195 | * |
||
196 | * @return string |
||
197 | */ |
||
198 | 1 | public function getKeyword() |
|
202 | |||
203 | /** |
||
204 | * Load component for this scene or set it's attr |
||
205 | * |
||
206 | * @param string $component_name |
||
207 | * @param null|string $attr_data |
||
208 | * @throws \AframeVR\Core\Exceptions\BadComponentCallException |
||
209 | * @return object|null |
||
210 | */ |
||
211 | 2 | public function attr(string $component_name, string $attr_data = null) |
|
229 | |||
230 | /** |
||
231 | * Map calls to scene entities and components |
||
232 | * |
||
233 | * Since we might need to customize these to have |
||
234 | * custom components loaded as $this->methosd aswell therefore |
||
235 | * we have these placeholder magic methods here |
||
236 | * |
||
237 | * @param string $method |
||
238 | * @param array $args |
||
239 | * @throws BadShaderCallException |
||
240 | * @return Entity|\AframeVR\Interfaces\ComponentInterface |
||
241 | */ |
||
242 | 79 | public function __call(string $method, array $args) |
|
253 | |||
254 | /** |
||
255 | * Add everyting to DOM |
||
256 | * |
||
257 | * @return void |
||
258 | */ |
||
259 | 19 | protected function prepare() |
|
275 | } |
||
276 |
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.
We recommend to add an additional type check (or disallow null for the parameter):