CR and style fixes

This commit is contained in:
Thijs Wenker 2018-10-09 00:59:53 +02:00
parent 27e0c85b01
commit 776b8b8fc7
5 changed files with 69 additions and 63 deletions

View file

@ -385,7 +385,7 @@ var toolBar = (function () {
Entities.editEntity(entityID, { Entities.editEntity(entityID, {
position: position position: position
}); });
selectionManager._update(); selectionManager._update(false, this);
} else if (dimensionsCheckCount < MAX_DIMENSIONS_CHECKS) { } else if (dimensionsCheckCount < MAX_DIMENSIONS_CHECKS) {
Script.setTimeout(dimensionsCheckFunction, DIMENSIONS_CHECK_INTERVAL); Script.setTimeout(dimensionsCheckFunction, DIMENSIONS_CHECK_INTERVAL);
} }
@ -397,9 +397,9 @@ var toolBar = (function () {
properties.type + " would be out of bounds."); properties.type + " would be out of bounds.");
} }
selectionManager.clearSelections(); selectionManager.clearSelections(this);
entityListTool.sendUpdate(); entityListTool.sendUpdate();
selectionManager.setSelections([entityID]); selectionManager.setSelections([entityID], this);
Window.setFocus(); Window.setFocus();
@ -550,7 +550,7 @@ var toolBar = (function () {
} }
deletedEntityTimer = Script.setTimeout(function () { deletedEntityTimer = Script.setTimeout(function () {
if (entitiesToDelete.length > 0) { if (entitiesToDelete.length > 0) {
selectionManager.removeEntities(entitiesToDelete); selectionManager.removeEntities(entitiesToDelete, this);
} }
entityListTool.removeEntities(entitiesToDelete, selectionManager.selections); entityListTool.removeEntities(entitiesToDelete, selectionManager.selections);
entitiesToDelete = []; entitiesToDelete = [];
@ -866,7 +866,7 @@ var toolBar = (function () {
gridTool.setVisible(false); gridTool.setVisible(false);
grid.setEnabled(false); grid.setEnabled(false);
propertiesTool.setVisible(false); propertiesTool.setVisible(false);
selectionManager.clearSelections(); selectionManager.clearSelections(this);
cameraManager.disable(); cameraManager.disable();
selectionDisplay.disableTriggerMapping(); selectionDisplay.disableTriggerMapping();
tablet.landscape = false; tablet.landscape = false;
@ -994,7 +994,7 @@ function handleOverlaySelectionToolUpdates(channel, message, sender) {
var entity = entityIconOverlayManager.findEntity(data.overlayID); var entity = entityIconOverlayManager.findEntity(data.overlayID);
if (entity !== null) { if (entity !== null) {
selectionManager.setSelections([entity]); selectionManager.setSelections([entity], this);
} }
} }
} }
@ -1141,7 +1141,7 @@ function mouseClickEvent(event) {
if (result === null || result === undefined) { if (result === null || result === undefined) {
if (!event.isShifted) { if (!event.isShifted) {
selectionManager.clearSelections(); selectionManager.clearSelections(this);
} }
return; return;
} }
@ -1193,9 +1193,9 @@ function mouseClickEvent(event) {
} }
if (!event.isShifted) { if (!event.isShifted) {
selectionManager.setSelections([foundEntity]); selectionManager.setSelections([foundEntity], this);
} else { } else {
selectionManager.addEntity(foundEntity, true); selectionManager.addEntity(foundEntity, true, this);
} }
if (wantDebug) { if (wantDebug) {
@ -1493,7 +1493,7 @@ function selectAllEtitiesInCurrentSelectionBox(keepIfTouching) {
} }
} }
} }
selectionManager.setSelections(entities); selectionManager.setSelections(entities, this);
} }
} }
@ -1633,7 +1633,7 @@ function deleteSelectedEntities() {
} }
if (savedProperties.length > 0) { if (savedProperties.length > 0) {
SelectionManager.clearSelections(); SelectionManager.clearSelections(this);
pushCommandForSelections([], savedProperties); pushCommandForSelections([], savedProperties);
entityListTool.deleteEntities(deletedIDs); entityListTool.deleteEntities(deletedIDs);
} }
@ -1650,7 +1650,7 @@ function toggleSelectedEntitiesLocked() {
}); });
} }
entityListTool.sendUpdate(); entityListTool.sendUpdate();
selectionManager._update(); selectionManager._update(false, this);
} }
} }
@ -1664,7 +1664,7 @@ function toggleSelectedEntitiesVisible() {
}); });
} }
entityListTool.sendUpdate(); entityListTool.sendUpdate();
selectionManager._update(); selectionManager._update(false, this);
} }
} }
@ -1861,7 +1861,7 @@ function importSVO(importURL) {
} }
if (isActive) { if (isActive) {
selectionManager.setSelections(pastedEntityIDs); selectionManager.setSelections(pastedEntityIDs, this);
} }
} else { } else {
Window.notifyEditError("Can't import entities: entities would be out of bounds."); Window.notifyEditError("Can't import entities: entities would be out of bounds.");
@ -1909,7 +1909,7 @@ function deleteKey(value) {
} }
function deselectKey(value) { function deselectKey(value) {
if (value === 0) { // on release if (value === 0) { // on release
selectionManager.clearSelections(); selectionManager.clearSelections(this);
} }
} }
function toggleKey(value) { function toggleKey(value) {
@ -2069,7 +2069,7 @@ function applyEntityProperties(data) {
// We might be getting an undo while edit.js is disabled. If that is the case, don't set // We might be getting an undo while edit.js is disabled. If that is the case, don't set
// our selections, causing the edit widgets to display. // our selections, causing the edit widgets to display.
if (isActive) { if (isActive) {
selectionManager.setSelections(selectedEntityIDs); selectionManager.setSelections(selectedEntityIDs, this);
} }
} }
@ -2272,7 +2272,7 @@ var PropertiesTool = function (opts) {
} }
} }
pushCommandForSelections(); pushCommandForSelections();
selectionManager._update(); selectionManager._update(false, this);
} else if (data.type === 'parent') { } else if (data.type === 'parent') {
parentSelectedEntities(); parentSelectedEntities();
} else if (data.type === 'unparent') { } else if (data.type === 'unparent') {
@ -2301,7 +2301,7 @@ var PropertiesTool = function (opts) {
}); });
} }
pushCommandForSelections(); pushCommandForSelections();
selectionManager._update(); selectionManager._update(false, this);
} }
} else if (data.action === "moveAllToGrid") { } else if (data.action === "moveAllToGrid") {
if (selectionManager.hasSelection()) { if (selectionManager.hasSelection()) {
@ -2321,7 +2321,7 @@ var PropertiesTool = function (opts) {
}); });
} }
pushCommandForSelections(); pushCommandForSelections();
selectionManager._update(); selectionManager._update(false, this);
} }
} else if (data.action === "resetToNaturalDimensions") { } else if (data.action === "resetToNaturalDimensions") {
if (selectionManager.hasSelection()) { if (selectionManager.hasSelection()) {
@ -2342,7 +2342,7 @@ var PropertiesTool = function (opts) {
} }
} }
pushCommandForSelections(); pushCommandForSelections();
selectionManager._update(); selectionManager._update(false, this);
} }
} else if (data.action === "previewCamera") { } else if (data.action === "previewCamera") {
if (selectionManager.hasSelection()) { if (selectionManager.hasSelection()) {
@ -2360,7 +2360,7 @@ var PropertiesTool = function (opts) {
}); });
} }
pushCommandForSelections(); pushCommandForSelections();
selectionManager._update(); selectionManager._update(false, this);
} }
} else if (data.action === "reloadClientScripts") { } else if (data.action === "reloadClientScripts") {
if (selectionManager.hasSelection()) { if (selectionManager.hasSelection()) {

View file

@ -13,7 +13,7 @@ const DESCENDING_STRING = '&#x25BE;';
const LOCKED_GLYPH = "&#xe006;"; const LOCKED_GLYPH = "&#xe006;";
const VISIBLE_GLYPH = "&#xe007;"; const VISIBLE_GLYPH = "&#xe007;";
const TRANSPARENCY_GLYPH = "&#xe00b;"; const TRANSPARENCY_GLYPH = "&#xe00b;";
const BAKED_GLYPH = "&#xe01a;" const BAKED_GLYPH = "&#xe01a;";
const SCRIPT_GLYPH = "k"; const SCRIPT_GLYPH = "k";
const BYTES_PER_MEGABYTE = 1024 * 1024; const BYTES_PER_MEGABYTE = 1024 * 1024;
const IMAGE_MODEL_NAME = 'default-image-model.fbx'; const IMAGE_MODEL_NAME = 'default-image-model.fbx';
@ -54,10 +54,10 @@ const COMPARE_ASCENDING = function(a, b) {
} }
return 1; return 1;
} };
const COMPARE_DESCENDING = function(a, b) { const COMPARE_DESCENDING = function(a, b) {
return COMPARE_ASCENDING(b, a); return COMPARE_ASCENDING(b, a);
} };
// List of all entities // List of all entities
var entities = []; var entities = [];
@ -156,22 +156,22 @@ function loaded() {
}; };
elRefresh.onclick = function() { elRefresh.onclick = function() {
refreshEntities(); refreshEntities();
} };
elToggleLocked.onclick = function() { elToggleLocked.onclick = function() {
EventBridge.emitWebEvent(JSON.stringify({ type: 'toggleLocked' })); EventBridge.emitWebEvent(JSON.stringify({ type: 'toggleLocked' }));
} };
elToggleVisible.onclick = function() { elToggleVisible.onclick = function() {
EventBridge.emitWebEvent(JSON.stringify({ type: 'toggleVisible' })); EventBridge.emitWebEvent(JSON.stringify({ type: 'toggleVisible' }));
} };
elExport.onclick = function() { elExport.onclick = function() {
EventBridge.emitWebEvent(JSON.stringify({ type: 'export'})); EventBridge.emitWebEvent(JSON.stringify({ type: 'export'}));
} };
elPal.onclick = function() { elPal.onclick = function() {
EventBridge.emitWebEvent(JSON.stringify({ type: 'pal' })); EventBridge.emitWebEvent(JSON.stringify({ type: 'pal' }));
} };
elDelete.onclick = function() { elDelete.onclick = function() {
EventBridge.emitWebEvent(JSON.stringify({ type: 'delete' })); EventBridge.emitWebEvent(JSON.stringify({ type: 'delete' }));
} };
elFilter.onkeyup = refreshEntityList; elFilter.onkeyup = refreshEntityList;
elFilter.onpaste = refreshEntityList; elFilter.onpaste = refreshEntityList;
elFilter.onchange = onFilterChange; elFilter.onchange = onFilterChange;
@ -227,7 +227,7 @@ function loaded() {
} }
} }
updateSelectedEntities(selection); updateSelectedEntities(selection, false);
EventBridge.emitWebEvent(JSON.stringify({ EventBridge.emitWebEvent(JSON.stringify({
type: "selectionUpdate", type: "selectionUpdate",
@ -289,7 +289,7 @@ function loaded() {
hasScript: entity.hasScript, hasScript: entity.hasScript,
elRow: null, // if this entity has a visible row element assigned to it elRow: null, // if this entity has a visible row element assigned to it
selected: false // if this entity is selected for edit regardless of having a visible row selected: false // if this entity is selected for edit regardless of having a visible row
} };
entities.push(entityData); entities.push(entityData);
entitiesByID[entityData.id] = entityData; entitiesByID[entityData.id] = entityData;
@ -418,7 +418,7 @@ function loaded() {
isBaked: document.querySelector('#entity-isBaked .sort-order'), isBaked: document.querySelector('#entity-isBaked .sort-order'),
drawCalls: document.querySelector('#entity-drawCalls .sort-order'), drawCalls: document.querySelector('#entity-drawCalls .sort-order'),
hasScript: document.querySelector('#entity-hasScript .sort-order'), hasScript: document.querySelector('#entity-hasScript .sort-order'),
} };
function setSortColumn(column) { function setSortColumn(column) {
PROFILE("set-sort-column", function() { PROFILE("set-sort-column", function() {
if (currentSortColumn === column) { if (currentSortColumn === column) {
@ -454,9 +454,6 @@ function loaded() {
} }
function updateSelectedEntities(selectedIDs, autoScroll) { function updateSelectedEntities(selectedIDs, autoScroll) {
// force autoScroll to be a boolean
autoScroll = !!autoScroll;
let notFound = false; let notFound = false;
// reset all currently selected entities and their rows first // reset all currently selected entities and their rows first
@ -663,7 +660,7 @@ function loaded() {
data = JSON.parse(data); data = JSON.parse(data);
if (data.type === "clearEntityList") { if (data.type === "clearEntityList") {
clearEntities(); clearEntities();
} else if (data.type === "selectionUpdate" && data.caller !== "entityList") { } else if (data.type === "selectionUpdate") {
let notFound = updateSelectedEntities(data.selectedIDs, true); let notFound = updateSelectedEntities(data.selectedIDs, true);
if (notFound) { if (notFound) {
refreshEntities(); refreshEntities();

View file

@ -38,7 +38,7 @@ function ListView(elTableBody, elTableScroll, elTableHeaderRow, createRowFunctio
this.lastRowShiftScrollTop = 0; this.lastRowShiftScrollTop = 0;
this.initialize(); this.initialize();
}; }
ListView.prototype = { ListView.prototype = {
getNumRows: function() { getNumRows: function() {
@ -153,9 +153,15 @@ ListView.prototype = {
} }
}, },
scrollToRow(rowIndex, lastRowIndex) { /**
lastRowIndex = lastRowIndex ? lastRowIndex : rowIndex; * Scrolls firstRowIndex with least effort, also tries to make the window include the other selections in case lastRowIndex is set.
let boundingTop = rowIndex * this.rowHeight; * In the case that firstRowIndex and lastRowIndex are already within the visible bounds then nothing will happen.
* @param {number} firstRowIndex - The row that will be scrolled to.
* @param {number} lastRowIndex - The last index of the bound.
*/
scrollToRow: function (firstRowIndex, lastRowIndex) {
lastRowIndex = lastRowIndex ? lastRowIndex : firstRowIndex;
let boundingTop = firstRowIndex * this.rowHeight;
let boundingBottom = (lastRowIndex * this.rowHeight) + this.rowHeight; let boundingBottom = (lastRowIndex * this.rowHeight) + this.rowHeight;
if ((boundingBottom - boundingTop) > this.elTableScroll.clientHeight) { if ((boundingBottom - boundingTop) > this.elTableScroll.clientHeight) {
boundingBottom = boundingTop + this.elTableScroll.clientHeight; boundingBottom = boundingTop + this.elTableScroll.clientHeight;

View file

@ -99,6 +99,10 @@ EntityListTool = function(shouldUseEditTabletApp) {
}; };
selectionManager.addEventListener(function(isSelectionUpdate, caller) { selectionManager.addEventListener(function(isSelectionUpdate, caller) {
if (caller === that) {
// ignore events that we emitted from the entity list itself
return;
}
var selectedIDs = []; var selectedIDs = [];
for (var i = 0; i < selectionManager.selections.length; i++) { for (var i = 0; i < selectionManager.selections.length; i++) {
@ -107,8 +111,7 @@ EntityListTool = function(shouldUseEditTabletApp) {
emitJSONScriptEvent({ emitJSONScriptEvent({
type: 'selectionUpdate', type: 'selectionUpdate',
selectedIDs: selectedIDs, selectedIDs: selectedIDs
caller: caller
}); });
}); });
@ -225,7 +228,7 @@ EntityListTool = function(shouldUseEditTabletApp) {
for (var i = 0; i < ids.length; i++) { for (var i = 0; i < ids.length; i++) {
entityIDs.push(ids[i]); entityIDs.push(ids[i]);
} }
selectionManager.setSelections(entityIDs, "entityList"); selectionManager.setSelections(entityIDs, that);
if (data.focus) { if (data.focus) {
cameraManager.enable(); cameraManager.enable();
cameraManager.focus(selectionManager.worldPosition, cameraManager.focus(selectionManager.worldPosition,

View file

@ -40,7 +40,7 @@ SelectionManager = (function() {
Messages.messageReceived.connect(handleEntitySelectionToolUpdates); Messages.messageReceived.connect(handleEntitySelectionToolUpdates);
} }
// FUNCTION: HANDLE ENTITY SELECTION TOOL UDPATES // FUNCTION: HANDLE ENTITY SELECTION TOOL UPDATES
function handleEntitySelectionToolUpdates(channel, message, sender) { function handleEntitySelectionToolUpdates(channel, message, sender) {
if (channel !== 'entityToolUpdates') { if (channel !== 'entityToolUpdates') {
return; return;
@ -63,7 +63,7 @@ SelectionManager = (function() {
if (wantDebug) { if (wantDebug) {
print("setting selection to " + messageParsed.entityID); print("setting selection to " + messageParsed.entityID);
} }
that.setSelections([messageParsed.entityID]); that.setSelections([messageParsed.entityID], that);
} }
} else if (messageParsed.method === "clearSelection") { } else if (messageParsed.method === "clearSelection") {
if (!SelectionDisplay.triggered() || SelectionDisplay.triggeredHand === messageParsed.hand) { if (!SelectionDisplay.triggered() || SelectionDisplay.triggeredHand === messageParsed.hand) {
@ -147,7 +147,7 @@ SelectionManager = (function() {
that._update(true, caller); that._update(true, caller);
}; };
that.addEntity = function(entityID, toggleSelection) { that.addEntity = function(entityID, toggleSelection, caller) {
if (entityID) { if (entityID) {
var idx = -1; var idx = -1;
for (var i = 0; i < that.selections.length; i++) { for (var i = 0; i < that.selections.length; i++) {
@ -165,7 +165,7 @@ SelectionManager = (function() {
} }
} }
that._update(true); that._update(true, caller);
}; };
function removeEntityByID(entityID) { function removeEntityByID(entityID) {
@ -176,21 +176,21 @@ SelectionManager = (function() {
} }
} }
that.removeEntity = function (entityID) { that.removeEntity = function (entityID, caller) {
removeEntityByID(entityID); removeEntityByID(entityID);
that._update(true); that._update(true, caller);
}; };
that.removeEntities = function(entityIDs) { that.removeEntities = function(entityIDs, caller) {
for (var i = 0, length = entityIDs.length; i < length; i++) { for (var i = 0, length = entityIDs.length; i < length; i++) {
removeEntityByID(entityIDs[i]); removeEntityByID(entityIDs[i]);
} }
that._update(true); that._update(true, caller);
}; };
that.clearSelections = function() { that.clearSelections = function(caller) {
that.selections = []; that.selections = [];
that._update(true); that._update(true, caller);
}; };
that.addChildrenEntities = function(parentEntityID, entityList) { that.addChildrenEntities = function(parentEntityID, entityList) {
@ -985,7 +985,7 @@ SelectionDisplay = (function() {
that.pressedHand = NO_HAND; that.pressedHand = NO_HAND;
that.triggered = function() { that.triggered = function() {
return that.triggeredHand !== NO_HAND; return that.triggeredHand !== NO_HAND;
} };
function pointingAtDesktopWindowOrTablet(hand) { function pointingAtDesktopWindowOrTablet(hand) {
var pointingAtDesktopWindow = (hand === Controller.Standard.RightHand && var pointingAtDesktopWindow = (hand === Controller.Standard.RightHand &&
SelectionManager.pointingAtDesktopWindowRight) || SelectionManager.pointingAtDesktopWindowRight) ||
@ -1032,7 +1032,7 @@ SelectionDisplay = (function() {
that.disableTriggerMapping = function() { that.disableTriggerMapping = function() {
that.triggerClickMapping.disable(); that.triggerClickMapping.disable();
that.triggerPressMapping.disable(); that.triggerPressMapping.disable();
} };
Script.scriptEnding.connect(that.disableTriggerMapping); Script.scriptEnding.connect(that.disableTriggerMapping);
// FUNCTION DEF(s): Intersection Check Helpers // FUNCTION DEF(s): Intersection Check Helpers
@ -1234,7 +1234,7 @@ SelectionDisplay = (function() {
if (wantDebug) { if (wantDebug) {
print(" Trigger SelectionManager::update"); print(" Trigger SelectionManager::update");
} }
SelectionManager._update(); SelectionManager._update(false, that);
if (wantDebug) { if (wantDebug) {
print("=============== eST::MouseMoveEvent END ======================="); print("=============== eST::MouseMoveEvent END =======================");
@ -1299,7 +1299,7 @@ SelectionDisplay = (function() {
lastMouseEvent.isControl = event.isControl; lastMouseEvent.isControl = event.isControl;
lastMouseEvent.isAlt = event.isAlt; lastMouseEvent.isAlt = event.isAlt;
activeTool.onMove(lastMouseEvent); activeTool.onMove(lastMouseEvent);
SelectionManager._update(); SelectionManager._update(false, this);
} }
}; };
@ -1315,7 +1315,7 @@ SelectionDisplay = (function() {
lastMouseEvent.isControl = event.isControl; lastMouseEvent.isControl = event.isControl;
lastMouseEvent.isAlt = event.isAlt; lastMouseEvent.isAlt = event.isAlt;
activeTool.onMove(lastMouseEvent); activeTool.onMove(lastMouseEvent);
SelectionManager._update(); SelectionManager._update(false, this);
} }
}; };
@ -2179,7 +2179,7 @@ SelectionDisplay = (function() {
} }
} }
SelectionManager._update(); SelectionManager._update(false, this);
} }
}); });
} }
@ -2301,7 +2301,7 @@ SelectionDisplay = (function() {
previousPickRay = pickRay; previousPickRay = pickRay;
SelectionManager._update(); SelectionManager._update(false, this);
} }
}); });
} }
@ -2488,7 +2488,7 @@ SelectionDisplay = (function() {
previousPickRay = pickRay; previousPickRay = pickRay;
SelectionManager._update(); SelectionManager._update(false, this);
} }
}); });
} }
@ -2599,7 +2599,7 @@ SelectionDisplay = (function() {
previousPickRay = pickRay; previousPickRay = pickRay;
SelectionManager._update(); SelectionManager._update(false, this);
} }
}); });
} }