1 | <?php |
||
31 | final class Mixin extends AssetsAbstract implements MixinInterface |
||
32 | { |
||
33 | |||
34 | /** |
||
35 | * DOM tag name of asset item |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $element_tag = 'a-mixin'; |
||
40 | |||
41 | /** |
||
42 | * Array of mocked components |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $components = array(); |
||
47 | |||
48 | /** |
||
49 | * Load component for this entity |
||
50 | * |
||
51 | * @param string $component_name |
||
52 | * @throws \AframeVR\Core\Exceptions\BadComponentCallException |
||
53 | * @return object|null |
||
54 | */ |
||
55 | 2 | public function component(string $component_name) |
|
56 | { |
||
57 | 2 | if (! array_key_exists($component_name, $this->components)) { |
|
58 | 2 | $component = sprintf('\AframeVR\Core\Components\%s\%sComponent', ucfirst($component_name), |
|
59 | ucfirst($component_name)); |
||
60 | 2 | if (class_exists($component)) { |
|
61 | 1 | $this->components[$component_name] = new $component(); |
|
62 | } else { |
||
63 | 1 | throw new BadComponentCallException($component_name); |
|
64 | } |
||
65 | } |
||
66 | |||
67 | 1 | return $this->components[$component_name] ?? null; |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * Handle entity components |
||
72 | * |
||
73 | * Since we might need to customize these to have |
||
74 | * custom components loaded as $this->methosd aswell therefore |
||
75 | * we have these placeholder magic methods here |
||
76 | * |
||
77 | * @param string $component_name |
||
78 | * @param array $args |
||
79 | */ |
||
80 | 1 | public function __call(string $component_name, array $args) |
|
81 | { |
||
82 | 1 | if (! method_exists($this, $component_name)) { |
|
83 | 1 | $this->{$component_name} = Closure::bind( |
|
84 | 1 | function () use ($component_name) { |
|
85 | 1 | return $this->component($component_name); |
|
86 | 1 | }, $this, get_class()); |
|
87 | } |
||
88 | |||
89 | 1 | return call_user_func($this->{$component_name}, $args); |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * material.color |
||
94 | * |
||
95 | * @param string $color |
||
96 | * @return Mixin |
||
97 | */ |
||
98 | 1 | public function color(string $color = 'gray') |
|
105 | |||
106 | /** |
||
107 | * material.metalness |
||
108 | * |
||
109 | * @param int|float $metalness |
||
110 | * @return Mixin |
||
111 | */ |
||
112 | 1 | public function metalness(float $metalness = 0) |
|
119 | |||
120 | /** |
||
121 | * material.roughness |
||
122 | * |
||
123 | * @param float $roughness |
||
124 | * @return Mixin |
||
125 | */ |
||
126 | 1 | public function roughness(float $roughness = 0.5) |
|
133 | |||
134 | /** |
||
135 | * material.src |
||
136 | * |
||
137 | * @param null|string $src |
||
138 | * @return Mixin |
||
139 | */ |
||
140 | 1 | public function src(string $src = null) |
|
147 | |||
148 | /** |
||
149 | * material.shader |
||
150 | * |
||
151 | * @param string $shader |
||
152 | * @return Mixin |
||
153 | */ |
||
154 | 1 | public function shader($shader = 'standard') |
|
159 | |||
160 | /** |
||
161 | * material.opacity |
||
162 | * |
||
163 | * @param float $opacity |
||
164 | * @return Mixin |
||
165 | */ |
||
166 | 1 | public function opacity(float $opacity = 1.0) |
|
171 | |||
172 | /** |
||
173 | * material.transparent |
||
174 | * |
||
175 | * @param bool $transparent |
||
176 | * @return Mixin |
||
177 | */ |
||
178 | 1 | public function transparent(bool $transparent = false) |
|
183 | } |
||
184 |