From 9dd91ea31e89c49a57b23371f3db8bc2533a1108 Mon Sep 17 00:00:00 2001 From: Liv Erickson Date: Fri, 23 Mar 2018 11:39:44 -0700 Subject: [PATCH 1/4] style fixes and fix for grid color changes not applying --- scripts/system/libraries/gridTool.js | 110 ++++++++++++++------------- 1 file changed, 57 insertions(+), 53 deletions(-) diff --git a/scripts/system/libraries/gridTool.js b/scripts/system/libraries/gridTool.js index 19d4417a12..3968c9376c 100644 --- a/scripts/system/libraries/gridTool.js +++ b/scripts/system/libraries/gridTool.js @@ -1,16 +1,8 @@ var GRID_CONTROLS_HTML_URL = Script.resolvePath('../html/gridControls.html'); -Grid = function(opts) { +Grid = function (opts) { var that = {}; - - var colors = [ - { red: 0, green: 0, blue: 0 }, - { red: 255, green: 255, blue: 255 }, - { red: 255, green: 0, blue: 0 }, - { red: 0, green: 255, blue: 0 }, - { red: 0, green: 0, blue: 255 }, - ]; - var colorIndex = 0; + var gridColor = { red: 0, green: 0, blue: 0 }; var gridAlpha = 0.6; var origin = { x: 0, y: +MyAvatar.getJointPosition('LeftToeBase').y.toFixed(1) + 0.1, z: 0 }; var scale = 500; @@ -28,58 +20,70 @@ Grid = function(opts) { position: origin, visible: false, drawInFront: false, - color: colors[0], + color: gridColor, alpha: gridAlpha, minorGridEvery: minorGridEvery, - majorGridEvery: majorGridEvery, + majorGridEvery: majorGridEvery }); that.visible = false; that.enabled = false; - that.getOrigin = function() { + that.getOrigin = function () { return origin; - } + }; - that.getMinorIncrement = function() { return minorGridEvery; }; - that.setMinorIncrement = function(value) { + that.getMinorIncrement = function () { + return minorGridEvery; + }; + + that.setMinorIncrement = function (value) { minorGridEvery = value; updateGrid(); - } - that.getMajorIncrement = function() { return majorGridEvery; }; - that.setMajorIncrement = function(value) { + }; + + that.getMajorIncrement = function () { + return majorGridEvery; + }; + + that.setMajorIncrement = function (value) { majorGridEvery = value; updateGrid(); }; - that.getColorIndex = function() { return colorIndex; }; - that.setColorIndex = function(value) { - colorIndex = value; + that.getColor = function () { + return gridColor; + }; + + that.setColor = function (value) { + gridColor = value; updateGrid(); }; - that.getSnapToGrid = function() { return snapToGrid; }; - that.setSnapToGrid = function(value) { + that.getSnapToGrid = function () { + return snapToGrid; + }; + that.setSnapToGrid = function (value) { snapToGrid = value; that.emitUpdate(); }; - that.setEnabled = function(enabled) { + that.setEnabled = function (enabled) { that.enabled = enabled; updateGrid(); - } + }; - that.getVisible = function() { return that.visible; }; - that.setVisible = function(visible, noUpdate) { + that.getVisible = function () { return that.visible; }; + that.setVisible = function (visible, noUpdate) { that.visible = visible; updateGrid(); if (!noUpdate) { that.emitUpdate(); } - } + }; - that.snapToSurface = function(position, dimensions, registration) { + that.snapToSurface = function (position, dimensions, registration) { if (!snapToGrid) { return position; } @@ -97,9 +101,9 @@ Grid = function(opts) { y: origin.y + (registration.y * dimensions.y), z: position.z }; - } + }; - that.snapToGrid = function(position, majorOnly, dimensions, registration) { + that.snapToGrid = function (position, majorOnly, dimensions, registration) { if (!snapToGrid) { return position; } @@ -123,7 +127,7 @@ Grid = function(opts) { return Vec3.sum(Vec3.sum(position, Vec3.multiplyVbyV(registration, dimensions)), origin); } - that.snapToSpacing = function(delta, majorOnly) { + that.snapToSpacing = function (delta, majorOnly) { if (!snapToGrid) { return delta; } @@ -133,14 +137,14 @@ Grid = function(opts) { var snappedDelta = { x: Math.round(delta.x / spacing) * spacing, y: Math.round(delta.y / spacing) * spacing, - z: Math.round(delta.z / spacing) * spacing, + z: Math.round(delta.z / spacing) * spacing }; return snappedDelta; - } + }; - that.setPosition = function(newPosition, noUpdate) { + that.setPosition = function (newPosition, noUpdate) { origin = { x: 0, y: newPosition.y, z: 0 }; updateGrid(); @@ -149,7 +153,7 @@ Grid = function(opts) { } }; - that.emitUpdate = function() { + that.emitUpdate = function () { if (that.onUpdate) { that.onUpdate({ origin: origin, @@ -157,12 +161,12 @@ Grid = function(opts) { majorGridEvery: majorGridEvery, gridSize: halfSize, visible: that.visible, - snapToGrid: snapToGrid, + snapToGrid: snapToGrid }); } }; - that.update = function(data) { + that.update = function (data) { if (data.snapToGrid !== undefined) { snapToGrid = data.snapToGrid; } @@ -183,8 +187,8 @@ Grid = function(opts) { majorGridEvery = data.majorGridEvery; } - if (data.colorIndex !== undefined) { - colorIndex = data.colorIndex; + if (data.gridColor) { + gridColor = data.gridColor; } if (data.gridSize) { @@ -196,7 +200,7 @@ Grid = function(opts) { } updateGrid(true); - } + }; function updateGrid(noUpdate) { Overlays.editOverlay(gridOverlay, { @@ -204,8 +208,8 @@ Grid = function(opts) { visible: that.visible && that.enabled, minorGridEvery: minorGridEvery, majorGridEvery: majorGridEvery, - color: colors[colorIndex], - alpha: gridAlpha, + color: gridColor, + alpha: gridAlpha }); if (!noUpdate) { @@ -217,7 +221,7 @@ Grid = function(opts) { Overlays.deleteOverlay(gridOverlay); } - that.addListener = function(callback) { + that.addListener = function (callback) { that.onUpdate = callback; } @@ -229,7 +233,7 @@ Grid = function(opts) { return that; }; -GridTool = function(opts) { +GridTool = function (opts) { var that = {}; var horizontalGrid = opts.horizontalGrid; @@ -238,19 +242,19 @@ GridTool = function(opts) { var webView = null; webView = Tablet.getTablet("com.highfidelity.interface.tablet.system"); - webView.setVisible = function(value) {}; + webView.setVisible = function (value) { }; - horizontalGrid.addListener(function(data) { + horizontalGrid.addListener(function (data) { webView.emitScriptEvent(JSON.stringify(data)); if (selectionDisplay) { selectionDisplay.updateHandles(); } }); - webView.webEventReceived.connect(function(data) { + webView.webEventReceived.connect(function (data) { try { data = JSON.parse(data); - } catch(e) { + } catch (e) { print("gridTool.js: Error parsing JSON: " + e.name + " data " + data) return; } @@ -260,7 +264,7 @@ GridTool = function(opts) { } else if (data.type == "update") { horizontalGrid.update(data); for (var i = 0; i < listeners.length; i++) { - listeners[i] && listeners[i](data); + [i] && listeners[i](data); } } else if (data.type == "action") { var action = data.action; @@ -278,11 +282,11 @@ GridTool = function(opts) { } }); - that.addListener = function(callback) { + that.addListener = function (callback) { listeners.push(callback); } - that.setVisible = function(visible) { + that.setVisible = function (visible) { webView.setVisible(visible); } From c66badc53c7b8e49a56dbc934cd07eeb528ea840 Mon Sep 17 00:00:00 2001 From: Liv Erickson Date: Fri, 23 Mar 2018 11:42:39 -0700 Subject: [PATCH 2/4] replace accidentally deleted line --- scripts/system/libraries/gridTool.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/system/libraries/gridTool.js b/scripts/system/libraries/gridTool.js index 3968c9376c..a991d66b40 100644 --- a/scripts/system/libraries/gridTool.js +++ b/scripts/system/libraries/gridTool.js @@ -264,7 +264,7 @@ GridTool = function (opts) { } else if (data.type == "update") { horizontalGrid.update(data); for (var i = 0; i < listeners.length; i++) { - [i] && listeners[i](data); + listeners[i] && listeners[i](data); } } else if (data.type == "action") { var action = data.action; From 6c155776535d9175573eec1d34cb396ef8a16c27 Mon Sep 17 00:00:00 2001 From: Liv Erickson Date: Tue, 10 Apr 2018 09:18:54 -0700 Subject: [PATCH 3/4] style fixes for eslint --- scripts/system/libraries/gridTool.js | 60 ++++++++++++++-------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/scripts/system/libraries/gridTool.js b/scripts/system/libraries/gridTool.js index a991d66b40..fe2938326a 100644 --- a/scripts/system/libraries/gridTool.js +++ b/scripts/system/libraries/gridTool.js @@ -1,6 +1,6 @@ var GRID_CONTROLS_HTML_URL = Script.resolvePath('../html/gridControls.html'); -Grid = function (opts) { +Grid = function(opts) { var that = {}; var gridColor = { red: 0, green: 0, blue: 0 }; var gridAlpha = 0.6; @@ -29,52 +29,54 @@ Grid = function (opts) { that.visible = false; that.enabled = false; - that.getOrigin = function () { + that.getOrigin = function() { return origin; }; - that.getMinorIncrement = function () { + that.getMinorIncrement = function() { return minorGridEvery; }; - that.setMinorIncrement = function (value) { + that.setMinorIncrement = function(value) { minorGridEvery = value; updateGrid(); }; - that.getMajorIncrement = function () { + that.getMajorIncrement = function() { return majorGridEvery; }; - that.setMajorIncrement = function (value) { + that.setMajorIncrement = function(value) { majorGridEvery = value; updateGrid(); }; - that.getColor = function () { + that.getColor = function() { return gridColor; }; - that.setColor = function (value) { + that.setColor = function(value) { gridColor = value; updateGrid(); }; - that.getSnapToGrid = function () { + that.getSnapToGrid = function() { return snapToGrid; }; - that.setSnapToGrid = function (value) { + that.setSnapToGrid = function(value) { snapToGrid = value; that.emitUpdate(); }; - that.setEnabled = function (enabled) { + that.setEnabled = function(enabled) { that.enabled = enabled; updateGrid(); }; - that.getVisible = function () { return that.visible; }; - that.setVisible = function (visible, noUpdate) { + that.getVisible = function() { + return that.visible; + }; + that.setVisible = function(visible, noUpdate) { that.visible = visible; updateGrid(); @@ -83,7 +85,7 @@ Grid = function (opts) { } }; - that.snapToSurface = function (position, dimensions, registration) { + that.snapToSurface = function(position, dimensions, registration) { if (!snapToGrid) { return position; } @@ -103,7 +105,7 @@ Grid = function (opts) { }; }; - that.snapToGrid = function (position, majorOnly, dimensions, registration) { + that.snapToGrid = function(position, majorOnly, dimensions, registration) { if (!snapToGrid) { return position; } @@ -125,9 +127,9 @@ Grid = function (opts) { position.z = Math.round(position.z / spacing) * spacing; return Vec3.sum(Vec3.sum(position, Vec3.multiplyVbyV(registration, dimensions)), origin); - } + }; - that.snapToSpacing = function (delta, majorOnly) { + that.snapToSpacing = function(delta, majorOnly) { if (!snapToGrid) { return delta; } @@ -144,7 +146,7 @@ Grid = function (opts) { }; - that.setPosition = function (newPosition, noUpdate) { + that.setPosition = function(newPosition, noUpdate) { origin = { x: 0, y: newPosition.y, z: 0 }; updateGrid(); @@ -153,7 +155,7 @@ Grid = function (opts) { } }; - that.emitUpdate = function () { + that.emitUpdate = function() { if (that.onUpdate) { that.onUpdate({ origin: origin, @@ -166,7 +168,7 @@ Grid = function (opts) { } }; - that.update = function (data) { + that.update = function(data) { if (data.snapToGrid !== undefined) { snapToGrid = data.snapToGrid; } @@ -223,7 +225,7 @@ Grid = function (opts) { that.addListener = function (callback) { that.onUpdate = callback; - } + }; Script.scriptEnding.connect(cleanup); updateGrid(); @@ -233,7 +235,7 @@ Grid = function (opts) { return that; }; -GridTool = function (opts) { +GridTool = function(opts) { var that = {}; var horizontalGrid = opts.horizontalGrid; @@ -244,18 +246,18 @@ GridTool = function (opts) { webView = Tablet.getTablet("com.highfidelity.interface.tablet.system"); webView.setVisible = function (value) { }; - horizontalGrid.addListener(function (data) { + horizontalGrid.addListener(function(data) { webView.emitScriptEvent(JSON.stringify(data)); if (selectionDisplay) { selectionDisplay.updateHandles(); } }); - webView.webEventReceived.connect(function (data) { + webView.webEventReceived.connect(function(data) { try { data = JSON.parse(data); } catch (e) { - print("gridTool.js: Error parsing JSON: " + e.name + " data " + data) + print("gridTool.js: Error parsing JSON: " + e.name + " data " + data); return; } @@ -282,13 +284,13 @@ GridTool = function (opts) { } }); - that.addListener = function (callback) { + that.addListener = function(callback) { listeners.push(callback); - } + }; - that.setVisible = function (visible) { + that.setVisible = function(visible) { webView.setVisible(visible); - } + }; return that; }; From 20ee1690547911038580ba48b166ea02f872a36b Mon Sep 17 00:00:00 2001 From: Liv Erickson Date: Tue, 10 Apr 2018 09:23:14 -0700 Subject: [PATCH 4/4] two more spaces --- scripts/system/libraries/gridTool.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/system/libraries/gridTool.js b/scripts/system/libraries/gridTool.js index fe2938326a..3be6ac0b00 100644 --- a/scripts/system/libraries/gridTool.js +++ b/scripts/system/libraries/gridTool.js @@ -223,7 +223,7 @@ Grid = function(opts) { Overlays.deleteOverlay(gridOverlay); } - that.addListener = function (callback) { + that.addListener = function(callback) { that.onUpdate = callback; }; @@ -244,7 +244,7 @@ GridTool = function(opts) { var webView = null; webView = Tablet.getTablet("com.highfidelity.interface.tablet.system"); - webView.setVisible = function (value) { }; + webView.setVisible = function(value) { }; horizontalGrid.addListener(function(data) { webView.emitScriptEvent(JSON.stringify(data));