Skip to content

Commit 286a6e3

Browse files
author
Phil Behreberg
committed
moving script to version folder
1 parent 0db1740 commit 286a6e3

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

TurnClock/0.0.0/TurnClock.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
on("ready", function() {
2+
"use strict";
3+
on("chat:message", function (msg) {
4+
var args;
5+
if (msg.type === "api"){
6+
args = msg.content.split(/\s+/);
7+
if (args[0].match(/^!Clock/i)){
8+
let time = parseInt(args[1],10)||0;
9+
if(time){
10+
let due = _.now()+time*1000,
11+
tokens = _.chain(msg.selected)
12+
.map((o)=>getObj('graphic',o._id))
13+
.reject(_.isUndefined)
14+
.value(),
15+
names = _.map(tokens,(t)=>t.get('name')),
16+
numCheck,
17+
updateClock = ()=>{
18+
let num=Math.ceil((due-_.now())/1000);
19+
if(num>0){
20+
_.map(tokens,(t)=>t.set('status_stopwatch',num));
21+
if (numCheck !== num){
22+
sendChat("", "Turn Time Remaining: " + num);
23+
numCheck = num;
24+
}
25+
_.delay(updateClock,200);
26+
} else {
27+
_.map(tokens,(t)=>t.set('status_stopwatch',false));
28+
sendChat("TurnClock", "!Sound: Buzzer");
29+
sendChat("", "Turn Over!");
30+
}
31+
};
32+
sendChat("TurnClock", "!Sound: Ticking Clock");
33+
sendChat("", "TurnClock Started on: " + names.join(', '));
34+
updateClock();
35+
}
36+
}
37+
}
38+
});
39+
on("chat:message", function (msg) {
40+
if (msg.type === "api" && msg.content === "!Sound: Ticking Clock") {
41+
PlaySound('Sound: Ticking Clock', 6000);
42+
};
43+
if (msg.type === "api" && msg.content === "!Sound: Buzzer") {
44+
PlaySound('Sound: Buzzer', 1000);
45+
};
46+
});
47+
});
48+
49+
function PlaySound(trackname, time) {
50+
var track = findObjs({type: 'jukeboxtrack', title: trackname})[0];
51+
if(track){
52+
if (track.get('playing') === false){
53+
54+
track.set('playing',false);
55+
track.set('softstop',false);
56+
//track.set('volume', 100);
57+
log(track);
58+
if(track) {
59+
track.set('playing',true);
60+
log('playing');
61+
setTimeout(function() {track.set('playing',false);log('stopping sound');}, time);
62+
log(track);
63+
}
64+
else {
65+
log("No track found");
66+
}
67+
}
68+
else {track.set('playing', false);
69+
70+
}}
71+
}

0 commit comments

Comments
 (0)