mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 01:24:36 +02:00
Teleport.js: Fix message bugs, and made eslint clean
* 'Hifi-Teleport-Ignore-Add' and 'Hifi-Teleport-Ignore-Remove' messages should now should work * 'Hifi-Teleport-Disabler' message should now work
This commit is contained in:
parent
51d5f86989
commit
c26d04dca1
1 changed files with 319 additions and 373 deletions
|
@ -14,7 +14,6 @@
|
||||||
enableDispatcherModule, disableDispatcherModule, Messages, makeDispatcherModuleParameters, makeRunningValues, Vec3,
|
enableDispatcherModule, disableDispatcherModule, Messages, makeDispatcherModuleParameters, makeRunningValues, Vec3,
|
||||||
LaserPointers, RayPick, HMD, Uuid, AvatarList
|
LaserPointers, RayPick, HMD, Uuid, AvatarList
|
||||||
*/
|
*/
|
||||||
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
|
|
||||||
|
|
||||||
Script.include("/~/system/libraries/Xform.js");
|
Script.include("/~/system/libraries/Xform.js");
|
||||||
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
||||||
|
@ -22,11 +21,6 @@ Script.include("/~/system/libraries/controllers.js");
|
||||||
|
|
||||||
(function() { // BEGIN LOCAL_SCOPE
|
(function() { // BEGIN LOCAL_SCOPE
|
||||||
|
|
||||||
var inTeleportMode = false;
|
|
||||||
|
|
||||||
var SMOOTH_ARRIVAL_SPACING = 33;
|
|
||||||
var NUMBER_OF_STEPS = 6;
|
|
||||||
|
|
||||||
var TARGET_MODEL_URL = Script.resolvePath("../../assets/models/teleport-destination.fbx");
|
var TARGET_MODEL_URL = Script.resolvePath("../../assets/models/teleport-destination.fbx");
|
||||||
var TOO_CLOSE_MODEL_URL = Script.resolvePath("../../assets/models/teleport-cancel.fbx");
|
var TOO_CLOSE_MODEL_URL = Script.resolvePath("../../assets/models/teleport-cancel.fbx");
|
||||||
var SEAT_MODEL_URL = Script.resolvePath("../../assets/models/teleport-seat.fbx");
|
var SEAT_MODEL_URL = Script.resolvePath("../../assets/models/teleport-seat.fbx");
|
||||||
|
@ -120,29 +114,6 @@ var teleportRenderStates = [{name: "cancel", path: cancelPath, end: cancelEnd},
|
||||||
var DEFAULT_DISTANCE = 50;
|
var DEFAULT_DISTANCE = 50;
|
||||||
var teleportDefaultRenderStates = [{name: "cancel", distance: DEFAULT_DISTANCE, path: cancelPath}];
|
var teleportDefaultRenderStates = [{name: "cancel", distance: DEFAULT_DISTANCE, path: cancelPath}];
|
||||||
|
|
||||||
function ThumbPad(hand) {
|
|
||||||
this.hand = hand;
|
|
||||||
var _thisPad = this;
|
|
||||||
|
|
||||||
this.buttonPress = function(value) {
|
|
||||||
_thisPad.buttonValue = value;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function Trigger(hand) {
|
|
||||||
this.hand = hand;
|
|
||||||
var _this = this;
|
|
||||||
|
|
||||||
this.buttonPress = function(value) {
|
|
||||||
_this.buttonValue = value;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.down = function() {
|
|
||||||
var down = _this.buttonValue === 1 ? 1.0 : 0.0;
|
|
||||||
return down;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
var coolInTimeout = null;
|
var coolInTimeout = null;
|
||||||
var ignoredEntities = [];
|
var ignoredEntities = [];
|
||||||
|
|
||||||
|
@ -150,7 +121,7 @@ var TELEPORTER_STATES = {
|
||||||
IDLE: 'idle',
|
IDLE: 'idle',
|
||||||
COOL_IN: 'cool_in',
|
COOL_IN: 'cool_in',
|
||||||
TARGETTING: 'targetting',
|
TARGETTING: 'targetting',
|
||||||
TARGETTING_INVALID: 'targetting_invalid',
|
TARGETTING_INVALID: 'targetting_invalid'
|
||||||
};
|
};
|
||||||
|
|
||||||
var TARGET = {
|
var TARGET = {
|
||||||
|
@ -158,13 +129,14 @@ var TARGET = {
|
||||||
INVISIBLE: 'invisible', // The current target is an invvsible surface
|
INVISIBLE: 'invisible', // The current target is an invvsible surface
|
||||||
INVALID: 'invalid', // The current target is invalid (wall, ceiling, etc.)
|
INVALID: 'invalid', // The current target is invalid (wall, ceiling, etc.)
|
||||||
SURFACE: 'surface', // The current target is a valid surface
|
SURFACE: 'surface', // The current target is a valid surface
|
||||||
SEAT: 'seat', // The current target is a seat
|
SEAT: 'seat' // The current target is a seat
|
||||||
};
|
};
|
||||||
|
|
||||||
function Teleporter(hand) {
|
function Teleporter(hand) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
this.hand = hand;
|
this.hand = hand;
|
||||||
this.buttonValue = 0;
|
this.buttonValue = 0;
|
||||||
|
this.disabled = false; // used by the 'Hifi-Teleport-Disabler' message handler
|
||||||
this.active = false;
|
this.active = false;
|
||||||
this.state = TELEPORTER_STATES.IDLE;
|
this.state = TELEPORTER_STATES.IDLE;
|
||||||
this.currentTarget = TARGET.INVALID;
|
this.currentTarget = TARGET.INVALID;
|
||||||
|
@ -206,20 +178,7 @@ function Teleporter(hand) {
|
||||||
renderStates: teleportRenderStates
|
renderStates: teleportRenderStates
|
||||||
});
|
});
|
||||||
|
|
||||||
this.teleporterMappingInternalName = 'Hifi-Teleporter-Internal-Dev-' + Math.random();
|
|
||||||
this.teleportMappingInternal = Controller.newMapping(this.teleporterMappingInternalName);
|
|
||||||
|
|
||||||
this.enableMappings = function() {
|
|
||||||
Controller.enableMapping(this.teleporterMappingInternalName);
|
|
||||||
};
|
|
||||||
|
|
||||||
this.disableMappings = function() {
|
|
||||||
Controller.disableMapping(teleporter.teleporterMappingInternalName);
|
|
||||||
};
|
|
||||||
|
|
||||||
this.cleanup = function() {
|
this.cleanup = function() {
|
||||||
this.disableMappings();
|
|
||||||
|
|
||||||
LaserPointers.removeLaserPointer(this.teleportRayHandVisible);
|
LaserPointers.removeLaserPointer(this.teleportRayHandVisible);
|
||||||
LaserPointers.removeLaserPointer(this.teleportRayHandInvisible);
|
LaserPointers.removeLaserPointer(this.teleportRayHandInvisible);
|
||||||
LaserPointers.removeLaserPointer(this.teleportRayHeadVisible);
|
LaserPointers.removeLaserPointer(this.teleportRayHeadVisible);
|
||||||
|
@ -279,7 +238,7 @@ function Teleporter(hand) {
|
||||||
|
|
||||||
this.isReady = function(controllerData, deltaTime) {
|
this.isReady = function(controllerData, deltaTime) {
|
||||||
var otherModule = this.getOtherModule();
|
var otherModule = this.getOtherModule();
|
||||||
if (_this.buttonValue !== 0 && !otherModule.active) {
|
if (!this.disabled && this.buttonValue !== 0 && !otherModule.active) {
|
||||||
this.active = true;
|
this.active = true;
|
||||||
this.enterTeleport();
|
this.enterTeleport();
|
||||||
return makeRunningValues(true, [], []);
|
return makeRunningValues(true, [], []);
|
||||||
|
@ -288,7 +247,6 @@ function Teleporter(hand) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.run = function(controllerData, deltaTime) {
|
this.run = function(controllerData, deltaTime) {
|
||||||
//_this.state = TELEPORTER_STATES.TARGETTING;
|
|
||||||
|
|
||||||
// Get current hand pose information to see if the pose is valid
|
// Get current hand pose information to see if the pose is valid
|
||||||
var pose = Controller.getPoseValue(handInfo[(_this.hand === RIGHT_HAND) ? 'right' : 'left'].controllerInput);
|
var pose = Controller.getPoseValue(handInfo[(_this.hand === RIGHT_HAND) ? 'right' : 'left'].controllerInput);
|
||||||
|
@ -387,6 +345,13 @@ function Teleporter(hand) {
|
||||||
LaserPointers.setRenderState(_this.teleportRayHandInvisible, invisibleState);
|
LaserPointers.setRenderState(_this.teleportRayHandInvisible, invisibleState);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.setIgnoreEntities = function(entitiesToIgnore) {
|
||||||
|
LaserPointers.setIgnoreEntities(this.teleportRayHandVisible, entitiesToIgnore);
|
||||||
|
LaserPointers.setIgnoreEntities(this.teleportRayHandInvisible, entitiesToIgnore);
|
||||||
|
LaserPointers.setIgnoreEntities(this.teleportRayHeadVisible, entitiesToIgnore);
|
||||||
|
LaserPointers.setIgnoreEntities(this.teleportRayHeadInvisible, entitiesToIgnore);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// related to repositioning the avatar after you teleport
|
// related to repositioning the avatar after you teleport
|
||||||
|
@ -399,11 +364,11 @@ function Teleporter(hand) {
|
||||||
var i, l = FOOT_JOINT_NAMES.length;
|
var i, l = FOOT_JOINT_NAMES.length;
|
||||||
for (i = 0; i < l; i++) {
|
for (i = 0; i < l; i++) {
|
||||||
footJointIndex = MyAvatar.getJointIndex(FOOT_JOINT_NAMES[i]);
|
footJointIndex = MyAvatar.getJointIndex(FOOT_JOINT_NAMES[i]);
|
||||||
if (footJointIndex != -1) {
|
if (footJointIndex !== -1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (footJointIndex != -1) {
|
if (footJointIndex !== -1) {
|
||||||
// default vertical offset from foot to avatar root.
|
// default vertical offset from foot to avatar root.
|
||||||
var footPos = MyAvatar.getAbsoluteDefaultJointTranslationInObjectFrame(footJointIndex);
|
var footPos = MyAvatar.getAbsoluteDefaultJointTranslationInObjectFrame(footJointIndex);
|
||||||
if (footPos.x === 0 && footPos.y === 0 && footPos.z === 0.0) {
|
if (footPos.x === 0 && footPos.y === 0 && footPos.z === 0.0) {
|
||||||
|
@ -417,23 +382,8 @@ function Teleporter(hand) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var leftPad = new ThumbPad('left');
|
|
||||||
var rightPad = new ThumbPad('right');
|
|
||||||
|
|
||||||
var mappingName, teleportMapping;
|
var mappingName, teleportMapping;
|
||||||
|
|
||||||
var TELEPORT_DELAY = 0;
|
|
||||||
|
|
||||||
function isMoving() {
|
|
||||||
var LY = Controller.getValue(Controller.Standard.LY);
|
|
||||||
var LX = Controller.getValue(Controller.Standard.LX);
|
|
||||||
if (LY !== 0 || LX !== 0) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseJSON(json) {
|
function parseJSON(json) {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(json);
|
return JSON.parse(json);
|
||||||
|
@ -447,7 +397,7 @@ function Teleporter(hand) {
|
||||||
// you can't teleport there.
|
// you can't teleport there.
|
||||||
var MAX_ANGLE_FROM_UP_TO_TELEPORT = 70;
|
var MAX_ANGLE_FROM_UP_TO_TELEPORT = 70;
|
||||||
function getTeleportTargetType(result) {
|
function getTeleportTargetType(result) {
|
||||||
if (result.type == RayPick.INTERSECTED_NONE) {
|
if (result.type === RayPick.INTERSECTED_NONE) {
|
||||||
return TARGET.NONE;
|
return TARGET.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,41 +452,37 @@ function Teleporter(hand) {
|
||||||
}
|
}
|
||||||
Script.scriptEnding.connect(cleanup);
|
Script.scriptEnding.connect(cleanup);
|
||||||
|
|
||||||
var setIgnoreEntities = function() {
|
|
||||||
LaserPointers.setIgnoreEntities(teleporter.teleportRayRightVisible, ignoredEntities);
|
|
||||||
LaserPointers.setIgnoreEntities(teleporter.teleportRayRightInvisible, ignoredEntities);
|
|
||||||
LaserPointers.setIgnoreEntities(teleporter.teleportRayLeftVisible, ignoredEntities);
|
|
||||||
LaserPointers.setIgnoreEntities(teleporter.teleportRayLeftInvisible, ignoredEntities);
|
|
||||||
LaserPointers.setIgnoreEntities(teleporter.teleportRayHeadVisible, ignoredEntities);
|
|
||||||
LaserPointers.setIgnoreEntities(teleporter.teleportRayHeadInvisible, ignoredEntities);
|
|
||||||
};
|
|
||||||
|
|
||||||
var isDisabled = false;
|
|
||||||
var handleTeleportMessages = function(channel, message, sender) {
|
var handleTeleportMessages = function(channel, message, sender) {
|
||||||
if (sender === MyAvatar.sessionUUID) {
|
if (sender === MyAvatar.sessionUUID) {
|
||||||
if (channel === 'Hifi-Teleport-Disabler') {
|
if (channel === 'Hifi-Teleport-Disabler') {
|
||||||
if (message === 'both') {
|
if (message === 'both') {
|
||||||
isDisabled = 'both';
|
leftTeleporter.disabled = true;
|
||||||
|
rightTeleporter.disabled = true;
|
||||||
}
|
}
|
||||||
if (message === 'left') {
|
if (message === 'left') {
|
||||||
isDisabled = 'left';
|
leftTeleporter.disabled = true;
|
||||||
|
rightTeleporter.disabled = false;
|
||||||
}
|
}
|
||||||
if (message === 'right') {
|
if (message === 'right') {
|
||||||
isDisabled = 'right';
|
leftTeleporter.disabled = false;
|
||||||
|
rightTeleporter.disabled = true;
|
||||||
}
|
}
|
||||||
if (message === 'none') {
|
if (message === 'none') {
|
||||||
isDisabled = false;
|
leftTeleporter.disabled = false;
|
||||||
|
rightTeleporter.disabled = false;
|
||||||
}
|
}
|
||||||
} else if (channel === 'Hifi-Teleport-Ignore-Add' &&
|
} else if (channel === 'Hifi-Teleport-Ignore-Add' &&
|
||||||
!Uuid.isNull(message) &&
|
!Uuid.isNull(message) &&
|
||||||
ignoredEntities.indexOf(message) === -1) {
|
ignoredEntities.indexOf(message) === -1) {
|
||||||
ignoredEntities.push(message);
|
ignoredEntities.push(message);
|
||||||
setIgnoreEntities();
|
leftTeleporter.setIgnoreEntities(ignoredEntities);
|
||||||
|
rightTeleporter.setIgnoreEntities(ignoredEntities);
|
||||||
} else if (channel === 'Hifi-Teleport-Ignore-Remove' && !Uuid.isNull(message)) {
|
} else if (channel === 'Hifi-Teleport-Ignore-Remove' && !Uuid.isNull(message)) {
|
||||||
var removeIndex = ignoredEntities.indexOf(message);
|
var removeIndex = ignoredEntities.indexOf(message);
|
||||||
if (removeIndex > -1) {
|
if (removeIndex > -1) {
|
||||||
ignoredEntities.splice(removeIndex, 1);
|
ignoredEntities.splice(removeIndex, 1);
|
||||||
setIgnoreEntities();
|
leftTeleporter.setIgnoreEntities(ignoredEntities);
|
||||||
|
rightTeleporter.setIgnoreEntities(ignoredEntities);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue