Add support to tutorial for touch

This commit is contained in:
Ryan Huffman 2016-12-09 15:50:39 -08:00
parent 6fb39080e2
commit 70e6cce113
2 changed files with 148 additions and 69 deletions

View file

@ -227,6 +227,12 @@ function isEntityInLocalTree(entityID) {
/** /**
* *
*/ */
function showEntitiesWithTags(tags) {
for (var i = 0; i < tags.length; ++i) {
showEntitiesWithTag(tags[i]);
}
}
function showEntitiesWithTag(tag) { function showEntitiesWithTag(tag) {
var entities = TUTORIAL_TAG_TO_ENTITY_IDS_MAP[tag]; var entities = TUTORIAL_TAG_TO_ENTITY_IDS_MAP[tag];
if (entities) { if (entities) {
@ -271,9 +277,12 @@ function showEntitiesWithTag(tag) {
}); });
} }
/** function hideEntitiesWithTags(tags) {
* @function hideEntitiesWithTag for (var i = 0; i < tags.length; ++i) {
*/ hideEntitiesWithTag(tags[i]);
}
}
function hideEntitiesWithTag(tag) { function hideEntitiesWithTag(tag) {
var entities = TUTORIAL_TAG_TO_ENTITY_IDS_MAP[tag]; var entities = TUTORIAL_TAG_TO_ENTITY_IDS_MAP[tag];
if (entities) { if (entities) {
@ -313,8 +322,10 @@ function hideEntitiesWithTag(tag) {
}); });
} }
// Return the entity properties for an entity with a given name if it is in our /**
// cached list of entities. Otherwise, return undefined. * Return the entity properties for an entity with a given name if it is in our
* cached list of entities. Otherwise, return undefined.
*/
function getEntityWithName(name) { function getEntityWithName(name) {
debug("Getting entity with name:", name); debug("Getting entity with name:", name);
var entityID = TUTORIAL_NAME_TO_ENTITY_PROPERTIES_MAP[name]; var entityID = TUTORIAL_NAME_TO_ENTITY_PROPERTIES_MAP[name];
@ -338,27 +349,17 @@ function playFirecrackerSound(position) {
}); });
} }
/////////////////////////////////////////////////////////////////////////////// /**
/////////////////////////////////////////////////////////////////////////////// * This disables everything, including:
// // *
// STEP: DISABLE CONTROLLERS // * - The door to leave the tutorial
// // * - Overlays
/////////////////////////////////////////////////////////////////////////////// * - Hand controlelrs
var stepStart = function() { * - Teleportation
this.tag = "start"; * - Advanced movement
} * - Equip and far grab
stepStart.prototype = { * - Away mode
start: function(onFinish) { */
disableEverything();
HMD.requestShowHandControllers();
onFinish();
},
cleanup: function() {
}
};
function disableEverything() { function disableEverything() {
editEntitiesWithTag('door', { visible: true, collisionless: false }); editEntitiesWithTag('door', { visible: true, collisionless: false });
Menu.setIsOptionChecked("Overlays", false); Menu.setIsOptionChecked("Overlays", false);
@ -371,6 +372,11 @@ function disableEverything() {
farGrabEnabled: false, farGrabEnabled: false,
})); }));
setControllerPartLayer('touchpad', 'blank'); setControllerPartLayer('touchpad', 'blank');
setControllerPartLayer('trigger', 'blank');
setControllerPartLayer('joystick', 'blank');
setControllerPartLayer('grip', 'blank');
setControllerPartLayer('button_a', 'blank');
setControllerPartLayer('button_b', 'blank');
setControllerPartLayer('tips', 'blank'); setControllerPartLayer('tips', 'blank');
hideEntitiesWithTag('finish'); hideEntitiesWithTag('finish');
@ -378,6 +384,10 @@ function disableEverything() {
setAwayEnabled(false); setAwayEnabled(false);
} }
/**
* This reenables everything that disableEverything() disables. This can be
* used when leaving the tutorial to ensure that nothing is left disabled.
*/
function reenableEverything() { function reenableEverything() {
editEntitiesWithTag('door', { visible: false, collisionless: true }); editEntitiesWithTag('door', { visible: false, collisionless: true });
Menu.setIsOptionChecked("Overlays", true); Menu.setIsOptionChecked("Overlays", true);
@ -390,11 +400,38 @@ function reenableEverything() {
farGrabEnabled: true, farGrabEnabled: true,
})); }));
setControllerPartLayer('touchpad', 'blank'); setControllerPartLayer('touchpad', 'blank');
setControllerPartLayer('trigger', 'blank');
setControllerPartLayer('joystick', 'blank');
setControllerPartLayer('grip', 'blank');
setControllerPartLayer('button_a', 'blank');
setControllerPartLayer('button_b', 'blank');
setControllerPartLayer('tips', 'blank'); setControllerPartLayer('tips', 'blank');
MyAvatar.shouldRenderLocally = true; MyAvatar.shouldRenderLocally = true;
setAwayEnabled(true); setAwayEnabled(true);
} }
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// //
// STEP: DISABLE CONTROLLERS //
// //
///////////////////////////////////////////////////////////////////////////////
var stepStart = function() {
};
stepStart.prototype = {
start: function(onFinish) {
disableEverything();
HMD.requestShowHandControllers();
onFinish();
},
cleanup: function() {
}
};
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// // // //
@ -404,7 +441,7 @@ function reenableEverything() {
var stepEnableControllers = function() { var stepEnableControllers = function() {
this.shouldLog = false; this.shouldLog = false;
} };
stepEnableControllers.prototype = { stepEnableControllers.prototype = {
start: function(onFinish) { start: function(onFinish) {
reenableEverything(); reenableEverything();
@ -416,6 +453,7 @@ stepEnableControllers.prototype = {
}; };
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// // // //
@ -424,7 +462,6 @@ stepEnableControllers.prototype = {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
var stepOrient = function() { var stepOrient = function() {
this.tag = "orient"; this.tag = "orient";
this.tempTag = "orient-temporary";
} }
stepOrient.prototype = { stepOrient.prototype = {
start: function(onFinish) { start: function(onFinish) {
@ -463,7 +500,6 @@ stepOrient.prototype = {
this.checkIntervalID = null; this.checkIntervalID = null;
} }
editEntitiesWithTag(this.tag, { visible: false, collisionless: 1 }); editEntitiesWithTag(this.tag, { visible: false, collisionless: 1 });
deleteEntitiesWithTag(this.tempTag);
} }
}; };
@ -475,7 +511,7 @@ stepOrient.prototype = {
// STEP: Near Grab // // STEP: Near Grab //
// // // //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
var stepNearGrab = function(name) { var stepNearGrab = function() {
this.tag = "nearGrab"; this.tag = "nearGrab";
this.tempTag = "nearGrab-temporary"; this.tempTag = "nearGrab-temporary";
this.birdIDs = []; this.birdIDs = [];
@ -549,7 +585,7 @@ stepNearGrab.prototype = {
// // // //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
var stepFarGrab = function() { var stepFarGrab = function() {
this.tag = "farGrab; this.tag = "farGrab";
this.tempTag = "farGrab-temporary"; this.tempTag = "farGrab-temporary";
this.finished = true; this.finished = true;
this.birdIDs = []; this.birdIDs = [];
@ -651,11 +687,14 @@ PositionWatcher.prototype = {
// STEP: Equip // // STEP: Equip //
// // // //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
var stepEquip = function() { var stepEquip = function(tutorialManager) {
this.tag = "equip"; const controllerName = tutorialManager.controllerName;
this.tagPart1 = "equip-part1";
this.tagPart2 = "equip-part2"; this.tags = ["equip", "equip-" + controllerName];
this.tagsPart1 = ["equip-part1", "equip-part1-" + controllerName];
this.tagsPart2 = ["equip-part2", "equip-part2-" + controllerName];
this.tempTag = "equip-temporary"; this.tempTag = "equip-temporary";
this.PART1 = 0; this.PART1 = 0;
this.PART2 = 1; this.PART2 = 1;
this.PART3 = 2; this.PART3 = 2;
@ -668,6 +707,7 @@ stepEquip.prototype = {
start: function(onFinish) { start: function(onFinish) {
setControllerPartLayer('tips', 'trigger'); setControllerPartLayer('tips', 'trigger');
setControllerPartLayer('trigger', 'highlight'); setControllerPartLayer('trigger', 'highlight');
Messages.sendLocalMessage('Hifi-Grab-Disable', JSON.stringify({ Messages.sendLocalMessage('Hifi-Grab-Disable', JSON.stringify({
holdEnabled: true, holdEnabled: true,
})); }));
@ -675,8 +715,8 @@ stepEquip.prototype = {
var tag = this.tag; var tag = this.tag;
// Spawn content set // Spawn content set
showEntitiesWithTag(this.tag); showEntitiesWithTags(this.tags);
showEntitiesWithTag(this.tagPart1); showEntitiesWithTags(this.tagsPart1);
this.currentPart = this.PART1; this.currentPart = this.PART1;
@ -733,9 +773,10 @@ stepEquip.prototype = {
Script.setTimeout(function() { Script.setTimeout(function() {
debug("Equip | Starting part 3"); debug("Equip | Starting part 3");
this.currentPart = this.PART3; this.currentPart = this.PART3;
hideEntitiesWithTag(this.tagPart1); hideEntitiesWithTags(this.tagsPart1);
showEntitiesWithTag(this.tagPart2); showEntitiesWithTags(this.tagsPart2);
setControllerPartLayer('trigger', 'normal'); setControllerPartLayer('trigger', 'normal');
setControllerPartLayer('grip', 'highlight');
setControllerPartLayer('tips', 'grip'); setControllerPartLayer('tips', 'grip');
Messages.subscribe('Hifi-Object-Manipulation'); Messages.subscribe('Hifi-Object-Manipulation');
debug("Equip | Finished starting part 3"); debug("Equip | Finished starting part 3");
@ -762,16 +803,19 @@ stepEquip.prototype = {
} }
setControllerPartLayer('tips', 'blank'); setControllerPartLayer('tips', 'blank');
setControllerPartLayer('grip', 'normal');
setControllerPartLayer('trigger', 'normal'); setControllerPartLayer('trigger', 'normal');
this.stopWatchingGun(); this.stopWatchingGun();
this.currentPart = this.COMPLETE; this.currentPart = this.COMPLETE;
if (this.checkCollidesTimer) { if (this.checkCollidesTimer) {
Script.clearInterval(this.checkCollidesTimer); Script.clearInterval(this.checkCollidesTimer);
this.checkColllidesTimer = null;
} }
hideEntitiesWithTag(this.tagPart1);
hideEntitiesWithTag(this.tagPart2); hideEntitiesWithTags(this.tagsPart1);
hideEntitiesWithTag(this.tag); hideEntitiesWithTags(this.tagsPart2);
hideEntitiesWithTags(this.tags);
deleteEntitiesWithTag(this.tempTag); deleteEntitiesWithTag(this.tempTag);
} }
}; };
@ -785,8 +829,8 @@ stepEquip.prototype = {
// STEP: Turn Around // // STEP: Turn Around //
// // // //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
var stepTurnAround = function() { var stepTurnAround = function(tutorialManager) {
this.tag = "turnAround"; this.tags = ["turnAround", "turnAround-" + tutorialManager.controllerName];
this.tempTag = "turnAround-temporary"; this.tempTag = "turnAround-temporary";
this.onActionBound = this.onAction.bind(this); this.onActionBound = this.onAction.bind(this);
@ -795,10 +839,11 @@ var stepTurnAround = function() {
} }
stepTurnAround.prototype = { stepTurnAround.prototype = {
start: function(onFinish) { start: function(onFinish) {
setControllerPartLayer('joystick', 'highlight');
setControllerPartLayer('touchpad', 'arrows'); setControllerPartLayer('touchpad', 'arrows');
setControllerPartLayer('tips', 'arrows'); setControllerPartLayer('tips', 'arrows');
showEntitiesWithTag(this.tag); showEntitiesWithTags(this.tags);
this.numTimesSnapTurnPressed = 0; this.numTimesSnapTurnPressed = 0;
this.numTimesSmoothTurnPressed = 0; this.numTimesSmoothTurnPressed = 0;
@ -851,13 +896,14 @@ stepTurnAround.prototype = {
} catch (e) { } catch (e) {
} }
setControllerPartLayer('joystick', 'normal');
setControllerPartLayer('touchpad', 'blank'); setControllerPartLayer('touchpad', 'blank');
setControllerPartLayer('tips', 'blank'); setControllerPartLayer('tips', 'blank');
if (this.interval) { if (this.interval) {
Script.clearInterval(this.interval); Script.clearInterval(this.interval);
} }
hideEntitiesWithTag(this.tag); hideEntitiesWithTags(this.tags);
deleteEntitiesWithTag(this.tempTag); deleteEntitiesWithTag(this.tempTag);
} }
}; };
@ -871,12 +917,13 @@ stepTurnAround.prototype = {
// STEP: Teleport // // STEP: Teleport //
// // // //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
var stepTeleport = function() { var stepTeleport = function(tutorialManager) {
this.tag = "teleport"; this.tags = ["teleport", "teleport-" + tutorialManager.controllerName];
this.tempTag = "teleport-temporary"; this.tempTag = "teleport-temporary";
} }
stepTeleport.prototype = { stepTeleport.prototype = {
start: function(onFinish) { start: function(onFinish) {
setControllerPartLayer('button_a', 'highlight');
setControllerPartLayer('touchpad', 'teleport'); setControllerPartLayer('touchpad', 'teleport');
setControllerPartLayer('tips', 'teleport'); setControllerPartLayer('tips', 'teleport');
@ -906,17 +953,18 @@ stepTeleport.prototype = {
} }
this.checkCollidesTimer = Script.setInterval(checkCollides.bind(this), 500); this.checkCollidesTimer = Script.setInterval(checkCollides.bind(this), 500);
showEntitiesWithTag(this.tag); showEntitiesWithTags(this.tags);
}, },
cleanup: function() { cleanup: function() {
debug("Teleport | Cleanup"); debug("Teleport | Cleanup");
setControllerPartLayer('button_a', 'normal');
setControllerPartLayer('touchpad', 'blank'); setControllerPartLayer('touchpad', 'blank');
setControllerPartLayer('tips', 'blank'); setControllerPartLayer('tips', 'blank');
if (this.checkCollidesTimer) { if (this.checkCollidesTimer) {
Script.clearInterval(this.checkCollidesTimer); Script.clearInterval(this.checkCollidesTimer);
} }
hideEntitiesWithTag(this.tag); hideEntitiesWithTags(this.tags);
deleteEntitiesWithTag(this.tempTag); deleteEntitiesWithTag(this.tempTag);
} }
}; };
@ -977,6 +1025,15 @@ TutorialManager = function() {
var self = this; var self = this;
if (HMD.isSubdeviceContainingNameAvailable("OculusTouch")) {
this.controllerName = "touch";
} else if (HMD.isHandControllerAvailable("OpenVR")) {
this.controllerName = "vive";
} else {
info("ERROR, no known hand controller found, defaulting to Vive");
this.controllerName = "vive";
}
this.startTutorial = function() { this.startTutorial = function() {
currentStepNum = -1; currentStepNum = -1;
currentStep = null; currentStep = null;
@ -986,15 +1043,15 @@ TutorialManager = function() {
// If Script.generateUUID is not available, default to an empty string. // If Script.generateUUID is not available, default to an empty string.
tutorialID = Script.generateUUID ? Script.generateUUID() : ""; tutorialID = Script.generateUUID ? Script.generateUUID() : "";
STEPS = [ STEPS = [
new stepStart(), new stepStart(this),
new stepOrient(), new stepOrient(this),
new stepNearGrab(), new stepNearGrab(this),
new stepFarGrab(), new stepFarGrab(this),
new stepEquip(), new stepEquip(this),
new stepTurnAround(), new stepTurnAround(this),
new stepTeleport(), new stepTeleport(this),
new stepFinish(), new stepFinish(this),
new stepEnableControllers(), new stepEnableControllers(this),
]; ];
wentToEntryStepNum = STEPS.length; wentToEntryStepNum = STEPS.length;
for (var i = 0; i < STEPS.length; ++i) { for (var i = 0; i < STEPS.length; ++i) {

View file

@ -1,8 +1,25 @@
TUTORIAL_TAG_TO_ENTITY_IDS_MAP = { TUTORIAL_TAG_TO_ENTITY_IDS_MAP = {
"teleport": { "teleport-vive": {
"{7df1abc4-1b7c-4352-985c-f3f6ad8d65b7}": {
"tag": "teleport-vive"
}
},
"teleport-touch": {
"{ff064b9e-7fa4-4693-a386-a67b9f92a948}": { "{ff064b9e-7fa4-4693-a386-a67b9f92a948}": {
"tag": "teleport" "tag": "teleport-touch"
}, }
},
"turnAround-vive": {
"{9b14f224-b2f6-447f-bb86-f5d875cf4c33}": {
"tag": "turnAround-vive"
}
},
"turnAround-touch": {
"{ce74b3ca-d1c7-4980-bd98-2d488095a39e}": {
"tag": "turnAround-touch"
}
},
"teleport": {
"{4478f7b5-d3ac-4213-9a7b-ad8cd69575b8}": { "{4478f7b5-d3ac-4213-9a7b-ad8cd69575b8}": {
"tag": "teleport" "tag": "teleport"
} }
@ -90,11 +107,11 @@ TUTORIAL_TAG_TO_ENTITY_IDS_MAP = {
"tag": "equip-part2" "tag": "equip-part2"
} }
}, },
"turnAround": { //"turnAround": {
"{ce74b3ca-d1c7-4980-bd98-2d488095a39e}": { // "{ce74b3ca-d1c7-4980-bd98-2d488095a39e}": {
"tag": "turnAround" // "tag": "turnAround"
} // }
}, //},
"bothGrab": { "bothGrab": {
"{14792a6e-dc6f-4e7a-843f-4b109b06b5a4}": { "{14792a6e-dc6f-4e7a-843f-4b109b06b5a4}": {
"visible": false, "visible": false,
@ -143,9 +160,14 @@ TUTORIAL_TAG_TO_ENTITY_IDS_MAP = {
"tag": "equip" "tag": "equip"
} }
}, },
"orient": { "orient-vive": {
"{95d233ab-ed0a-46e1-b047-1c542688ef3f}": { "{95d233ab-ed0a-46e1-b047-1c542688ef3f}": {
"tag": "orient" "tag": "orient-vive"
}
},
"orient-oculus": {
"{95d233ab-ed0a-46e1-b047-1c542688ef3f}": {
"tag": "orient-oculus"
} }
} }
}; };