From 156f186e49e209c24f0d9971f86744bc012632b5 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 18 Mar 2016 18:28:59 -0700 Subject: [PATCH] fixed bugs --- .../cuckooClockMinuteHandEntityScript.js | 39 +++++-- .../DomainContent/Home/cuckooClock/wrapper.js | 104 +++++++++++------- .../DomainContent/Home/reset.js | 21 +--- 3 files changed, 99 insertions(+), 65 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/cuckooClock/cuckooClockMinuteHandEntityScript.js b/unpublishedScripts/DomainContent/Home/cuckooClock/cuckooClockMinuteHandEntityScript.js index eb9154f410..3190d735a0 100644 --- a/unpublishedScripts/DomainContent/Home/cuckooClock/cuckooClockMinuteHandEntityScript.js +++ b/unpublishedScripts/DomainContent/Home/cuckooClock/cuckooClockMinuteHandEntityScript.js @@ -24,13 +24,19 @@ function startUpdate() { print("EBL Start CLOCK Update") - //when the baton is claimed; - // print('trying to claim the object' + _entityID) + //when the baton is claimed; + // print('trying to claim the object' + _entityID) iOwn = true; connected = true; + + + _this.updateSecondHandForOwnersLocalTime(); + Script.update.connect(_this.update); } + + function stopUpdateAndReclaim() { //when the baton is released; print('EBL I released the object ' + _this.entityID) @@ -55,16 +61,32 @@ return; } _this.clockBody = _this.userData.clockBody; + _this.secondHand = _this.userData.secondHand; // One winner for each entity - if(Entities.canRez() && Entities.canAdjustLocks){ + if (Entities.canRez() && Entities.canAdjustLocks) { print("EBL I HAVE EDIT RIGHTS, SO SET UP BATON!"); baton = virtualBaton({ batonName: "io.highfidelity.cuckooClock:" + _this.entityID }); stopUpdateAndReclaim(); } - + + }, + + updateSecondHandForOwnersLocalTime: function() { + // We are taking over so make sure to update our second hand to reflect local time + if (!_this.secondHand) { + print("WE DONT HAVE A SECOND HAND! RETURNING"); + return; + } + + var DEGREES_FOR_SECOND = 6; + var myDate = new Date(); + var seconds = myDate.getSeconds(); + secondRollDegrees = -seconds * DEGREES_FOR_SECOND; + Entities.editEntity(_this.secondHand, {rotation: Quat.fromPitchYawRollDegrees(0, 0, secondRollDegrees)}); + }, unload: function() { @@ -90,7 +112,7 @@ // if (seconds === 0 && minutes === 0) { // _this.popCuckooOut(); // } - if (seconds % 15 === 0) { + if (seconds % 15 === 0) { _this.popCuckooOut(); } @@ -100,8 +122,11 @@ // We are at the top of the hour! _this.position = Entities.getEntityProperties(_this.entityID, "position").position; print("EBL POP CUCKOO CLOCK!!!!!!!!!!!"); - if(!_this.cuckooSoundInjector) { - _this.cuckooSoundInjector = Audio.playSound(_this.cuckooSound, {position: _this.position, volume: _this.CUCKOO_SOUND_VOLUME}); + if (!_this.cuckooSoundInjector) { + _this.cuckooSoundInjector = Audio.playSound(_this.cuckooSound, { + position: _this.position, + volume: _this.CUCKOO_SOUND_VOLUME + }); } else { _this.cuckooSoundInjector.stop(); _this.cuckooSoundInjector.restart(); diff --git a/unpublishedScripts/DomainContent/Home/cuckooClock/wrapper.js b/unpublishedScripts/DomainContent/Home/cuckooClock/wrapper.js index 5ceb2f2f88..52817da1ad 100644 --- a/unpublishedScripts/DomainContent/Home/cuckooClock/wrapper.js +++ b/unpublishedScripts/DomainContent/Home/cuckooClock/wrapper.js @@ -38,6 +38,11 @@ MyCuckooClock = function(spawnPosition, spawnRotation) { y: 1.3662, z: 0.8181 }, + userData: JSON.stringify({ + hifiHomeKey: { + reset: true + } + }) }) var clockFaceOffset = { @@ -56,7 +61,13 @@ MyCuckooClock = function(spawnPosition, spawnRotation) { x: 0.2397, y: 0.2402, z: 0.0212 - } + }, + userData: JSON.stringify({ + hifiHomeKey: { + reset: true + } + }) + }); // CLOCK HANDS @@ -100,7 +111,52 @@ MyCuckooClock = function(spawnPosition, spawnRotation) { y: 0.0982, z: 0.0024 }, - // script: SCRIPT_URL + userData: JSON.stringify({ + hifiHomeKey: { + reset: true + } + }) + }); + + + // **************** SECOND HAND ********************* + var DEGREES_FOR_SECOND = 6; + var seconds = myDate.getSeconds(); + secondRollDegrees = -seconds * DEGREES_FOR_SECOND; + var ANGULAR_ROLL_SPEED_SECOND_RADIANS = 0.10472 + clockSecondHand = Entities.addEntity({ + type: "Box", + parentID: clockBody, + // modelURL: CLOCK_SECOND_HAND_URL, + name: "home_model_clockSecondHand", + position: Vec3.sum(clockFacePosition, clockHandOffset), + dimensions: { + x: 0.00263, + y: 0.0982, + z: 0.0024 + }, + color: { + red: 200, + green: 10, + blue: 200 + }, + registrationPoint: { + x: 0.5, + y: 0.05, + z: 0.5 + }, + rotation: Quat.fromPitchYawRollDegrees(0, 0, secondRollDegrees), + angularDamping: 0, + angularVelocity: { + x: 0, + y: 0, + z: -ANGULAR_ROLL_SPEED_SECOND_RADIANS + }, + userData: JSON.stringify({ + hifiHomeKey: { + reset: true + } + }) }); @@ -133,44 +189,14 @@ MyCuckooClock = function(spawnPosition, spawnRotation) { z: 0.0032 }, script: MINUTE_HAND_CLOCK_SCRIPT_URL, - userData: JSON.stringify({clockBody: clockBody}) + userData: JSON.stringify({ + clockBody: clockBody, + secondHand: clockSecondHand, + hifiHomeKey: { + reset: true + } + }) }); - // ******************************************* - - var DEGREES_FOR_SECOND = 6; - var seconds = myDate.getSeconds(); - secondRollDegrees = -seconds * DEGREES_FOR_SECOND; - var ANGULAR_ROLL_SPEED_SECOND_RADIANS = 0.10472 - clockSecondHand = Entities.addEntity({ - type: "Box", - parentID: clockBody, - // modelURL: CLOCK_SECOND_HAND_URL, - name: "home_model_clockSecondHand", - position: Vec3.sum(clockFacePosition, clockHandOffset), - dimensions: { - x: 0.00263, - y: 0.0982, - z: 0.0024 - }, - color: { - red: 200, - green: 10, - blue: 200 - }, - registrationPoint: { - x: 0.5, - y: 0.05, - z: 0.5 - }, - rotation: Quat.fromPitchYawRollDegrees(0, 0, secondRollDegrees), - angularDamping: 0, - angularVelocity: { - x: 0, - y: 0, - z: -ANGULAR_ROLL_SPEED_SECOND_RADIANS - } - }); - } createClock(); diff --git a/unpublishedScripts/DomainContent/Home/reset.js b/unpublishedScripts/DomainContent/Home/reset.js index b6f969825e..fb5bc8a0f3 100644 --- a/unpublishedScripts/DomainContent/Home/reset.js +++ b/unpublishedScripts/DomainContent/Home/reset.js @@ -96,7 +96,7 @@ }, 2500); Script.setTimeout(function() { - _this.createKineticEntities(); + // _this.createKineticEntities(); _this.createDynamicEntities(); }, 750) @@ -169,26 +169,9 @@ var cuckooClock = new MyCuckooClock(center); // var doppelganger = new Doppelganger(); - dynamicEntities.push(cuckooClock); - - // dynamicEntities.push(fishTank); - // dynamicEntities.push(tiltMaze); - // dynamicEntities.push(whiteboard); - // dynamicEntities.push(myPlant); - - }, - - cleanupDynamicEntities: function() { - if (dynamicEntities.length === 0) { - return; - } - dynamicEntities.forEach(function(dynamicEntity) { - print('dynamicEntity is:: '+JSON.stringify(dynamicEntity)) - dynamicEntity.cleanup(); - }); - }, + createKineticEntities: function() { var fruitBowl = new FruitBowl({