diff --git a/examples/painting/whiteboard/colorIndicatorEntityScript.js b/examples/painting/whiteboard/colorIndicatorEntityScript.js new file mode 100644 index 0000000000..97deb0bc67 --- /dev/null +++ b/examples/painting/whiteboard/colorIndicatorEntityScript.js @@ -0,0 +1,41 @@ +// +// colorIndicatorEntityScript.js +// examples/painting/whiteboard +// +// Created by Eric Levin on 9/21/15. +// Copyright 2015 High Fidelity, Inc. +// + +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +/*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt */ +/*global ColorIndicator */ + +(function() { + + var _this; + ColorIndicator = function() { + _this = this; + }; + + ColorIndicator.prototype = { + + changeColor: function() { + var newColor = Entities.getEntityProperties(this.whiteboard, "userData").currentColor; + Entities.editEntity(this.EntityID, { + color: newColor + }); + }, + + preload: function(entityID) { + this.entityID = entityID; + var props = Entities.getEntityProperties(this.entityID, "userData"); + this.position = props.position; + this.whiteboard = JSON.parse(props.userData).whiteboard; + }, + + }; + + // entity scripts always need to return a newly constructed object of our type + return new ColorIndicator(); +}); \ No newline at end of file diff --git a/examples/painting/whiteboard/whiteboardEntityScript.js b/examples/painting/whiteboard/whiteboardEntityScript.js index 0cfa12746a..f376c4f61c 100644 --- a/examples/painting/whiteboard/whiteboardEntityScript.js +++ b/examples/painting/whiteboard/whiteboardEntityScript.js @@ -210,7 +210,9 @@ this.painting = false; this.strokes = []; this.whitelist = [this.entityID]; - this.strokeColor = JSON.parse(props.userData).currentColor; + var userData = JSON.parse(props.userData); + this.strokeColor = userData.currentColor; + this.colorIndicator = userData.colorIndicator; this.laserPointer = Overlays.addOverlay("circle3d", { color: this.strokeColor, solid: true, diff --git a/examples/painting/whiteboard/whiteboardSpawner.js b/examples/painting/whiteboard/whiteboardSpawner.js index 6a92be3295..2624fba9b2 100644 --- a/examples/painting/whiteboard/whiteboardSpawner.js +++ b/examples/painting/whiteboard/whiteboardSpawner.js @@ -63,7 +63,7 @@ var colorIndicatorDimensions = { z: 0.02 }; scriptURL = Script.resolvePath("colorIndicatorEntityScript.js"); -var colorIndicatorPosition = Vec3.sum(center, {x: 0, y: whiteboardDimensions.y/2, z: 0}); +var colorIndicatorPosition = Vec3.sum(center, {x: 0, y: whiteboardDimensions.y/2 + colorIndicatorDimensions.y/2, z: 0}); var colorIndicatorBox = Entities.addEntity({ type: "Box", color: colors[0], @@ -73,6 +73,8 @@ var colorIndicatorBox = Entities.addEntity({ script: scriptURL }); +Entities.editEntity(whiteboard, {userData: JSON.stringify({currentColor: colors[i], colorIndicator: colorIndicatorBox})} ); + //COLOR BOXES var direction = Quat.getRight(rotation); var colorBoxPosition = Vec3.subtract(center, Vec3.multiply(direction, whiteboardDimensions.x / 2)); @@ -82,7 +84,7 @@ var colorSquareDimensions = { y: 0.1, z: 0.05 }; -colorBoxPosition.y += whiteboardDimensions.y / 2 + colorIndicatorDimensions.y/2 + colorSquareDimensions.y / 2 - 0.01; +colorBoxPosition.y += whiteboardDimensions.y / 2 + colorIndicatorDimensions.y + colorSquareDimensions.y / 2; var spaceBetweenColorBoxes = Vec3.multiply(direction, colorSquareDimensions.x * 2); var scriptURL = Script.resolvePath("colorSelectorEntityScript.js"); for (var i = 0; i < colors.length; i++) { @@ -117,7 +119,7 @@ var blackBox = Entities.addEntity({ userData: JSON.stringify({ whiteboard: whiteboard }) -}) +}); var eraseBoxDimensions = { @@ -159,6 +161,7 @@ function cleanup() { Entities.deleteEntity(whiteboard); Entities.deleteEntity(eraseAllText); Entities.deleteEntity(blackBox); + Entities.deleteEntity(colorIndicatorBox); colorBoxes.forEach(function(colorBox) { Entities.deleteEntity(colorBox); });