mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-08 22:17:03 +02:00
Able to switch url sounds
This commit is contained in:
parent
355f60f088
commit
120c5ac370
1 changed files with 20 additions and 22 deletions
|
@ -29,7 +29,6 @@ print("EBL STARTING SCRIPT");
|
||||||
|
|
||||||
function slowUpdate() {
|
function slowUpdate() {
|
||||||
var avatars = AvatarList.getAvatarIdentifiers();
|
var avatars = AvatarList.getAvatarIdentifiers();
|
||||||
print("CURRENT AVATAR LIST: " + JSON.stringify(avatars));
|
|
||||||
for (var i = 0; i < avatars.length; i++) {
|
for (var i = 0; i < avatars.length; i++) {
|
||||||
var avatar = AvatarList.getAvatar(avatars[i]);
|
var avatar = AvatarList.getAvatar(avatars[i]);
|
||||||
var avatarPosition = avatar.position;
|
var avatarPosition = avatar.position;
|
||||||
|
@ -57,30 +56,26 @@ function handleActiveSoundEntities() {
|
||||||
var soundEntity = potentialSoundEntity;
|
var soundEntity = potentialSoundEntity;
|
||||||
var soundProperties = soundEntityMap[soundEntity];
|
var soundProperties = soundEntityMap[soundEntity];
|
||||||
soundProperties.timeWithoutAvatarInRange += UPDATE_TIME;
|
soundProperties.timeWithoutAvatarInRange += UPDATE_TIME;
|
||||||
if (soundProperties.timeWithoutAvatarInRange > EXPIRATION_TIME) {
|
if (soundProperties.timeWithoutAvatarInRange > EXPIRATION_TIME && soundProperties.soundInjector) {
|
||||||
// An avatar hasn't been within range of this sound entity recently, so remove it from map
|
// An avatar hasn't been within range of this sound entity recently, so remove it from map
|
||||||
print("NO AVATARS HAVE BEEN AROUND FOR A WHILE SO REMOVE THIS SOUND FROM SOUNDMAP!");
|
print("NO AVATARS HAVE BEEN AROUND FOR A WHILE SO REMOVE THIS SOUND FROM SOUNDMAP!");
|
||||||
// If the sound was looping, make sure to stop playing it
|
soundProperties.soundInjector.stop();
|
||||||
if (soundProperties.loop) {
|
|
||||||
print("STOP SOUND INJECTOR!!");
|
|
||||||
soundProperties.soundInjector.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
delete soundEntityMap[soundEntity];
|
delete soundEntityMap[soundEntity];
|
||||||
print("NEW MAP " + JSON.stringify(soundEntityMap));
|
} else if(soundProperties.isDownloaded) {
|
||||||
} else {
|
print("WERE DOWNLOADED");
|
||||||
// If this sound hasn't expired yet, we want to potentially play it!
|
// If this sound hasn't expired yet, we want to potentially play it!
|
||||||
if (soundProperties.readyToPlay) {
|
if (soundProperties.readyToPlay) {
|
||||||
|
print("WERE READY TO PLAY")
|
||||||
var newPosition = Entities.getEntityProperties(soundEntity, "position").position;
|
var newPosition = Entities.getEntityProperties(soundEntity, "position").position;
|
||||||
if (!soundProperties.soundInjector) {
|
if (!soundProperties.soundInjector) {
|
||||||
print("PLAY SOUND! SOUND VOLUME " + soundProperties.volume)
|
print("PLAY SOUND!");
|
||||||
soundProperties.soundInjector = Audio.playSound(soundProperties.sound, {
|
soundProperties.soundInjector = Audio.playSound(soundProperties.sound, {
|
||||||
volume: soundProperties.volume,
|
volume: soundProperties.volume,
|
||||||
position: newPosition,
|
position: newPosition,
|
||||||
loop: soundProperties.loop
|
loop: soundProperties.loop
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
print ("RESTART INJECTOR!")
|
||||||
soundProperties.soundInjector.restart();
|
soundProperties.soundInjector.restart();
|
||||||
}
|
}
|
||||||
soundProperties.readyToPlay = false;
|
soundProperties.readyToPlay = false;
|
||||||
|
@ -88,6 +83,7 @@ function handleActiveSoundEntities() {
|
||||||
// We need to check all of our entities that are not looping but have an interval associated with them
|
// We need to check all of our entities that are not looping but have an interval associated with them
|
||||||
// to see if it's time for them to play again
|
// to see if it's time for them to play again
|
||||||
soundProperties.timeSinceLastPlay += UPDATE_TIME;
|
soundProperties.timeSinceLastPlay += UPDATE_TIME;
|
||||||
|
print("INCREMENT TIME SINCE LAST PLAY")
|
||||||
if (soundProperties.timeSinceLastPlay > soundProperties.currentInterval) {
|
if (soundProperties.timeSinceLastPlay > soundProperties.currentInterval) {
|
||||||
soundProperties.readyToPlay = true;
|
soundProperties.readyToPlay = true;
|
||||||
soundProperties.timeSinceLastPlay = 0;
|
soundProperties.timeSinceLastPlay = 0;
|
||||||
|
@ -117,7 +113,8 @@ function handleFoundSoundEntities(entities) {
|
||||||
readyToPlay: false,
|
readyToPlay: false,
|
||||||
position: Entities.getEntityProperties(entity, "position").position,
|
position: Entities.getEntityProperties(entity, "position").position,
|
||||||
timeSinceLastPlay: 0,
|
timeSinceLastPlay: 0,
|
||||||
timeWithoutAvatarInRange: 0
|
timeWithoutAvatarInRange: 0,
|
||||||
|
isDownloaded: false
|
||||||
};
|
};
|
||||||
|
|
||||||
if (soundProperties.interval !== -1) {
|
if (soundProperties.interval !== -1) {
|
||||||
|
@ -135,6 +132,7 @@ function handleFoundSoundEntities(entities) {
|
||||||
print("ADD TO MAP!")
|
print("ADD TO MAP!")
|
||||||
soundProperties.sound = sound;
|
soundProperties.sound = sound;
|
||||||
soundProperties.readyToPlay = true;
|
soundProperties.readyToPlay = true;
|
||||||
|
soundProperties.isDownloaded = true;
|
||||||
soundEntityMap[entity] = soundProperties;
|
soundEntityMap[entity] = soundProperties;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -162,28 +160,28 @@ function checkForSoundPropertyChanges(currentProps, newProps) {
|
||||||
}
|
}
|
||||||
if (currentProps.url !== newProps.url) {
|
if (currentProps.url !== newProps.url) {
|
||||||
currentProps.url = newProps.url;
|
currentProps.url = newProps.url;
|
||||||
|
currentProps.sound = null;
|
||||||
if (!soundUrls[currentProps.url]) {
|
if (!soundUrls[currentProps.url]) {
|
||||||
var sound = SoundCache.getSound(currentProps.url);
|
var sound = SoundCache.getSound(currentProps.url);
|
||||||
currentProps.sound = null;
|
currentProps.isDownloaded = false;
|
||||||
currentProps.readyToPlay = false;
|
|
||||||
sound.ready.connect(function() {
|
sound.ready.connect(function() {
|
||||||
print("Ready to play new sound!")
|
print("Ready to play new sound!")
|
||||||
currentProps.soundInjector.restart();
|
|
||||||
currentProps.soundInjector.stop();
|
|
||||||
currentProps.sound = sound;
|
currentProps.sound = sound;
|
||||||
currentProps.soundInjector = null;
|
currentProps.isDownloaded = true;
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
currentProps.sound = sound;
|
||||||
}
|
}
|
||||||
|
needsUpdate = true;
|
||||||
}
|
}
|
||||||
if (needsUpdate && currentProps.loop) {
|
if (needsUpdate) {
|
||||||
print("LOOP CHANGED!");
|
print("UPDATING!");
|
||||||
currentProps.loop = newProps.loop;
|
|
||||||
// If we were looping we need to stop that so new changes are applied
|
// If we were looping we need to stop that so new changes are applied
|
||||||
currentProps.soundInjector.restart();
|
|
||||||
currentProps.soundInjector.stop();
|
currentProps.soundInjector.stop();
|
||||||
currentProps.soundInjector = null;
|
currentProps.soundInjector = null;
|
||||||
currentProps.readyToPlay = true;
|
currentProps.readyToPlay = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Script.setInterval(slowUpdate, UPDATE_TIME);
|
Script.setInterval(slowUpdate, UPDATE_TIME);
|
Loading…
Reference in a new issue