1 | <?php |
||
30 | final class Mixin extends AssetsAbstract implements MixinInterface |
||
31 | { |
||
32 | |||
33 | /** |
||
34 | * DOM tag name of asset item |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $element_tag = 'a-mixin'; |
||
39 | |||
40 | /** |
||
41 | * Array of mocked components |
||
42 | * |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $components = array(); |
||
46 | |||
47 | /** |
||
48 | * Load component for this entity |
||
49 | * |
||
50 | * @param string $component_name |
||
51 | * @throws \AframeVR\Core\Exceptions\BadComponentCallException |
||
52 | * @return object|null |
||
53 | */ |
||
54 | 3 | public function attr(string $component_name, string $attr_data = null) |
|
55 | { |
||
56 | 3 | if(!is_null($attr_data)) { |
|
57 | 1 | $this->attrs[$component_name] = $attr_data; |
|
58 | 1 | return $this; |
|
59 | } |
||
60 | 2 | if (! array_key_exists($component_name, $this->components)) { |
|
61 | 2 | $component = sprintf('\AframeVR\Core\Components\%s\%sComponent', ucfirst($component_name), |
|
62 | ucfirst($component_name)); |
||
63 | 2 | if (class_exists($component)) { |
|
64 | 1 | $this->components[$component_name] = new $component(); |
|
65 | } else { |
||
66 | 1 | throw new BadComponentCallException($component_name); |
|
67 | } |
||
68 | } |
||
69 | |||
70 | 1 | return $this->components[$component_name] ?? null; |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * Handle entity components |
||
75 | * |
||
76 | * Since we might need to customize these to have |
||
77 | * custom components loaded as $this->methosd aswell therefore |
||
78 | * we have these placeholder magic methods here |
||
79 | * |
||
80 | * @param string $component_name |
||
81 | * @param array $args |
||
82 | */ |
||
83 | 1 | public function __call(string $component_name, array $args) |
|
87 | |||
88 | /** |
||
89 | * material.color |
||
90 | * |
||
91 | * @param string $color |
||
92 | * @return Mixin |
||
93 | */ |
||
94 | 1 | public function color(string $color = 'gray') |
|
101 | |||
102 | /** |
||
103 | * material.metalness |
||
104 | * |
||
105 | * @param int|float $metalness |
||
106 | * @return Mixin |
||
107 | */ |
||
108 | 1 | public function metalness(float $metalness = 0) |
|
115 | |||
116 | /** |
||
117 | * material.roughness |
||
118 | * |
||
119 | * @param float $roughness |
||
120 | * @return Mixin |
||
121 | */ |
||
122 | 1 | public function roughness(float $roughness = 0.5) |
|
129 | |||
130 | /** |
||
131 | * material.src |
||
132 | * |
||
133 | * @param null|string $src |
||
134 | * @return Mixin |
||
135 | */ |
||
136 | 1 | public function src(string $src = null) |
|
143 | |||
144 | /** |
||
145 | * material.shader |
||
146 | * |
||
147 | * @param string $shader |
||
148 | * @return Mixin |
||
149 | */ |
||
150 | 1 | public function shader($shader = 'standard') |
|
155 | |||
156 | /** |
||
157 | * material.opacity |
||
158 | * |
||
159 | * @param float $opacity |
||
160 | * @return Mixin |
||
161 | */ |
||
162 | 1 | public function opacity(float $opacity = 1.0) |
|
167 | |||
168 | /** |
||
169 | * material.transparent |
||
170 | * |
||
171 | * @param bool $transparent |
||
172 | * @return Mixin |
||
173 | */ |
||
174 | 1 | public function transparent(bool $transparent = false) |
|
179 | } |
||
180 |