overte-HifiExperiments/unpublishedScripts/DomainContent/Home/cuckooClock/cuckooClockMinuteHandEntityScript.js
2016-03-16 17:27:38 -07:00

70 lines
No EOL
2.2 KiB
JavaScript

(function() {
Script.include('../utils.js');
var _this;
var d = new Date();
var h = d.getHours();
h = h % 12;
CuckooClockMinuteHand = function() {
_this = this;
_this.TIME_CHECK_REFRACTORY_PERIOD = 1000;
_this.checkTime = true;
};
CuckooClockMinuteHand.prototype = {
preload: function(entityID) {
_this.entityID = entityID; // this.animation.isRunning = true;
_this.userData = getEntityUserData(entityID);
// print("ANIMATION!!! " + JSON.stringify(_this.animationURL));
if (!_this.userData || !_this.userData.clockBody) {
print("THIS CLOCK HAND IS NOT ATTACHED TO A CLOCK BODY!");
return;
}
_this.clockBody = _this.userData.clockBody;
Entities.editEntity(_this.clockBody, {animation: {running: true}});
Script.update.connect(_this.update);
},
unload: function() {
Script.update.disconnect(_this.update);
},
update: function() {
_this.clockBodyAnimationProps = Entities.getEntityProperties(_this.clockBody, "animation").animation;
if (!_this.clockBodyAnimationProps) {
print("NO CLOCK BODY ANIMATION PROPS! RETURNING");
return;
}
if (_this.checkTime === false) {
print ("We are in our refractory period. Please wait.");
return;
}
var date = new Date();
// Check to see if we are at the top of the hour
var seconds = date.getSeconds();
var minutes = date.getMinutes();
if(seconds === 0 && (minutes === 23|| minutes === 24)) {
// We are at the top of the hour!
print("TOP OF THE HOUR!");
_this.checkTime = false;
Script.setTimeout(function() {
_this.checkTime = true;
_this.print("NOW WE CAN CHECK TIME AGAIN");
}, _this.TIME_CHECK_REFRACTORY_PERIOD);
}
}
};
// entity scripts always need to return a newly constructed object of our type
return new CuckooClockMinuteHand();
});