simplify code

This commit is contained in:
James B. Pollack 2016-07-08 13:37:59 -07:00
parent 24832df14a
commit 1cda8afa40

View file

@ -133,7 +133,9 @@ function Teleporter() {
}; };
this.enterTeleportMode = function(hand) { this.enterTeleportMode = function(hand) {
print('entered teleport from ' + hand)
if (inTeleportMode === true) { if (inTeleportMode === true) {
print('already in teleport mode so dont enter again')
return; return;
} }
@ -144,12 +146,9 @@ function Teleporter() {
this.teleportHand = hand; this.teleportHand = hand;
this.initialize(); this.initialize();
this.updateConnected = true; this.updateConnected = true;
if (USE_THUMB_AND_TRIGGER_MODE === true) { Script.update.connect(this.update);
Script.update.connect(this.updateForThumbAndTrigger);
} else {
Script.update.connect(this.update);
}
}; };
this.findMidpoint = function(start, end) { this.findMidpoint = function(start, end) {
@ -197,14 +196,12 @@ function Teleporter() {
Script.clearInterval(fadeSphereInterval); Script.clearInterval(fadeSphereInterval);
_this.deleteFadeSphere(); _this.deleteFadeSphere();
fadeSphereInterval = null; fadeSphereInterval = null;
print('sphere done fading out');
return; return;
} }
if (currentFadeSphereOpacity > 0) { if (currentFadeSphereOpacity > 0) {
currentFadeSphereOpacity = currentFadeSphereOpacity - 1; currentFadeSphereOpacity = currentFadeSphereOpacity - 1;
} }
print('setting sphere alpha to: ' + currentFadeSphereOpacity)
Overlays.editOverlay(_this.fadeSphere, { Overlays.editOverlay(_this.fadeSphere, {
alpha: currentFadeSphereOpacity / 10 alpha: currentFadeSphereOpacity / 10
}) })
@ -218,7 +215,6 @@ function Teleporter() {
Script.clearInterval(fadeSphereInterval); Script.clearInterval(fadeSphereInterval);
_this.deleteFadeSphere(); _this.deleteFadeSphere();
fadeSphereInterval = null; fadeSphereInterval = null;
print('sphere done fading in')
return; return;
} }
if (currentFadeSphereOpacity < 1) { if (currentFadeSphereOpacity < 1) {
@ -240,7 +236,6 @@ function Teleporter() {
this.deleteFadeSphere = function() { this.deleteFadeSphere = function() {
if (_this.fadeSphere !== null) { if (_this.fadeSphere !== null) {
print('deleting fade sphere');
Script.update.disconnect(_this.updateFadeSphere); Script.update.disconnect(_this.updateFadeSphere);
Overlays.deleteOverlay(_this.fadeSphere); Overlays.deleteOverlay(_this.fadeSphere);
_this.fadeSphere = null; _this.fadeSphere = null;
@ -260,44 +255,24 @@ function Teleporter() {
} }
this.exitTeleportMode = function(value) { this.exitTeleportMode = function(value) {
if (USE_THUMB_AND_TRIGGER_MODE === true) { print('exiting teleport mode')
Script.update.disconnect(this.updateForThumbAndTrigger);
} else { Script.update.disconnect(this.update);
Script.update.disconnect(this.update);
}
this.teleportHand = null; this.teleportHand = null;
this.updateConnected = null; this.updateConnected = null;
this.disableMappings(); this.disableMappings();
this.turnOffOverlayBeams(); this.turnOffOverlayBeams();
this.enableGrab(); this.enableGrab();
Script.setTimeout(function() { Script.setTimeout(function() {
print('fully exited teleport mode')
inTeleportMode = false; inTeleportMode = false;
}, 100); }, 100);
}; };
this.update = function() { this.update = function() {
if (teleporter.teleportHand === 'left') {
teleporter.leftRay();
if (leftPad.buttonValue === 0) {
_this.teleport();
return;
}
} else {
teleporter.rightRay();
if (rightPad.buttonValue === 0) {
_this.teleport();
return;
}
}
};
this.updateForThumbAndTrigger = function() {
if (teleporter.teleportHand === 'left') { if (teleporter.teleportHand === 'left') {
teleporter.leftRay(); teleporter.leftRay();
@ -526,7 +501,7 @@ function Teleporter() {
}; };
this.teleport = function(value) { this.teleport = function(value) {
print('teleporting : ' + value)
if (this.intersection !== null) { if (this.intersection !== null) {
if (USE_FADE_MODE === true) { if (USE_FADE_MODE === true) {
this.createFadeSphere(); this.createFadeSphere();
@ -648,39 +623,10 @@ var mappingName, teleportMapping;
var TELEPORT_DELAY = 100; var TELEPORT_DELAY = 100;
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(rightPad.buttonPress);
teleportMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(leftPad.buttonPress);
teleportMapping.from(leftPad.down).to(function(value) {
print('left down' + value)
if (value === 1) {
Script.setTimeout(function() {
teleporter.enterTeleportMode('left')
}, TELEPORT_DELAY)
}
});
teleportMapping.from(rightPad.down).to(function(value) {
print('right down' + value)
if (value === 1) {
Script.setTimeout(function() {
teleporter.enterTeleportMode('right')
}, TELEPORT_DELAY)
}
});
}
function registerMappingsWithThumbAndTrigger() {
mappingName = 'Hifi-Teleporter-Dev-' + Math.random();
teleportMapping = Controller.newMapping(mappingName);
teleportMapping.from(Controller.Standard.RT).peek().to(rightTrigger.buttonPress); teleportMapping.from(Controller.Standard.RT).peek().to(rightTrigger.buttonPress);
teleportMapping.from(Controller.Standard.LT).peek().to(leftTrigger.buttonPress); teleportMapping.from(Controller.Standard.LT).peek().to(leftTrigger.buttonPress);
@ -688,24 +634,32 @@ function registerMappingsWithThumbAndTrigger() {
teleportMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(leftPad.buttonPress); teleportMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(leftPad.buttonPress);
teleportMapping.from(leftPad.down).when(leftTrigger.down).to(function(value) { teleportMapping.from(leftPad.down).when(leftTrigger.down).to(function(value) {
print('tel 1')
teleporter.enterTeleportMode('left') teleporter.enterTeleportMode('left')
return;
}); });
teleportMapping.from(rightPad.down).when(rightTrigger.down).to(function(value) { teleportMapping.from(rightPad.down).when(rightTrigger.down).to(function(value) {
print('tel 2')
teleporter.enterTeleportMode('right') teleporter.enterTeleportMode('right')
return;
}); });
teleportMapping.from(leftTrigger.down).when(leftPad.down).to(function(value) { teleportMapping.from(leftTrigger.down).when(leftPad.down).to(function(value) {
print('tel 3')
teleporter.enterTeleportMode('left') teleporter.enterTeleportMode('left')
return;
}); });
teleportMapping.from(rightTrigger.down).when(rightPad.down).to(function(value) { teleportMapping.from(rightTrigger.down).when(rightPad.down).to(function(value) {
print('tel 4')
teleporter.enterTeleportMode('right') teleporter.enterTeleportMode('right')
return;
}); });
} }
if (USE_THUMB_AND_TRIGGER_MODE === true) {
registerMappingsWithThumbAndTrigger(); registerMappings();
} else {
registerMappings();
}
var teleporter = new Teleporter(); var teleporter = new Teleporter();