mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 23:40:11 +02:00
simpler/better/more reliable (peek)
This commit is contained in:
parent
0d8404e7e8
commit
7c4e31687c
1 changed files with 9 additions and 24 deletions
|
@ -19,14 +19,6 @@ var OVERLAY_DATA = {
|
||||||
color: {red: 255, green: 255, blue: 255},
|
color: {red: 255, green: 255, blue: 255},
|
||||||
alpha: 1
|
alpha: 1
|
||||||
};
|
};
|
||||||
// For the script to receive an event when the user presses a hand-controller button, we need to map
|
|
||||||
// that button to the handler, which we do at the bottom of this script. However, doing so changes
|
|
||||||
// the mapping for the user, across all scripts. Therefore, we just enable the mapping when going
|
|
||||||
// "away", and disable it when going "active". However, this is occuring within a Controller event, so we
|
|
||||||
// have to wait until the Controller code has finished with all such events, so we delay
|
|
||||||
// it. Additionally, we may go "away" on startup, and we want to wait until any other such mapping
|
|
||||||
// have occured, because only the last remapping wins.
|
|
||||||
var CONTROLLER_REMAPPING_DELAY = 750; // ms
|
|
||||||
|
|
||||||
// ANIMATION
|
// ANIMATION
|
||||||
// We currently don't have play/stopAnimation integrated with the animation graph, but we can get the same effect
|
// We currently don't have play/stopAnimation integrated with the animation graph, but we can get the same effect
|
||||||
|
@ -105,11 +97,6 @@ function goAway() {
|
||||||
if (isAway) {
|
if (isAway) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Script.setTimeout(function () {
|
|
||||||
if (isAway) { // i.e., unless something changed during the delay.
|
|
||||||
Controller.enableMapping(eventMappingName);
|
|
||||||
}
|
|
||||||
}, CONTROLLER_REMAPPING_DELAY);
|
|
||||||
isAway = true;
|
isAway = true;
|
||||||
print('going "away"');
|
print('going "away"');
|
||||||
wasMuted = AudioDevice.getMuted();
|
wasMuted = AudioDevice.getMuted();
|
||||||
|
@ -124,11 +111,6 @@ function goActive() {
|
||||||
if (!isAway) {
|
if (!isAway) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Script.setTimeout(function () {
|
|
||||||
if (!isAway) { // i.e., unless something changed during the delay
|
|
||||||
Controller.disableMapping(eventMappingName); // Let hand-controller events through to other scripts.
|
|
||||||
}
|
|
||||||
}, CONTROLLER_REMAPPING_DELAY);
|
|
||||||
isAway = false;
|
isAway = false;
|
||||||
print('going "active"');
|
print('going "active"');
|
||||||
if (!wasMuted) {
|
if (!wasMuted) {
|
||||||
|
@ -160,16 +142,19 @@ function maybeGoAway() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Script.update.connect(maybeGoAway);
|
Script.update.connect(maybeGoAway);
|
||||||
// These two can be set now and left active as long as the script is running. They do not interfere with other scripts.
|
|
||||||
Controller.mousePressEvent.connect(goActive);
|
Controller.mousePressEvent.connect(goActive);
|
||||||
Controller.keyPressEvent.connect(maybeGoActive);
|
Controller.keyPressEvent.connect(maybeGoActive);
|
||||||
// Set up the mapping, but don't enable it until we're actually away.
|
// Note peek() so as to not interfere with other mappings.
|
||||||
eventMapping.from(Controller.Standard.LeftPrimaryThumb).to(goActive);
|
eventMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(goActive);
|
||||||
eventMapping.from(Controller.Standard.RightPrimaryThumb).to(goActive);
|
eventMapping.from(Controller.Standard.RightPrimaryThumb).peek().to(goActive);
|
||||||
eventMapping.from(Controller.Standard.LeftSecondaryThumb).to(goActive);
|
eventMapping.from(Controller.Standard.LeftSecondaryThumb).peek().to(goActive);
|
||||||
eventMapping.from(Controller.Standard.RightSecondaryThumb).to(goActive);
|
eventMapping.from(Controller.Standard.RightSecondaryThumb).peek().to(goActive);
|
||||||
|
Controller.enableMapping(eventMappingName);
|
||||||
|
|
||||||
Script.scriptEnding.connect(function () {
|
Script.scriptEnding.connect(function () {
|
||||||
Script.update.disconnect(maybeGoAway);
|
Script.update.disconnect(maybeGoAway);
|
||||||
goActive();
|
goActive();
|
||||||
|
Controller.disableMapping(eventMappingName);
|
||||||
|
Controller.mousePressEvent.disconnect(goActive);
|
||||||
|
Controller.keyPressEvent.disconnect(maybeGoActive);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue