mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 07:12:40 +02:00
Add stopwatch scripts
This commit is contained in:
parent
fae94b5500
commit
43255f16bf
2 changed files with 74 additions and 0 deletions
20
unpublishedScripts/marketplace/stopwatch/stopwatchClient.js
Normal file
20
unpublishedScripts/marketplace/stopwatch/stopwatchClient.js
Normal file
|
@ -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;
|
||||
};
|
||||
});
|
54
unpublishedScripts/marketplace/stopwatch/stopwatchServer.js
Normal file
54
unpublishedScripts/marketplace/stopwatch/stopwatchServer.js
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
Loading…
Reference in a new issue