mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 09:17:29 +02:00
Merge pull request #13826 from ctrlaltdavid/M17615
Disable Vive teleport button if transitioning from direction button
This commit is contained in:
commit
c876cda89d
1 changed files with 66 additions and 3 deletions
|
@ -190,8 +190,42 @@ Script.include("/~/system/libraries/controllers.js");
|
||||||
Pointers.removePointer(this.teleportParabolaHeadInvisible);
|
Pointers.removePointer(this.teleportParabolaHeadInvisible);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.buttonPress = function(value) {
|
this.axisButtonStateX = 0; // Left/right axis button pressed.
|
||||||
_this.buttonValue = value;
|
this.axisButtonStateY = 0; // Up/down axis button pressed.
|
||||||
|
this.BUTTON_TRANSITION_DELAY = 100; // Allow time for transition from direction buttons to touch-pad.
|
||||||
|
|
||||||
|
this.axisButtonChangeX = function (value) {
|
||||||
|
if (value !== 0) {
|
||||||
|
_this.axisButtonStateX = value;
|
||||||
|
} else {
|
||||||
|
// Delay direction button release until after teleport possibly pressed.
|
||||||
|
Script.setTimeout(function () {
|
||||||
|
_this.axisButtonStateX = value;
|
||||||
|
}, _this.BUTTON_TRANSITION_DELAY);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.axisButtonChangeY = function (value) {
|
||||||
|
if (value !== 0) {
|
||||||
|
_this.axisButtonStateY = value;
|
||||||
|
} else {
|
||||||
|
// Delay direction button release until after teleport possibly pressed.
|
||||||
|
Script.setTimeout(function () {
|
||||||
|
_this.axisButtonStateY = value;
|
||||||
|
}, _this.BUTTON_TRANSITION_DELAY);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.teleportLocked = function () {
|
||||||
|
// Lock teleport if in advanced movement mode and have just transitioned from pressing a direction button.
|
||||||
|
return Controller.getValue(Controller.Hardware.Application.AdvancedMovement)
|
||||||
|
&& (_this.axisButtonStateX !== 0 || _this.axisButtonStateY !== 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.buttonPress = function (value) {
|
||||||
|
if (value === 0 || !_this.teleportLocked()) {
|
||||||
|
_this.buttonValue = value;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.parameters = makeDispatcherModuleParameters(
|
this.parameters = makeDispatcherModuleParameters(
|
||||||
|
@ -347,6 +381,7 @@ Script.include("/~/system/libraries/controllers.js");
|
||||||
}
|
}
|
||||||
|
|
||||||
var mappingName, teleportMapping;
|
var mappingName, teleportMapping;
|
||||||
|
var isViveMapped = false;
|
||||||
|
|
||||||
function parseJSON(json) {
|
function parseJSON(json) {
|
||||||
try {
|
try {
|
||||||
|
@ -390,12 +425,39 @@ Script.include("/~/system/libraries/controllers.js");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function registerViveTeleportMapping() {
|
||||||
|
// Disable Vive teleport if touch is transitioning across touch-pad after pressing a direction button.
|
||||||
|
if (Controller.Hardware.Vive) {
|
||||||
|
var mappingName = 'Hifi-Teleporter-Dev-Vive-' + Math.random();
|
||||||
|
var viveTeleportMapping = Controller.newMapping(mappingName);
|
||||||
|
viveTeleportMapping.from(Controller.Hardware.Vive.LSX).peek().to(leftTeleporter.axisButtonChangeX);
|
||||||
|
viveTeleportMapping.from(Controller.Hardware.Vive.LSY).peek().to(leftTeleporter.axisButtonChangeY);
|
||||||
|
viveTeleportMapping.from(Controller.Hardware.Vive.RSX).peek().to(rightTeleporter.axisButtonChangeX);
|
||||||
|
viveTeleportMapping.from(Controller.Hardware.Vive.RSY).peek().to(rightTeleporter.axisButtonChangeY);
|
||||||
|
Controller.enableMapping(mappingName);
|
||||||
|
isViveMapped = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onHardwareChanged() {
|
||||||
|
// Controller.Hardware.Vive is not immediately available at Interface start-up.
|
||||||
|
if (!isViveMapped && Controller.Hardware.Vive) {
|
||||||
|
registerViveTeleportMapping();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Controller.hardwareChanged.connect(onHardwareChanged);
|
||||||
|
|
||||||
function registerMappings() {
|
function registerMappings() {
|
||||||
mappingName = 'Hifi-Teleporter-Dev-' + Math.random();
|
mappingName = 'Hifi-Teleporter-Dev-' + Math.random();
|
||||||
teleportMapping = Controller.newMapping(mappingName);
|
teleportMapping = Controller.newMapping(mappingName);
|
||||||
|
|
||||||
teleportMapping.from(Controller.Standard.RightPrimaryThumb).peek().to(rightTeleporter.buttonPress);
|
// Vive teleport button lock-out.
|
||||||
|
registerViveTeleportMapping();
|
||||||
|
|
||||||
|
// Teleport actions.
|
||||||
teleportMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(leftTeleporter.buttonPress);
|
teleportMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(leftTeleporter.buttonPress);
|
||||||
|
teleportMapping.from(Controller.Standard.RightPrimaryThumb).peek().to(rightTeleporter.buttonPress);
|
||||||
}
|
}
|
||||||
|
|
||||||
var leftTeleporter = new Teleporter(LEFT_HAND);
|
var leftTeleporter = new Teleporter(LEFT_HAND);
|
||||||
|
@ -407,6 +469,7 @@ Script.include("/~/system/libraries/controllers.js");
|
||||||
Controller.enableMapping(mappingName);
|
Controller.enableMapping(mappingName);
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
|
Controller.hardwareChanged.disconnect(onHardwareChanged);
|
||||||
teleportMapping.disable();
|
teleportMapping.disable();
|
||||||
leftTeleporter.cleanup();
|
leftTeleporter.cleanup();
|
||||||
rightTeleporter.cleanup();
|
rightTeleporter.cleanup();
|
||||||
|
|
Loading…
Reference in a new issue