Fix grid controls not updateable

This commit is contained in:
Ryan Huffman 2014-11-18 09:52:00 -08:00
parent 62471c90e3
commit c39bd362b7

View file

@ -12,14 +12,13 @@
{ red: 0, green: 0, blue: 255 }, { red: 0, green: 0, blue: 255 },
]; ];
posY = document.getElementById("horiz-y"); elPosY = document.getElementById("horiz-y");
minorSpacing = document.getElementById("minor-spacing"); elMinorSpacing = document.getElementById("minor-spacing");
majorSpacing = document.getElementById("major-spacing"); elMajorSpacing = document.getElementById("major-spacing");
gridOn = document.getElementById("grid-on"); elSnapToGrid = document.getElementById("snap-to-grid");
snapToGrid = document.getElementById("snap-to-grid"); elHorizontalGridVisible = document.getElementById("horiz-grid-visible");
hGridVisible = document.getElementById("horiz-grid-visible"); elMoveToSelection = document.getElementById("move-to-selection");
bMoveToSelection = document.getElementById("move-to-selection"); elMoveToAvatar = document.getElementById("move-to-avatar");
bMoveToAvatar = document.getElementById("move-to-avatar");
if (window.EventBridge !== undefined) { if (window.EventBridge !== undefined) {
EventBridge.scriptEventReceived.connect(function(data) { EventBridge.scriptEventReceived.connect(function(data) {
@ -27,27 +26,27 @@
if (data.origin) { if (data.origin) {
var origin = data.origin; var origin = data.origin;
posY.value = origin.y; elPosY.value = origin.y.toFixed(2);
} }
if (data.minorGridSpacing) { if (data.minorGridSpacing) {
minorSpacing.value = data.minorGridSpacing; elMinorSpacing.value = data.minorGridSpacing;
} }
if (data.majorGridEvery) { if (data.majorGridEvery) {
majorSpacing.value = data.majorGridEvery; elMajorSpacing.value = data.majorGridEvery;
} }
if (data.gridColor) { if (data.gridColor) {
gridColor = data.gridColor; gridColor = data.gridColor;
} }
if (data.snapToGrid !== undefined) { if (data.elSnapToGrid !== undefined) {
snapToGrid.checked = data.snapToGrid == true; elSnapToGrid.checked = data.elSnapToGrid == true;
} }
if (data.visible !== undefined) { if (data.visible !== undefined) {
hGridVisible.checked = data.visible == true; elHorizontalGridVisible.checked = data.visible == true;
} }
}); });
@ -55,29 +54,31 @@
EventBridge.emitWebEvent(JSON.stringify({ EventBridge.emitWebEvent(JSON.stringify({
type: "update", type: "update",
origin: { origin: {
y: posY.value, y: elPosY.value,
}, },
minorGridSpacing: minorSpacing.value, minorGridSpacing: elMinorSpacing.value,
majorGridEvery: majorSpacing.value, majorGridEvery: elMajorSpacing.value,
gridColor: gridColor, gridColor: gridColor,
snapToGrid: snapToGrid.checked, elSnapToGrid: elSnapToGrid.checked,
visible: hGridVisible.checked, visible: elHorizontalGridVisible.checked,
})); }));
} }
} }
document.addEventListener("input", emitUpdate); elPosY.addEventListener("change", emitUpdate);
hGridVisible.addEventListener("change", emitUpdate); elMinorSpacing.addEventListener("change", emitUpdate);
snapToGrid.addEventListener("change", emitUpdate); elMajorSpacing.addEventListener("change", emitUpdate);
elSnapToGrid.addEventListener("change", emitUpdate);
elHorizontalGridVisible.addEventListener("change", emitUpdate);
bMoveToAvatar.addEventListener("click", function() { elMoveToAvatar.addEventListener("click", function() {
EventBridge.emitWebEvent(JSON.stringify({ EventBridge.emitWebEvent(JSON.stringify({
type: "action", type: "action",
action: "moveToAvatar", action: "moveToAvatar",
})); }));
}); });
bMoveToSelection.addEventListener("click", function() { elMoveToSelection.addEventListener("click", function() {
EventBridge.emitWebEvent(JSON.stringify({ EventBridge.emitWebEvent(JSON.stringify({
type: "action", type: "action",
action: "moveToSelection", action: "moveToSelection",