Merge pull request #3979 from huffman/rollback-gridtools

Roll gridTool.js back temporarily
This commit is contained in:
Brad Hefta-Gaub 2014-12-18 09:38:46 -08:00
commit fe5af952a4

View file

@ -1,9 +1,3 @@
var SETTING_GRID_VISIBLE = 'gridVisible';
var SETTING_GRID_SNAP_TO_GRID = 'gridSnapToGrid';
var SETTING_GRID_MINOR_WIDTH= 'gridMinorWidth';
var SETTING_GRID_MAJOR_EVERY = 'gridMajorEvery';
var SETTING_GRID_COLOR = 'gridColor';
Grid = function(opts) { Grid = function(opts) {
var that = {}; var that = {};
@ -18,6 +12,9 @@ Grid = function(opts) {
var worldSize = 16384; var worldSize = 16384;
var minorGridWidth = 0.5;
var majorGridWidth = 1.5;
var snapToGrid = false; var snapToGrid = false;
var gridOverlay = Overlays.addOverlay("grid", { var gridOverlay = Overlays.addOverlay("grid", {
@ -26,7 +23,7 @@ Grid = function(opts) {
color: { red: 0, green: 0, blue: 128 }, color: { red: 0, green: 0, blue: 128 },
alpha: 1.0, alpha: 1.0,
rotation: Quat.fromPitchYawRollDegrees(90, 0, 0), rotation: Quat.fromPitchYawRollDegrees(90, 0, 0),
minorGridSpacing: 0.1, minorGridWidth: 0.1,
majorGridEvery: 2, majorGridEvery: 2,
}); });
@ -43,37 +40,16 @@ Grid = function(opts) {
that.getSnapToGrid = function() { return snapToGrid; }; that.getSnapToGrid = function() { return snapToGrid; };
that.setEnabled = function(enabled) { that.setEnabled = function(enabled) {
if (that.enabled != enabled) { that.enabled = enabled;
that.enabled = enabled; updateGrid();
if (enabled) {
if (selectionManager.hasSelection()) {
that.setPosition(selectionManager.getBottomPosition());
} else {
that.setPosition(MyAvatar.position);
}
}
updateGrid();
}
} }
that.setVisible = function(visible, noUpdate) { that.setVisible = function(visible, noUpdate) {
if (visible != that.visible) { that.visible = visible;
that.visible = visible; updateGrid();
updateGrid();
if (visible) { if (!noUpdate) {
if (selectionManager.hasSelection()) { that.emitUpdate();
that.setPosition(selectionManager.getBottomPosition());
} else {
that.setPosition(MyAvatar.position);
}
}
if (!noUpdate) {
that.emitUpdate();
}
} }
} }
@ -205,43 +181,15 @@ Grid = function(opts) {
} }
function cleanup() { function cleanup() {
saveSettings();
Overlays.deleteOverlay(gridOverlay); Overlays.deleteOverlay(gridOverlay);
} }
function loadSettings() {
that.setVisible(Settings.getValue(SETTING_GRID_VISIBLE) == "true", true);
snapToGrid = Settings.getValue(SETTING_GRID_SNAP_TO_GRID) == "true";
minorGridSpacing = parseFloat(Settings.getValue(SETTING_GRID_MINOR_WIDTH), 10);
majorGridEvery = parseInt(Settings.getValue(SETTING_GRID_MAJOR_EVERY), 10);
try {
var newColor = JSON.parse(Settings.getValue(SETTING_GRID_COLOR));
if (newColor.red !== undefined && newColor.green !== undefined && newColor.blue !== undefined) {
gridColor.red = newColor.red;
gridColor.green = newColor.green;
gridColor.blue = newColor.blue;
}
} catch (e) {
}
updateGrid();
}
function saveSettings() {
Settings.setValue(SETTING_GRID_VISIBLE, that.visible);
Settings.setValue(SETTING_GRID_SNAP_TO_GRID, snapToGrid);
Settings.setValue(SETTING_GRID_MINOR_WIDTH, minorGridSpacing);
Settings.setValue(SETTING_GRID_MAJOR_EVERY, majorGridEvery);
Settings.setValue(SETTING_GRID_COLOR, JSON.stringify(gridColor));
}
that.addListener = function(callback) { that.addListener = function(callback) {
that.onUpdate = callback; that.onUpdate = callback;
} }
Script.scriptEnding.connect(cleanup); Script.scriptEnding.connect(cleanup);
updateGrid();
loadSettings();
that.onUpdate = null; that.onUpdate = null;