Improve code responsibilities

This commit is contained in:
David Rowe 2018-11-22 11:12:22 +13:00
parent c3a0805db1
commit 5e51ba051a
7 changed files with 127 additions and 104 deletions

View file

@ -12,7 +12,7 @@
LEFT_HAND, RIGHT_HAND, NEAR_GRAB_PICK_RADIUS, DEFAULT_SEARCH_SPHERE_DISTANCE, DISPATCHER_PROPERTIES,
getGrabPointSphereOffset, HMD, MyAvatar, Messages, findHandChildEntities, Picks, PickType, Pointers,
PointerManager, getGrabPointSphereOffset, HMD, MyAvatar, Messages, findHandChildEntities, Picks, PickType, Pointers,
PointerManager, print, Selection, DISPATCHER_HOVERING_LIST, DISPATCHER_HOVERING_STYLE, HIFI_EDIT_MANIPULATION_CHANNEL
PointerManager, print, Selection, DISPATCHER_HOVERING_LIST, DISPATCHER_HOVERING_STYLE
*/
controllerDispatcherPlugins = {};
@ -524,16 +524,17 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
_this.setBlacklist();
}
}
} else if (channel === HIFI_EDIT_MANIPULATION_CHANNEL) {
message = JSON.parse(data);
var tabletIDs = message.action === "startEdit" ?
[HMD.tabletID, HMD.tabletScreenID, HMD.homeButtonID, HMD.homeButtonHighlightID] : [];
if (message.hand === Controller.Standard.LeftHand) {
_this.leftBlacklistTabletIDs = tabletIDs;
_this.setLeftBlacklist();
} else if (message.hand === Controller.Standard.RightHand) {
_this.rightBlacklistTabletIDs = tabletIDs;
_this.setRightBlacklist();
if (action === "tablet") {
var tabletIDs = message.blacklist
? [HMD.tabletID, HMD.tabletScreenID, HMD.homeButtonID, HMD.homeButtonHighlightID] : [];
if (message.hand === LEFT_HAND) {
_this.leftBlacklistTabletIDs = tabletIDs;
_this.setLeftBlacklist();
} else {
_this.rightBlacklistTabletIDs = tabletIDs;
_this.setRightBlacklist();
}
}
}
} catch (e) {
@ -575,7 +576,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
var controllerDispatcher = new ControllerDispatcher();
Messages.subscribe('Hifi-Hand-RayPick-Blacklist');
Messages.subscribe(HIFI_EDIT_MANIPULATION_CHANNEL);
Messages.messageReceived.connect(controllerDispatcher.handleMessage);
Script.scriptEnding.connect(controllerDispatcher.cleanup);

View file

@ -20,6 +20,7 @@ Script.include("/~/system/libraries/utils.js");
var MARGIN = 25;
function InEditMode(hand) {
this.hand = hand;
this.isEditing = false;
this.triggerClicked = false;
this.selectedTarget = null;
this.reticleMinX = MARGIN;
@ -212,6 +213,37 @@ Script.include("/~/system/libraries/utils.js");
enableDispatcherModule("LeftHandInEditMode", leftHandInEditMode);
enableDispatcherModule("RightHandInEditMode", rightHandInEditMode);
var INEDIT_STATUS_CHANNEL = "Hifi-InEdit-Status";
var HAND_RAYPICK_BLACKLIST_CHANNEL = "Hifi-Hand-RayPick-Blacklist";
this.handleMessage = function (channel, data, sender) {
if (channel === INEDIT_STATUS_CHANNEL && sender === MyAvatar.sessionUUID) {
var message;
try {
message = JSON.parse(data);
} catch (e) {
return;
}
switch (message.method) {
case "editing":
if (message.hand === LEFT_HAND) {
leftHandInEditMode.isEditing = message.editing;
} else {
rightHandInEditMode.isEditing = message.editing;
}
Messages.sendLocalMessage(HAND_RAYPICK_BLACKLIST_CHANNEL, JSON.stringify({
action: "tablet",
hand: message.hand,
blacklist: message.editing
}));
break;
}
}
};
Messages.subscribe(INEDIT_STATUS_CHANNEL);
Messages.messageReceived.connect(this.handleMessage);
function cleanup() {
disableDispatcherModule("LeftHandInEditMode");
disableDispatcherModule("RightHandInEditMode");

View file

@ -18,7 +18,8 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
function InVREditMode(hand) {
this.hand = hand;
this.disableModules = false;
this.isAppActive = false;
this.isEditing = false;
this.running = false;
var NO_HAND_LASER = -1; // Invalid hand parameter so that standard laser is not displayed.
this.parameters = makeDispatcherModuleParameters(
@ -66,7 +67,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
};
this.isReady = function (controllerData) {
if (this.disableModules) {
if (this.isAppActive) {
return makeRunningValues(true, [], []);
}
return makeRunningValues(false, [], []);
@ -74,14 +75,13 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
this.run = function (controllerData) {
// Default behavior if disabling is not enabled.
if (!this.disableModules) {
if (!this.isAppActive) {
return this.exitModule();
}
// Tablet stylus.
var tabletStylusInput = getEnabledModuleByName(this.hand === RIGHT_HAND ?
"RightTabletStylusInput" :
"LeftTabletStylusInput");
var tabletStylusInput = getEnabledModuleByName(this.hand === RIGHT_HAND
? "RightTabletStylusInput" : "LeftTabletStylusInput");
if (tabletStylusInput) {
var tabletReady = tabletStylusInput.isReady(controllerData);
if (tabletReady.active) {
@ -90,9 +90,8 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
}
// Tablet surface.
var overlayLaser = getEnabledModuleByName(this.hand === RIGHT_HAND ?
"RightWebSurfaceLaserInput" :
"LeftWebSurfaceLaserInput");
var overlayLaser = getEnabledModuleByName(this.hand === RIGHT_HAND
? "RightWebSurfaceLaserInput" : "LeftWebSurfaceLaserInput");
if (overlayLaser) {
var overlayLaserReady = overlayLaser.isReady(controllerData);
var target = controllerData.rayPicks[this.hand].objectID;
@ -114,8 +113,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
// HUD overlay.
if (!controllerData.triggerClicks[this.hand]) {
var hudLaser = getEnabledModuleByName(this.hand === RIGHT_HAND
? "RightHudOverlayPointer"
: "LeftHudOverlayPointer");
? "RightHudOverlayPointer" : "LeftHudOverlayPointer");
if (hudLaser) {
var hudLaserReady = hudLaser.isReady(controllerData);
if (hudLaserReady.active) {
@ -125,9 +123,8 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
}
// Teleport.
var teleporter = getEnabledModuleByName(this.hand === RIGHT_HAND ?
"RightTeleporter" :
"LeftTeleporter");
var teleporter = getEnabledModuleByName(this.hand === RIGHT_HAND
? "RightTeleporter" : "LeftTeleporter");
if (teleporter) {
var teleporterReady = teleporter.isReady(controllerData);
if (teleporterReady.active) {
@ -145,19 +142,39 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
enableDispatcherModule("LeftHandInVREditMode", leftHandInVREditMode);
enableDispatcherModule("RightHandInVREditMode", rightHandInVREditMode);
var INVREDIT_DISABLER_MESSAGE_CHANNEL = "Hifi-InVREdit-Disabler";
this.handleMessage = function (channel, message, sender) {
if (sender === MyAvatar.sessionUUID && channel === INVREDIT_DISABLER_MESSAGE_CHANNEL) {
if (message === "both") {
leftHandInVREditMode.disableModules = true;
rightHandInVREditMode.disableModules = true;
} else if (message === "none") {
leftHandInVREditMode.disableModules = false;
rightHandInVREditMode.disableModules = false;
var INVREDIT_STATUS_CHANNEL = "Hifi-InVREdit-Status";
var HAND_RAYPICK_BLACKLIST_CHANNEL = "Hifi-Hand-RayPick-Blacklist";
this.handleMessage = function (channel, data, sender) {
if (channel === INVREDIT_STATUS_CHANNEL && sender === MyAvatar.sessionUUID) {
var message;
try {
message = JSON.parse(data);
} catch (e) {
return;
}
switch (message.method) {
case "active":
leftHandInVREditMode.isAppActive = message.active;
rightHandInVREditMode.isAppActive = message.active;
break;
case "editing":
if (message.hand === LEFT_HAND) {
leftHandInVREditMode.isEditing = message.editing;
} else {
rightHandInVREditMode.isEditing = message.editing;
}
Messages.sendLocalMessage(HAND_RAYPICK_BLACKLIST_CHANNEL, JSON.stringify({
action: "tablet",
hand: message.hand,
blacklist: message.editing
}));
break;
}
}
};
Messages.subscribe(INVREDIT_DISABLER_MESSAGE_CHANNEL);
Messages.subscribe(INVREDIT_STATUS_CHANNEL);
Messages.messageReceived.connect(this.handleMessage);
this.cleanup = function () {

View file

@ -9,7 +9,7 @@
/* global Script, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, getControllerJointIndex,
enableDispatcherModule, disableDispatcherModule, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION,
makeDispatcherModuleParameters, Overlays, makeRunningValues, Vec3, resizeTablet, getTabletWidthFromSettings,
NEAR_GRAB_RADIUS, HMD, Uuid, HIFI_EDIT_MANIPULATION_CHANNEL
NEAR_GRAB_RADIUS, HMD, Uuid, getEnabledModuleByName
*/
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
@ -176,14 +176,23 @@ Script.include("/~/system/libraries/utils.js");
return null;
};
this.isEditing = false;
this.setIsEditing = function (editing) {
this.isEditing = editing;
this.isEditing = function () {
var inEditModeModule = getEnabledModuleByName(this.hand === RIGHT_HAND
? "RightHandInEditMode" : "LeftHandInEditMode");
if (inEditModeModule && inEditModeModule.isEditing) {
return true;
}
var inVREditModeModule = getEnabledModuleByName(this.hand === RIGHT_HAND
? "RightHandInVREditMode" : "LeftHandInVREditMode");
if (inVREditModeModule && inVREditModeModule.isEditing) {
return true;
}
return false;
};
this.isReady = function (controllerData) {
if ((controllerData.triggerClicks[this.hand] === 0 && controllerData.secondaryValues[this.hand] === 0)
|| this.isEditing) {
|| this.isEditing()) {
this.robbed = false;
return makeRunningValues(false, [], []);
}
@ -207,7 +216,7 @@ Script.include("/~/system/libraries/utils.js");
this.run = function (controllerData) {
if ((controllerData.triggerClicks[this.hand] === 0 && controllerData.secondaryValues[this.hand] === 0)
|| this.isEditing || !this.isGrabbedThingVisible()) {
|| this.isEditing() || !this.isGrabbedThingVisible()) {
this.endNearParentingGrabOverlay();
this.robbed = false;
return makeRunningValues(false, [], []);
@ -235,28 +244,6 @@ Script.include("/~/system/libraries/utils.js");
enableDispatcherModule("LeftNearParentingGrabOverlay", leftNearParentingGrabOverlay);
enableDispatcherModule("RightNearParentingGrabOverlay", rightNearParentingGrabOverlay);
function onMessageReceived(channel, data, senderID) {
var message;
if (channel !== HIFI_EDIT_MANIPULATION_CHANNEL || senderID !== MyAvatar.sessionUUID) {
return;
}
try {
message = JSON.parse(data);
} catch (e) {
return;
}
if (message.hand === Controller.Standard.LeftHand) {
leftNearParentingGrabOverlay.setIsEditing(message.action === "startEdit");
} else if (message.hand === Controller.Standard.RightHand) {
rightNearParentingGrabOverlay.setIsEditing(message.action === "startEdit");
}
}
Messages.subscribe(HIFI_EDIT_MANIPULATION_CHANNEL);
Messages.messageReceived.connect(onMessageReceived);
function cleanup() {
leftNearParentingGrabOverlay.cleanup();
rightNearParentingGrabOverlay.cleanup();

View file

@ -11,7 +11,7 @@
//
/* global LEFT_HAND, RIGHT_HAND, makeDispatcherModuleParameters, makeRunningValues, enableDispatcherModule,
* disableDispatcherModule, HIFI_EDIT_MANIPULATION_CHANNEL */
* disableDispatcherModule, getEnabledModuleByName */
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
@ -66,9 +66,18 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
100
);
this.isEditing = false;
this.setIsEditing = function (editing) {
this.isEditing = editing;
this.isEditing = function () {
var inEditModeModule = getEnabledModuleByName(this.hand === RIGHT_HAND
? "RightHandInEditMode" : "LeftHandInEditMode");
if (inEditModeModule && inEditModeModule.isEditing) {
return true;
}
var inVREditModeModule = getEnabledModuleByName(this.hand === RIGHT_HAND
? "RightHandInVREditMode" : "LeftHandInVREditMode");
if (inVREditModeModule && inVREditModeModule.isEditing) {
return true;
}
return false;
};
this.isNearTablet = function (controllerData) {
@ -76,7 +85,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
};
this.isReady = function (controllerData) {
if (!this.isEditing && this.isNearTablet(controllerData)) {
if (!this.isEditing() && this.isNearTablet(controllerData)) {
return makeRunningValues(true, [], []);
}
setTabletNearGrabbable(this.hand, false);
@ -84,7 +93,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
};
this.run = function (controllerData) {
if (this.isEditing || !this.isNearTablet(controllerData)) {
if (this.isEditing() || !this.isNearTablet(controllerData)) {
setTabletNearGrabbable(this.hand, false);
return makeRunningValues(false, [], []);
}
@ -116,28 +125,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
HMD.mountedChanged.connect(onDisplayModeChanged);
onDisplayModeChanged();
function onMessageReceived(channel, data, senderID) {
var message;
if (channel !== HIFI_EDIT_MANIPULATION_CHANNEL || senderID !== MyAvatar.sessionUUID) {
return;
}
try {
message = JSON.parse(data);
} catch (e) {
return;
}
if (message.hand === Controller.Standard.LeftHand) {
leftNearTabletHighlight.setIsEditing(message.action === "startEdit");
} else if (message.hand === Controller.Standard.RightHand) {
rightNearTabletHighlight.setIsEditing(message.action === "startEdit");
}
}
Messages.subscribe(HIFI_EDIT_MANIPULATION_CHANNEL);
Messages.messageReceived.connect(onMessageReceived);
function cleanUp() {
disableDispatcherModule("LeftNearTabletHighlight");
disableDispatcherModule("RightNearTabletHighlight");

View file

@ -24,7 +24,6 @@
HAPTIC_PULSE_DURATION:true,
DISPATCHER_HOVERING_LIST:true,
DISPATCHER_HOVERING_STYLE:true,
HIFI_EDIT_MANIPULATION_CHANNEL:true,
Entities,
makeDispatcherModuleParameters:true,
makeRunningValues:true,
@ -150,8 +149,6 @@ DISPATCHER_PROPERTIES = [
"userData"
];
HIFI_EDIT_MANIPULATION_CHANNEL = "HiFi-Edit-Manipulation";
// priority -- a lower priority means the module will be asked sooner than one with a higher priority in a given update step
// activitySlots -- indicates which "slots" must not yet be in use for this module to start
// requiredDataForReady -- which "situation" parts this module looks at to decide if it will start
@ -593,7 +590,6 @@ if (typeof module !== 'undefined') {
TRIGGER_OFF_VALUE: TRIGGER_OFF_VALUE,
TRIGGER_ON_VALUE: TRIGGER_ON_VALUE,
DISPATCHER_HOVERING_LIST: DISPATCHER_HOVERING_LIST,
HIFI_EDIT_MANIPULATION_CHANNEL: HIFI_EDIT_MANIPULATION_CHANNEL,
worldPositionToRegistrationFrameMatrix: worldPositionToRegistrationFrameMatrix
};
}

View file

@ -14,7 +14,7 @@
//
/* global SelectionManager, SelectionDisplay, grid, rayPlaneIntersection, rayPlaneIntersection2, pushCommandForSelections,
getMainTabletIDs, getControllerWorldLocation, TRIGGER_ON_VALUE, HIFI_EDIT_MANIPULATION_CHANNEL */
getMainTabletIDs, getControllerWorldLocation, TRIGGER_ON_VALUE */
const SPACE_LOCAL = "local";
const SPACE_WORLD = "world";
@ -639,6 +639,8 @@ SelectionDisplay = (function() {
ROLL: 2
};
const INEDIT_STATUS_CHANNEL = "Hifi-InEdit-Status";
/**
* The current space mode, this could have been a forced space mode since we do not support multi selection while in
* local space mode.
@ -1118,11 +1120,12 @@ SelectionDisplay = (function() {
activeTool = hitTool;
that.clearDebugPickPlane();
if (activeTool.onBegin) {
Messages.sendLocalMessage(HIFI_EDIT_MANIPULATION_CHANNEL, JSON.stringify({
action: "startEdit",
hand: that.triggeredHand
}));
that.editingHand = that.triggeredHand;
Messages.sendLocalMessage(INEDIT_STATUS_CHANNEL, JSON.stringify({
method: "editing",
hand: that.editingHand === Controller.Standard.LeftHand ? LEFT_HAND : RIGHT_HAND,
editing: true
}));
activeTool.onBegin(event, pickRay, results);
} else {
print("ERROR: entitySelectionTool.mousePressEvent - ActiveTool(" + activeTool.mode + ") missing onBegin");
@ -1271,9 +1274,10 @@ SelectionDisplay = (function() {
if (wantDebug) {
print(" Triggering ActiveTool(" + activeTool.mode + ")'s onEnd");
}
Messages.sendLocalMessage(HIFI_EDIT_MANIPULATION_CHANNEL, JSON.stringify({
action: "finishEdit",
hand: that.editingHand
Messages.sendLocalMessage(INEDIT_STATUS_CHANNEL, JSON.stringify({
method: "editing",
hand: that.editingHand === Controller.Standard.LeftHand ? LEFT_HAND : RIGHT_HAND,
editing: false
}));
that.editingHand = NO_HAND;
activeTool.onEnd(event);