diff --git a/src/components/InteractiveObjects/InteractiveObject.js b/src/components/InteractiveObjects/InteractiveObject.js
index 167a1ce..5ee5054 100644
--- a/src/components/InteractiveObjects/InteractiveObject.js
+++ b/src/components/InteractiveObjects/InteractiveObject.js
@@ -70,7 +70,10 @@ class InteractiveObject extends EventDispatcher{
this.io = await new InteractiveObjectsImports[obj.type](gameEngine, obj);
this.source = this.io.source || this.io;
this.object = this.io.object;
- this.io.addEventListener?.('finish', this.dispatchEvent.bind(this))
+ this.emits = this.io.emits;
+ this.io.emits?.forEach(event=>{
+ this.io.addEventListener?.(event, this.dispatchEvent.bind(this))
+ })
break;
}
if (obj.shouldBeLocked){
diff --git a/src/components/SceneDesigner/Scene.vue b/src/components/SceneDesigner/Scene.vue
index e40ecc5..6df53ac 100644
--- a/src/components/SceneDesigner/Scene.vue
+++ b/src/components/SceneDesigner/Scene.vue
@@ -30,6 +30,12 @@
+
+
+ Select ambient sound
+
+
+
@@ -88,6 +94,9 @@ export default {
assignIntro(e){
this.modelValue.intro = e.id;
},
+ assignAudio(e){
+ this.modelValue.audio = e.id;
+ }
}
}
\ No newline at end of file
diff --git a/src/lib/GameEngine.js b/src/lib/GameEngine.js
index 0dab93e..b7b58c1 100644
--- a/src/lib/GameEngine.js
+++ b/src/lib/GameEngine.js
@@ -107,6 +107,10 @@ class GameEngine extends THREE.EventDispatcher{
const dashboard = new DashBoard(this);
this.dashboard = dashboard;
+ this.listener = new THREE.AudioListener();
+ this.camera.add(this.listener);
+ this.ambientSound = new THREE.Audio(this.listener);
+
this.activeObjects = new THREE.Group();
scene.add(this.activeObjects);
@@ -558,9 +562,19 @@ class GameEngine extends THREE.EventDispatcher{
this.physics.clear();
this.clickable.removeAll();
this.motionQueue.clearAll();
+ this.ambientSound.stop();
+ }
+
+ async playAmbientSound(source, path){
+ let buffer = await GameEngine.loadAudio(source, path);
+ this.ambientSound.setBuffer(buffer);
+ this.ambientSound.setLoop(true);
+ this.ambientSound.play();
}
static textureLoader = new THREE.TextureLoader();
+ static audioLoader = new THREE.AudioLoader();
+
static async loadTexture(url, path = assetPath, progress, assignTo) {
return new Promise((resolve, reject) => {
GameEngine.textureLoader.load(`${path}${url}`, texture => {
@@ -573,6 +587,14 @@ class GameEngine extends THREE.EventDispatcher{
})
}
+ static async loadAudio(url, path = assetPath, progress){
+ return new Promise((resolve, reject) => {
+ GameEngine.audioLoader.load(`${path}${url}`, buffer => {
+ resolve(buffer)
+ }, progress, reject)
+ })
+ }
+
loadTexture = GameEngine.loadTexture
}
diff --git a/src/mixins/GameEnvironmentMixin.js b/src/mixins/GameEnvironmentMixin.js
index be50195..5bd72d2 100644
--- a/src/mixins/GameEnvironmentMixin.js
+++ b/src/mixins/GameEnvironmentMixin.js
@@ -100,7 +100,7 @@ export default {
async expandScenarioData(scene){
const promises = [];
- ['environment', 'scene', 'intro'].filter(e=>scene.data[e]).forEach(e=>{
+ ['environment', 'scene', 'intro', 'audio'].filter(e=>scene.data[e]).forEach(e=>{
promises.push(this.$api.gameObject.load(scene.data[e]).then(r=>scene.data['$'+e] = r.data))
})
@@ -130,6 +130,10 @@ export default {
if (this.scene.data.$environment){
await gameEngine.loadPanorama(this.scene.data.$environment.asset.name);
}
+ if (this.scene.data.$audio){
+ await gameEngine.playAmbientSound(this.scene.data.$audio.asset.name);
+ gameEngine.ambientSound.setVolume( 0.5 );
+ }
if (this.scene.data.$scene){
let env = await gameEngine.load(this.scene.data.$scene.asset.name);
this.setObjectAttributes(l, this.scene.data, env.scene, env, 100);
@@ -194,7 +198,7 @@ export default {
});
if (finished == expectToFinish){
//GO TO NEXT LEVEL
-
+ console.log('LEVEL FINISHED')
}
})
}
diff --git a/src/plugins/params.js b/src/plugins/params.js
index d9f597d..db24635 100644
--- a/src/plugins/params.js
+++ b/src/plugins/params.js
@@ -38,6 +38,7 @@ export default {
}, {
value: 'audio',
icon: 'volume-medium',
+ type: 'Audio',
color: 'deep-purple-accent-2'
}]
}