@playcanvas/web-components 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/pwc.cjs +1 -1
- package/dist/pwc.cjs.map +1 -1
- package/dist/pwc.js +1 -1
- package/dist/pwc.js.map +1 -1
- package/dist/pwc.min.js +1 -1
- package/dist/pwc.min.js.map +1 -1
- package/dist/pwc.mjs +1 -1
- package/dist/pwc.mjs.map +1 -1
- package/package.json +3 -2
- package/src/app.ts +138 -0
- package/src/asset.ts +99 -0
- package/src/components/camera-component.ts +196 -0
- package/src/components/collision-component.ts +148 -0
- package/src/components/component.ts +106 -0
- package/src/components/element-component.ts +252 -0
- package/src/components/gsplat-component.ts +66 -0
- package/src/components/light-component.ts +313 -0
- package/src/components/listener-component.ts +26 -0
- package/src/components/render-component.ts +117 -0
- package/src/components/rigidbody-component.ts +226 -0
- package/src/components/script-component.ts +26 -0
- package/src/components/script.ts +130 -0
- package/src/components/sound-component.ts +117 -0
- package/src/components/sound-slot.ts +289 -0
- package/src/entity.ts +230 -0
- package/src/index.ts +46 -0
- package/src/model.ts +80 -0
- package/src/module.ts +35 -0
- package/src/scene.ts +188 -0
- package/src/sky.ts +150 -0
- package/src/utils.ts +50 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { RenderComponent } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
import { ComponentElement } from './component';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Represents a render component in the PlayCanvas engine.
|
|
7
|
+
*
|
|
8
|
+
* @category Components
|
|
9
|
+
*/
|
|
10
|
+
class RenderComponentElement extends ComponentElement {
|
|
11
|
+
private _type: 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere' = 'asset';
|
|
12
|
+
|
|
13
|
+
private _castShadows = true;
|
|
14
|
+
|
|
15
|
+
private _receiveShadows = true;
|
|
16
|
+
|
|
17
|
+
constructor() {
|
|
18
|
+
super('render');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getInitialComponentData() {
|
|
22
|
+
return {
|
|
23
|
+
type: this._type,
|
|
24
|
+
castShadows: this._castShadows,
|
|
25
|
+
receiveShadows: this._receiveShadows
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Gets the render component.
|
|
31
|
+
* @returns The render component.
|
|
32
|
+
*/
|
|
33
|
+
get component(): RenderComponent | null {
|
|
34
|
+
return super.component as RenderComponent | null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Sets the type of the render component.
|
|
39
|
+
* @param value - The type.
|
|
40
|
+
*/
|
|
41
|
+
set type(value: 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere') {
|
|
42
|
+
this._type = value;
|
|
43
|
+
if (this.component) {
|
|
44
|
+
this.component.type = value;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Gets the type of the render component.
|
|
50
|
+
* @returns The type.
|
|
51
|
+
*/
|
|
52
|
+
get type(): 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere' {
|
|
53
|
+
return this._type;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Sets the cast shadows flag of the render component.
|
|
58
|
+
* @param value - The cast shadows flag.
|
|
59
|
+
*/
|
|
60
|
+
set castShadows(value: boolean) {
|
|
61
|
+
this._castShadows = value;
|
|
62
|
+
if (this.component) {
|
|
63
|
+
this.component.castShadows = value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Gets the cast shadows flag of the render component.
|
|
69
|
+
* @returns The cast shadows flag.
|
|
70
|
+
*/
|
|
71
|
+
get castShadows(): boolean {
|
|
72
|
+
return this._castShadows;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Sets the receive shadows flag of the render component.
|
|
77
|
+
* @param value - The receive shadows flag.
|
|
78
|
+
*/
|
|
79
|
+
set receiveShadows(value: boolean) {
|
|
80
|
+
this._receiveShadows = value;
|
|
81
|
+
if (this.component) {
|
|
82
|
+
this.component.receiveShadows = value;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Gets the receive shadows flag of the render component.
|
|
88
|
+
* @returns The receive shadows flag.
|
|
89
|
+
*/
|
|
90
|
+
get receiveShadows(): boolean {
|
|
91
|
+
return this._receiveShadows;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static get observedAttributes() {
|
|
95
|
+
return [...super.observedAttributes, 'cast-shadows', 'receive-shadows', 'type'];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
99
|
+
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
100
|
+
|
|
101
|
+
switch (name) {
|
|
102
|
+
case 'type':
|
|
103
|
+
this.type = newValue as 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere';
|
|
104
|
+
break;
|
|
105
|
+
case 'cast-shadows':
|
|
106
|
+
this.castShadows = newValue !== 'false';
|
|
107
|
+
break;
|
|
108
|
+
case 'receive-shadows':
|
|
109
|
+
this.receiveShadows = newValue !== 'false';
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
customElements.define('pc-render', RenderComponentElement);
|
|
116
|
+
|
|
117
|
+
export { RenderComponentElement };
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { RigidBodyComponent, Vec3 } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
import { ComponentElement } from './component';
|
|
4
|
+
import { parseVec3 } from '../utils';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents a rigidbody component in the PlayCanvas engine.
|
|
8
|
+
*
|
|
9
|
+
* @category Components
|
|
10
|
+
*/
|
|
11
|
+
class RigidBodyComponentElement extends ComponentElement {
|
|
12
|
+
/**
|
|
13
|
+
* The angular damping of the rigidbody.
|
|
14
|
+
*/
|
|
15
|
+
private _angularDamping: number = 0;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The angular factor of the rigidbody.
|
|
19
|
+
*/
|
|
20
|
+
private _angularFactor: Vec3 = new Vec3(1, 1, 1);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The friction of the rigidbody.
|
|
24
|
+
*/
|
|
25
|
+
private _friction: number = 0.5;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The linear damping of the rigidbody.
|
|
29
|
+
*/
|
|
30
|
+
private _linearDamping: number = 0;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The linear factor of the rigidbody.
|
|
34
|
+
*/
|
|
35
|
+
private _linearFactor: Vec3 = new Vec3(1, 1, 1);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The mass of the rigidbody.
|
|
39
|
+
*/
|
|
40
|
+
private _mass: number = 1;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The restitution of the rigidbody.
|
|
44
|
+
*/
|
|
45
|
+
private _restitution: number = 0;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The rolling friction of the rigidbody.
|
|
49
|
+
*/
|
|
50
|
+
private _rollingFriction: number = 0;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The type of the rigidbody.
|
|
54
|
+
*/
|
|
55
|
+
private _type: string = 'static';
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new RigidBodyComponentElement.
|
|
59
|
+
*/
|
|
60
|
+
constructor() {
|
|
61
|
+
super('rigidbody');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getInitialComponentData() {
|
|
65
|
+
return {
|
|
66
|
+
angularDamping: this._angularDamping,
|
|
67
|
+
angularFactor: this._angularFactor,
|
|
68
|
+
friction: this._friction,
|
|
69
|
+
linearDamping: this._linearDamping,
|
|
70
|
+
linearFactor: this._linearFactor,
|
|
71
|
+
mass: this._mass,
|
|
72
|
+
restitution: this._restitution,
|
|
73
|
+
rollingFriction: this._rollingFriction,
|
|
74
|
+
type: this._type
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Gets the collision component.
|
|
80
|
+
* @returns The collision component.
|
|
81
|
+
*/
|
|
82
|
+
get component(): RigidBodyComponent | null {
|
|
83
|
+
return super.component as RigidBodyComponent | null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
set angularDamping(value: number) {
|
|
87
|
+
this._angularDamping = value;
|
|
88
|
+
if (this.component) {
|
|
89
|
+
this.component.angularDamping = value;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get angularDamping() {
|
|
94
|
+
return this._angularDamping;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
set angularFactor(value: Vec3) {
|
|
98
|
+
this._angularFactor = value;
|
|
99
|
+
if (this.component) {
|
|
100
|
+
this.component.angularFactor = value;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
get angularFactor() {
|
|
105
|
+
return this._angularFactor;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
set friction(value: number) {
|
|
109
|
+
this._friction = value;
|
|
110
|
+
if (this.component) {
|
|
111
|
+
this.component.friction = value;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
get friction() {
|
|
116
|
+
return this._friction;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
set linearDamping(value: number) {
|
|
120
|
+
this._linearDamping = value;
|
|
121
|
+
if (this.component) {
|
|
122
|
+
this.component.linearDamping = value;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
get linearDamping() {
|
|
127
|
+
return this._linearDamping;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
set linearFactor(value: Vec3) {
|
|
131
|
+
this._linearFactor = value;
|
|
132
|
+
if (this.component) {
|
|
133
|
+
this.component.linearFactor = value;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
get linearFactor() {
|
|
138
|
+
return this._linearFactor;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
set mass(value: number) {
|
|
142
|
+
this._mass = value;
|
|
143
|
+
if (this.component) {
|
|
144
|
+
this.component.mass = value;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
get mass() {
|
|
149
|
+
return this._mass;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
set restitution(value: number) {
|
|
153
|
+
this._restitution = value;
|
|
154
|
+
if (this.component) {
|
|
155
|
+
this.component.restitution = value;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
get restitution() {
|
|
160
|
+
return this._restitution;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
set rollingFriction(value: number) {
|
|
164
|
+
this._rollingFriction = value;
|
|
165
|
+
if (this.component) {
|
|
166
|
+
this.component.rollingFriction = value;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
get rollingFriction() {
|
|
171
|
+
return this._rollingFriction;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
set type(value: string) {
|
|
175
|
+
this._type = value;
|
|
176
|
+
if (this.component) {
|
|
177
|
+
this.component.type = value;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
get type() {
|
|
182
|
+
return this._type;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
static get observedAttributes() {
|
|
186
|
+
return [...super.observedAttributes, 'angular-damping', 'angular-factor', 'friction', 'linear-damping', 'linear-factor', 'mass', 'restitution', 'rolling-friction', 'type'];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
190
|
+
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
191
|
+
|
|
192
|
+
switch (name) {
|
|
193
|
+
case 'angular-damping':
|
|
194
|
+
this.angularDamping = parseFloat(newValue);
|
|
195
|
+
break;
|
|
196
|
+
case 'angular-factor':
|
|
197
|
+
this.angularFactor = parseVec3(newValue);
|
|
198
|
+
break;
|
|
199
|
+
case 'friction':
|
|
200
|
+
this.friction = parseFloat(newValue);
|
|
201
|
+
break;
|
|
202
|
+
case 'linear-damping':
|
|
203
|
+
this.linearDamping = parseFloat(newValue);
|
|
204
|
+
break;
|
|
205
|
+
case 'linear-factor':
|
|
206
|
+
this.linearFactor = parseVec3(newValue);
|
|
207
|
+
break;
|
|
208
|
+
case 'mass':
|
|
209
|
+
this.mass = parseFloat(newValue);
|
|
210
|
+
break;
|
|
211
|
+
case 'restitution':
|
|
212
|
+
this.restitution = parseFloat(newValue);
|
|
213
|
+
break;
|
|
214
|
+
case 'rolling-friction':
|
|
215
|
+
this.rollingFriction = parseFloat(newValue);
|
|
216
|
+
break;
|
|
217
|
+
case 'type':
|
|
218
|
+
this.type = newValue;
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
customElements.define('pc-rigidbody', RigidBodyComponentElement);
|
|
225
|
+
|
|
226
|
+
export { RigidBodyComponentElement };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ScriptComponent } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
import { ComponentElement } from './component';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Represents a script component in the PlayCanvas engine.
|
|
7
|
+
*
|
|
8
|
+
* @category Components
|
|
9
|
+
*/
|
|
10
|
+
class ScriptComponentElement extends ComponentElement {
|
|
11
|
+
constructor() {
|
|
12
|
+
super('script');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Gets the script component.
|
|
17
|
+
* @returns The script component.
|
|
18
|
+
*/
|
|
19
|
+
get component(): ScriptComponent | null {
|
|
20
|
+
return super.component as ScriptComponent | null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
customElements.define('pc-scripts', ScriptComponentElement);
|
|
25
|
+
|
|
26
|
+
export { ScriptComponentElement };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { ScriptType } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
import { AppElement } from '../app';
|
|
4
|
+
import { ScriptComponentElement } from './script-component';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents a script in the PlayCanvas engine.
|
|
8
|
+
*/
|
|
9
|
+
class ScriptElement extends HTMLElement {
|
|
10
|
+
private _attributes: Record<string, any> = {};
|
|
11
|
+
|
|
12
|
+
private _enabled: boolean = true;
|
|
13
|
+
|
|
14
|
+
private _name: string = '';
|
|
15
|
+
|
|
16
|
+
private _script: ScriptType | null = null;
|
|
17
|
+
|
|
18
|
+
async connectedCallback() {
|
|
19
|
+
const appElement = this.closest('pc-app') as AppElement | null;
|
|
20
|
+
if (!appElement) {
|
|
21
|
+
console.error(`${this.tagName.toLowerCase()} should be a descendant of pc-app`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
await appElement.getApplication();
|
|
26
|
+
|
|
27
|
+
const scriptAttributes = this.getAttribute('attributes');
|
|
28
|
+
if (scriptAttributes) {
|
|
29
|
+
try {
|
|
30
|
+
this._attributes = JSON.parse(scriptAttributes);
|
|
31
|
+
} catch (e) {
|
|
32
|
+
console.error('Failed to parse script attributes:', e);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// When the script is created, initialize it with the necessary attributes
|
|
37
|
+
this.scriptsElement?.component!.on(`create:${this._name}`, (scriptInstance) => {
|
|
38
|
+
Object.assign(scriptInstance, this._attributes);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
this._script = this.scriptsElement?.component!.create(this._name, { preloading: false }) ?? null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
disconnectedCallback() {
|
|
45
|
+
this.scriptsElement?.component!.destroy(this._name);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
refreshAttributes() {
|
|
49
|
+
if (this._script) {
|
|
50
|
+
Object.entries(this._attributes).forEach(([name, value]) => {
|
|
51
|
+
if (this._script && name in this._script) {
|
|
52
|
+
(this._script as any)[name] = value;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
protected get scriptsElement(): ScriptComponentElement | null {
|
|
59
|
+
const scriptsElement = this.parentElement as ScriptComponentElement;
|
|
60
|
+
|
|
61
|
+
if (!(scriptsElement instanceof ScriptComponentElement)) {
|
|
62
|
+
console.warn('pc-script must be a direct child of a pc-scripts element');
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return scriptsElement;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
set scriptAttributes(value: string) {
|
|
70
|
+
this._attributes = JSON.parse(value);
|
|
71
|
+
this.refreshAttributes();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
get scriptAttributes() {
|
|
75
|
+
return JSON.stringify(this._attributes);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
set enabled(value: boolean) {
|
|
79
|
+
this._enabled = value;
|
|
80
|
+
if (this._script) {
|
|
81
|
+
this._script.enabled = value;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Gets the enabled state of the script.
|
|
87
|
+
* @returns The enabled state of the script.
|
|
88
|
+
*/
|
|
89
|
+
get enabled() {
|
|
90
|
+
return this._enabled;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Sets the name of the script to create.
|
|
95
|
+
* @param value - The name.
|
|
96
|
+
*/
|
|
97
|
+
set name(value: string) {
|
|
98
|
+
this._name = value;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Gets the name of the script.
|
|
103
|
+
* @returns The name.
|
|
104
|
+
*/
|
|
105
|
+
get name() {
|
|
106
|
+
return this._name;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static get observedAttributes() {
|
|
110
|
+
return ['attributes', 'enabled', 'name'];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
114
|
+
switch (name) {
|
|
115
|
+
case 'attributes':
|
|
116
|
+
this.scriptAttributes = newValue;
|
|
117
|
+
break;
|
|
118
|
+
case 'enabled':
|
|
119
|
+
this.enabled = newValue !== 'false';
|
|
120
|
+
break;
|
|
121
|
+
case 'name':
|
|
122
|
+
this.name = newValue;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
customElements.define('pc-script', ScriptElement);
|
|
129
|
+
|
|
130
|
+
export { ScriptElement };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { SoundComponent } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
import { ComponentElement } from './component';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Represents a sound component in the PlayCanvas engine.
|
|
7
|
+
*
|
|
8
|
+
* @category Components
|
|
9
|
+
*/
|
|
10
|
+
class SoundComponentElement extends ComponentElement {
|
|
11
|
+
private _pitch: number = 1;
|
|
12
|
+
|
|
13
|
+
private _positional: boolean = false;
|
|
14
|
+
|
|
15
|
+
private _volume: number = 1;
|
|
16
|
+
|
|
17
|
+
constructor() {
|
|
18
|
+
super('sound');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getInitialComponentData() {
|
|
22
|
+
return {
|
|
23
|
+
pitch: this._pitch,
|
|
24
|
+
positional: this._positional,
|
|
25
|
+
volume: this._volume
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Gets the sound component.
|
|
31
|
+
* @returns The sound component.
|
|
32
|
+
*/
|
|
33
|
+
get component(): SoundComponent | null {
|
|
34
|
+
return super.component as SoundComponent | null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Sets the pitch of the sound.
|
|
39
|
+
* @param value - The pitch.
|
|
40
|
+
*/
|
|
41
|
+
set pitch(value: number) {
|
|
42
|
+
this._pitch = value;
|
|
43
|
+
if (this.component) {
|
|
44
|
+
this.component.pitch = value;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Gets the pitch of the sound.
|
|
50
|
+
* @returns The pitch.
|
|
51
|
+
*/
|
|
52
|
+
get pitch() {
|
|
53
|
+
return this._pitch;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Sets the positional flag of the sound.
|
|
58
|
+
* @param value - The positional flag.
|
|
59
|
+
*/
|
|
60
|
+
set positional(value: boolean) {
|
|
61
|
+
this._positional = value;
|
|
62
|
+
if (this.component) {
|
|
63
|
+
this.component.positional = value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Gets the positional flag of the sound.
|
|
69
|
+
* @returns The positional flag.
|
|
70
|
+
*/
|
|
71
|
+
get positional() {
|
|
72
|
+
return this._positional;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Sets the volume of the sound.
|
|
77
|
+
* @param value - The volume.
|
|
78
|
+
*/
|
|
79
|
+
set volume(value: number) {
|
|
80
|
+
this._volume = value;
|
|
81
|
+
if (this.component) {
|
|
82
|
+
this.component.volume = value;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Gets the volume of the sound.
|
|
88
|
+
* @returns The volume.
|
|
89
|
+
*/
|
|
90
|
+
get volume() {
|
|
91
|
+
return this._volume;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static get observedAttributes() {
|
|
95
|
+
return [...super.observedAttributes, 'pitch', 'positional', 'volume'];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
99
|
+
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
100
|
+
|
|
101
|
+
switch (name) {
|
|
102
|
+
case 'pitch':
|
|
103
|
+
this.pitch = parseFloat(newValue);
|
|
104
|
+
break;
|
|
105
|
+
case 'positional':
|
|
106
|
+
this.positional = this.hasAttribute('positional');
|
|
107
|
+
break;
|
|
108
|
+
case 'volume':
|
|
109
|
+
this.volume = parseFloat(newValue);
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
customElements.define('pc-sound', SoundComponentElement);
|
|
116
|
+
|
|
117
|
+
export { SoundComponentElement };
|