mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 10:09:05 +02:00
switch to messaging for toggle notifications; cleanup
This commit is contained in:
parent
1048c2a3bf
commit
f88b39918f
1 changed files with 34 additions and 23 deletions
|
@ -92,12 +92,16 @@
|
||||||
if ("disabled" in data && !(disabled === data.disabled)) {
|
if ("disabled" in data && !(disabled === data.disabled)) {
|
||||||
disabled = data.disabled;
|
disabled = data.disabled;
|
||||||
debugPrint("Read ambient disabled state: " + disabled);
|
debugPrint("Read ambient disabled state: " + disabled);
|
||||||
if (disabled) {
|
this._updateColor(disabled);
|
||||||
this.cleanup();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (disabled) {
|
||||||
|
this.cleanup();
|
||||||
|
soundURL = "";
|
||||||
|
return;
|
||||||
|
} else if (!checkTimer) {
|
||||||
|
checkTimer = Script.setInterval(_this.maybeUpdate, UPDATE_INTERVAL_MSECS);
|
||||||
|
}
|
||||||
if (!(soundURL === oldSoundURL) || (soundURL === "")) {
|
if (!(soundURL === oldSoundURL) || (soundURL === "")) {
|
||||||
if (soundURL) {
|
if (soundURL) {
|
||||||
debugPrint("Loading ambient sound into cache");
|
debugPrint("Loading ambient sound into cache");
|
||||||
|
@ -138,7 +142,7 @@
|
||||||
if (Settings.getValue("io.highfidelity.isEditting")) {
|
if (Settings.getValue("io.highfidelity.isEditting")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var props = Entities.getEntityProperties(entity, [ "userData", "age", "scriptTimestamp" ]);
|
var props = Entities.getEntityProperties(entity, [ "userData" ]);
|
||||||
if (!props.userData) {
|
if (!props.userData) {
|
||||||
debugPrint("userData is empty; ignoring " + hint);
|
debugPrint("userData is empty; ignoring " + hint);
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
|
@ -147,19 +151,15 @@
|
||||||
var data = JSON.parse(props.userData);
|
var data = JSON.parse(props.userData);
|
||||||
data.disabled = !data.disabled;
|
data.disabled = !data.disabled;
|
||||||
|
|
||||||
debugPrint(hint + " -- triggering ambient sound " + (data.disabled ? "OFF" : "ON") + " (" + soundURL + ")");
|
debugPrint(hint + " -- triggering ambient sound " + (data.disabled ? "OFF" : "ON") + " (" + data.soundURL + ")");
|
||||||
|
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
// Prevent rapid-fire toggling (which seems to sometimes lead to sound injectors becoming unstoppable)
|
|
||||||
this._toggle = this.clickDownOnEntity = function(hint) { debugPrint("ignoring additonal clicks" + hint); };
|
|
||||||
|
|
||||||
Script.setTimeout(function() {
|
// Save the userData and notify nearby listeners of the change
|
||||||
// Save the userData and bump scriptTimestamp, which causes all nearby listeners to apply the state change
|
Entities.editEntity(entity, {
|
||||||
Entities.editEntity(entity, {
|
userData: JSON.stringify(data)
|
||||||
userData: JSON.stringify(data),
|
});
|
||||||
scriptTimestamp: props.scriptTimestamp + 1
|
Messages.sendMessage(entity, "toggled");
|
||||||
});
|
|
||||||
}, 250);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this._updateColor = function(disabled) {
|
this._updateColor = function(disabled) {
|
||||||
|
@ -182,7 +182,7 @@
|
||||||
entity = entityID;
|
entity = entityID;
|
||||||
_this = this;
|
_this = this;
|
||||||
|
|
||||||
var props = Entities.getEntityProperties(entity, [ "name", "userData" ]);
|
var props = Entities.getEntityProperties(entity, [ "userData" ]);
|
||||||
var data = {};
|
var data = {};
|
||||||
if (props.userData) {
|
if (props.userData) {
|
||||||
data = JSON.parse(props.userData);
|
data = JSON.parse(props.userData);
|
||||||
|
@ -204,8 +204,17 @@
|
||||||
}
|
}
|
||||||
this._updateColor(data.disabled);
|
this._updateColor(data.disabled);
|
||||||
this.updateSettings();
|
this.updateSettings();
|
||||||
if (!data.disabled) {
|
|
||||||
checkTimer = Script.setInterval(_this.maybeUpdate, UPDATE_INTERVAL_MSECS);
|
// Subscribe to toggle notifications using entity ID as a channel name
|
||||||
|
Messages.subscribe(entity);
|
||||||
|
Messages.messageReceived.connect(this, "_onMessageReceived");
|
||||||
|
};
|
||||||
|
|
||||||
|
this._onMessageReceived = function(channel, message, sender, local) {
|
||||||
|
// Handle incoming toggle notifications
|
||||||
|
if (channel === entity && message === "toggled"/*&& sender !== MyAvatar.sessionUUID*/) {
|
||||||
|
debugPrint("received " + message + " from " + sender);
|
||||||
|
this.updateSettings();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -214,9 +223,9 @@
|
||||||
_this.updateSettings();
|
_this.updateSettings();
|
||||||
var HYSTERESIS_FRACTION = 0.1;
|
var HYSTERESIS_FRACTION = 0.1;
|
||||||
var props = Entities.getEntityProperties(entity, [ "position", "rotation" ]);
|
var props = Entities.getEntityProperties(entity, [ "position", "rotation" ]);
|
||||||
if (!props.position) {
|
if (disabled || !props.position) {
|
||||||
print("FIXME: ambientSound.js -- expected Entity unavailable!")
|
_this.cleanup();
|
||||||
return _this.cleanup();
|
return;
|
||||||
}
|
}
|
||||||
center = props.position;
|
center = props.position;
|
||||||
rotation = props.rotation;
|
rotation = props.rotation;
|
||||||
|
@ -236,11 +245,13 @@
|
||||||
soundPlaying = false;
|
soundPlaying = false;
|
||||||
debugPrint("Out of range, stopping ambient sound: " + soundURL);
|
debugPrint("Out of range, stopping ambient sound: " + soundURL);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
this.unload = function(entityID) {
|
this.unload = function(entityID) {
|
||||||
debugPrint("Ambient sound unload ");
|
debugPrint("Ambient sound unload");
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
|
Messages.unsubscribe(entity);
|
||||||
|
Messages.messageReceived.disconnect(this, "_onMessageReceived");
|
||||||
};
|
};
|
||||||
|
|
||||||
this.cleanup = function() {
|
this.cleanup = function() {
|
||||||
|
|
Loading…
Reference in a new issue