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 | 98 | */ |
|
87 | public function __construct(string $keyword, Config $config) |
||
88 | 98 | { |
|
89 | 98 | $this->keyword = $keyword; |
|
90 | $this->aframeDomObj = new AframeDOMDocument($config); |
||
91 | 98 | $this->childrenFactory = new EntityChildrenFactory(); |
|
92 | 98 | /* Initialize assests manager */ |
|
93 | $this->asset(); |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Aframe Document Object Model |
||
98 | * |
||
99 | * @api |
||
100 | * |
||
101 | 2 | * @return \AframeVR\Core\DOM\AframeDOMDocument |
|
102 | */ |
||
103 | 2 | public function dom() |
|
104 | { |
||
105 | return $this->aframeDomObj; |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * Assets |
||
110 | * |
||
111 | * @api |
||
112 | * |
||
113 | * @return \AframeVR\Core\Assets |
||
114 | 51 | */ |
|
115 | public function asset(): Assets |
||
116 | 51 | { |
|
117 | return $this->assets ?? $this->assets = new Assets(); |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * Child entity / primitive |
||
122 | * |
||
123 | * @return \AframeVR\Core\Helpers\EntityChildrenFactory |
||
124 | */ |
||
125 | public function child(): EntityChildrenFactory |
||
129 | |||
130 | /** |
||
131 | * Render the A-Frame scene and return the HTML |
||
132 | * |
||
133 | * @api |
||
134 | * |
||
135 | * @param bool $only_scene |
||
136 | * @return string |
||
137 | */ |
||
138 | public function save($only_scene = false, string $file = null): string |
||
148 | |||
149 | /** |
||
150 | * Render the A-Frame scene and passthru HTML |
||
151 | * |
||
152 | * @api |
||
153 | * |
||
154 | * @param bool $only_scene |
||
155 | * @return void |
||
156 | */ |
||
157 | public function render($only_scene = false) |
||
158 | 1 | { |
|
159 | print $this->save($only_scene); |
||
160 | 1 | } |
|
161 | 1 | ||
162 | /** |
||
163 | * Alias of AframeDOMDocument::setTitle(string) |
||
164 | * |
||
165 | * Set <title> tag |
||
166 | * $this->dom()->setTitle(string); |
||
167 | * |
||
168 | * @api |
||
169 | * |
||
170 | * @param string $title |
||
171 | */ |
||
172 | public function title(string $title) |
||
173 | 1 | { |
|
174 | $this->dom()->setTitle($title); |
||
175 | 1 | } |
|
176 | 1 | ||
177 | /** |
||
178 | * Alias of AframeDOMDocument::setDescription(string) |
||
179 | * |
||
180 | * Set <meta name="description"> tag |
||
181 | * $this->dom()->setDescription(string); |
||
182 | * |
||
183 | * @api |
||
184 | * |
||
185 | * @param string $description |
||
186 | */ |
||
187 | public function description(string $description) |
||
188 | 1 | { |
|
189 | $this->dom()->setDescription($description); |
||
190 | 1 | } |
|
191 | 1 | ||
192 | /** |
||
193 | * Get scenes keyword |
||
194 | * |
||
195 | * @return string |
||
196 | */ |
||
197 | public function getKeyword() |
||
201 | |||
202 | /** |
||
203 | * Load component for this entity |
||
204 | * |
||
205 | * @param string $component_name |
||
206 | * @throws \AframeVR\Core\Exceptions\BadComponentCallException |
||
207 | * @return object|null |
||
208 | */ |
||
209 | public function component(string $component_name) |
||
223 | |||
224 | /** |
||
225 | * Map calls to scene entities and components |
||
226 | * |
||
227 | * Since we might need to customize these to have |
||
228 | * custom components loaded as $this->methosd aswell therefore |
||
229 | * we have these placeholder magic methods here |
||
230 | * |
||
231 | * @param string $method |
||
232 | * @param array $args |
||
233 | 28 | * @throws BadShaderCallException |
|
234 | * @return Entity|\AframeVR\Interfaces\ComponentInterface |
||
|
|||
235 | 28 | */ |
|
236 | 28 | public function __call(string $method, array $args) |
|
247 | |||
248 | /** |
||
249 | * Add everyting to DOM |
||
250 | * |
||
251 | * @return void |
||
252 | */ |
||
253 | protected function prepare() |
||
269 | } |
||
270 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.