// // raffleWheel.js // // Created by Rebecca Stankus on 07/05/2018 // Copyright High Fidelity 2018 // // Licensed under the Apache 2.0 License // See accompanying license file or http://apache.org/ // /* global Avatar */ (function() { var ANGULAR_VELOCITY = { x: 0, y: 0, z: 10 }; var ANGULAR_VELOCITY_CHECK_MS = 100; var SEARCH_RADIUS = 1000; var ANGULAR_VELOCITY_DECREMENT = 0.1; var _this; var Wheel = function() { _this = this; }; Wheel.prototype = { interval: null, angularVelocityLimit: 10, nameText: null, avatarList: null, listCounter: 0, remotelyCallable: ['spin'], preload: function(entityID) { _this.entityID = entityID; }, mousePressOnEntity: function(entityID, mouseEvent) { _this.angularVelocityLimit = 10; var position = Entities.getEntityProperties(_this.entityID, 'position').position; _this.avatarList = AvatarList.getAvatarsInRange(position, SEARCH_RADIUS); _this.nameText = Entities.findEntitiesByName("Raffle Wheel Winner", position, 1, true); print("nameText: ", _this.nameText); Entities.editEntity(_this.entityID, { angularVelocity: ANGULAR_VELOCITY }); _this.interval = Script.setInterval(function() { var currentAngularVelocity = Entities.getEntityProperties(_this.entityID, 'angularVelocity').angularVelocity; if (currentAngularVelocity.z === 0) { if (_this.interval) { Script.clearInterval(_this.interval); } } else if (currentAngularVelocity.z <= _this.angularVelocityLimit) { var avatar = AvatarList.getAvatar(_this.avatarList[_this.listCounter]); Entities.editEntity("{af10c0a8-a7ea-4746-abe6-ff8d52ca0981}", { text: avatar.sessionDisplayName }); _this.listCounter += 1; _this.listCounter = _this.listCounter >= _this.avatarList.length ? 0 : _this.listCounter; _this.angularVelocityLimit -= ANGULAR_VELOCITY_DECREMENT; } }, ANGULAR_VELOCITY_CHECK_MS); }, unload: function(entityID) { if (_this.interval) { Script.clearInterval(_this.interval); } } }; return new Wheel(); });