From 43255f16bff768f9f944c668b8b6192d924d06ac Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 19 Jan 2017 16:49:32 -0800 Subject: [PATCH] Add stopwatch scripts --- .../marketplace/stopwatch/stopwatchClient.js | 20 +++++++ .../marketplace/stopwatch/stopwatchServer.js | 54 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 unpublishedScripts/marketplace/stopwatch/stopwatchClient.js create mode 100644 unpublishedScripts/marketplace/stopwatch/stopwatchServer.js diff --git a/unpublishedScripts/marketplace/stopwatch/stopwatchClient.js b/unpublishedScripts/marketplace/stopwatch/stopwatchClient.js new file mode 100644 index 0000000000..2c25231881 --- /dev/null +++ b/unpublishedScripts/marketplace/stopwatch/stopwatchClient.js @@ -0,0 +1,20 @@ +(function() { + this.equipped = false; + this.preload = function(entityID) { + this.entityID = entityID; + this.messageChannel = "STOPWATCH-" + entityID; + print("In stopwatch client", this.messageChannel); + }; + this.startEquip = function(entityID, args) { + this.equipped = true; + }; + this.continueEquip = function(entityID, args) { + var triggerValue = Controller.getValue(args[0] === 'left' ? Controller.Standard.LT : Controller.Standard.RT); + if (triggerValue > 0.5) { + Messages.sendMessage(messageChannel, 'click'); + } + }; + this.releaseEquip = function(entityID, args) { + this.equipped = false; + }; +}); diff --git a/unpublishedScripts/marketplace/stopwatch/stopwatchServer.js b/unpublishedScripts/marketplace/stopwatch/stopwatchServer.js new file mode 100644 index 0000000000..c23813eeaa --- /dev/null +++ b/unpublishedScripts/marketplace/stopwatch/stopwatchServer.js @@ -0,0 +1,54 @@ +(function() { + this.equipped = false; + this.isActive = false; + + this.secondsEntityID = null; + this.minutesEntityID = null; + + this.preload = function(entityID) { + print("Stopwatch Server Preload"); + this.entityID = entityID; + this.messageChannel = "STOPWATCH-" + entityID; + + var userData = Entities.getEntityProperties(this.entityID, 'userData').userData; + var data = JSON.parse(userData); + this.secondsEntityID = data.secondsEntityID; + this.minutesEntityID = data.minutesEntityID; + + this.resetTimer(); + + Messages.subscribe(this.messageChannel); + Messages.messageReceived.connect(this, this.messageReceived); + }; + + this.unload = function() { + print("Stopwatch Server Unload"); + Messages.unsubscribe(this.messageChannel); + Messages.messageReceived.disconnect(this, this.messageReceived); + }; + + this.resetTimer = function() { + Entities.editEntity(this.secondsEntityID, { + rotation: Quat.fromPitchYawRollDegrees(0, 0, 0), + angularVelocity: { x: 0, y: 0, z: 0 }, + }); + this.isActive = false; + }; + this.startTimer = function() { + Entities.editEntity(this.secondsEntityID, { + angularVelocity: { x: 0, y: -6, z: 0 }, + }); + this.isActive = true; + }; + + this.messageReceived = function(channel, sender, message) { + print("Message received", channel, sender, message); + if (channel == this.messageChannel && message === 'click') { + if (this.isActive) { + resetTimer(); + } else { + startTimer(); + } + } + }; +});