Clean up script, go away when putting HMD (not just on startup), and clear stopper properly.

This commit is contained in:
Howard Stearns 2015-11-05 13:19:29 -08:00
parent aef8b7639d
commit 8f65ee87bc

View file

@ -32,6 +32,7 @@ function playAwayAnimation() {
} }
if (stopper) { if (stopper) {
Script.clearTimeout(stopper); Script.clearTimeout(stopper);
stopper = false;
MyAvatar.removeAnimationStateHandler(activeAnimationHandlerId); // do it now, before making new assignment MyAvatar.removeAnimationStateHandler(activeAnimationHandlerId); // do it now, before making new assignment
} }
awayAnimationHandlerId = MyAvatar.addAnimationStateHandler(animateAway, null); awayAnimationHandlerId = MyAvatar.addAnimationStateHandler(animateAway, null);
@ -79,8 +80,8 @@ hideOverlay();
// MAIN CONTROL // MAIN CONTROL
var wasMuted, isAway; var wasMuted, isAway;
function goAway(event) { function goAway() {
if (isAway || event.isAutoRepeat) { // isAutoRepeat is true when held down (or when Windows feels like it) if (isAway) {
return; return;
} }
isAway = true; isAway = true;
@ -93,24 +94,36 @@ function goAway(event) {
playAwayAnimation(); // animation is still seen by others playAwayAnimation(); // animation is still seen by others
showOverlay(); showOverlay();
} }
function switchActiveState(event) { function goActive() {
if (!isAway || event.isAutoRepeat) { if (!isAway) {
if (event.text === '.') { return;
goAway(event);
}
} else {
isAway = false;
print('going "active"');
if (!wasMuted) {
AudioDevice.toggleMute();
}
MyAvatar.setEnableMeshVisible(true); // IWBNI we respected Developer->Avatar->Draw Mesh setting.
stopAwayAnimation();
hideOverlay();
} }
isAway = false;
print('going "active"');
if (!wasMuted) {
AudioDevice.toggleMute();
}
MyAvatar.setEnableMeshVisible(true); // IWBNI we respected Developer->Avatar->Draw Mesh setting.
stopAwayAnimation();
hideOverlay();
} }
Controller.keyPressEvent.connect(switchActiveState); Script.scriptEnding.connect(goActive);
Script.scriptEnding.connect(switchActiveState); Controller.keyPressEvent.connect(function (event) {
if (HMD.active) { if (event.isAutoRepeat) { // isAutoRepeat is true when held down (or when Windows feels like it)
goAway({}); // give a dummy event object return;
} }
if (!isAway && (event.text === '.')) {
goAway();
} else {
goActive();
}
});
var wasHmdActive = false;
Script.update.connect(function () {
if (HMD.active !== wasHmdActive) {
wasHmdActive = !wasHmdActive;
if (wasHmdActive) {
goAway();
}
}
});