mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-08 19:23:28 +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},
|
||||
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
|
||||
// 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) {
|
||||
return;
|
||||
}
|
||||
Script.setTimeout(function () {
|
||||
if (isAway) { // i.e., unless something changed during the delay.
|
||||
Controller.enableMapping(eventMappingName);
|
||||
}
|
||||
}, CONTROLLER_REMAPPING_DELAY);
|
||||
isAway = true;
|
||||
print('going "away"');
|
||||
wasMuted = AudioDevice.getMuted();
|
||||
|
@ -124,11 +111,6 @@ function goActive() {
|
|||
if (!isAway) {
|
||||
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;
|
||||
print('going "active"');
|
||||
if (!wasMuted) {
|
||||
|
@ -160,16 +142,19 @@ function 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.keyPressEvent.connect(maybeGoActive);
|
||||
// Set up the mapping, but don't enable it until we're actually away.
|
||||
eventMapping.from(Controller.Standard.LeftPrimaryThumb).to(goActive);
|
||||
eventMapping.from(Controller.Standard.RightPrimaryThumb).to(goActive);
|
||||
eventMapping.from(Controller.Standard.LeftSecondaryThumb).to(goActive);
|
||||
eventMapping.from(Controller.Standard.RightSecondaryThumb).to(goActive);
|
||||
// Note peek() so as to not interfere with other mappings.
|
||||
eventMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(goActive);
|
||||
eventMapping.from(Controller.Standard.RightPrimaryThumb).peek().to(goActive);
|
||||
eventMapping.from(Controller.Standard.LeftSecondaryThumb).peek().to(goActive);
|
||||
eventMapping.from(Controller.Standard.RightSecondaryThumb).peek().to(goActive);
|
||||
Controller.enableMapping(eventMappingName);
|
||||
|
||||
Script.scriptEnding.connect(function () {
|
||||
Script.update.disconnect(maybeGoAway);
|
||||
goActive();
|
||||
Controller.disableMapping(eventMappingName);
|
||||
Controller.mousePressEvent.disconnect(goActive);
|
||||
Controller.keyPressEvent.disconnect(maybeGoActive);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue