-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
206 lines (191 loc) · 6.97 KB
/
Copy pathscript.js
File metadata and controls
206 lines (191 loc) · 6.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
const script = async () => {
await WA.onInit();
await WA.players.configureTracking({
players: true,
movement: false,
});
//////////////////////////////////
///////// Welcome dialog /////////
//////////////////////////////////
let firstTime = true;
let isTrash = false;
let language = 'en';
let helloWorldPopup;
let inZone;
const birthdays = new Map([
['Umair', { month: 2, day: 1 }],
['Hugo', { month: 2, day: 14 }],
['Anton', { month: 2, day: 22 }],
['Darine', { month: 3, day: 20 }],
['Ali', { month: 5, day: 15 }],
['Antoine', { month: 5, day: 26 }],
['Cloe', { month: 7, day: 16 }],
['Alex', { month: 7, day: 22 }],
['Vincent', { month: 8, day: 23 }],
['Vivi', { month: 10, day: 4 }],
['Polina', { month: 11, day: 7 }],
['Polinka', { month: 11, day: 7 }],
['Gregance', { month: 12, day: 17 }],
// ['Gregance', { month: 11, day: 6 }],
]);
const date = new Date();
const userBirthday = birthdays.get(WA.player.name);
const isBirthday = userBirthday && userBirthday.month === (date.getMonth() + 1) && userBirthday.day === date.getDate();
if (isBirthday) {
WA.room.showLayer('birthday');
}
// https://v2.jokeapi.dev/joke/Any?blacklistFlags=racist,sexist
WA.room.onEnterLayer("Trigger/Welcome").subscribe(() => {
inZone = true;
if (firstTime) {
if (isBirthday) {
helloWorldPopup = WA.ui.openPopup("WelcomePopup", `Happy birthday ${WA.player.name}`, []);
} else {
helloWorldPopup = WA.ui.openPopup("WelcomePopup", 'Welcome to Pulsar Systems Office !', []);
}
firstTime = false;
} else {
const availableLanguages = [
{ label: 'English', symbol: 'en' },
{ label: 'French', symbol: 'fr' },
{ label: 'Spanish', symbol: 'es' },
].filter(l => l.symbol !== language);
const buttons = [...availableLanguages.map(l => ({
label: l.label,
className: "primary",
callback: (popup) => {
language = l.symbol;
popup.close();
}
})), {
label: isTrash ? 'Soft mode' : 'Trash mode',
className: "primary",
callback: (popup) => {
isTrash = !isTrash;
popup.close();
}
}];
fetch(`https://v2.jokeapi.dev/joke/Any?lang=${language}&blacklistFlags=${isTrash ? '' : 'racist,sexist,explicit'}`)
.then(d => d.json())
.then(res => {
if (inZone) {
if (res.type === 'twopart') {
helloWorldPopup = WA.ui.openPopup("WelcomePopup", res.setup, []);
setTimeout(() => {
helloWorldPopup.close();
if (inZone) {
helloWorldPopup = WA.ui.openPopup("WelcomePopup", res.delivery, buttons);
}
}, 4000);
} else {
helloWorldPopup = WA.ui.openPopup("WelcomePopup", res.joke, buttons);
}
}
});
}
});
WA.room.onLeaveLayer("Trigger/Welcome").subscribe(() => {
inZone = false;
if (isBirthday) {
WA.room.hideLayer('birthday');
}
helloWorldPopup.close();
});
//////////////////////////////////
////////////// Admin /////////////
//////////////////////////////////
const admins = ['Gregance'];
const happyBirthdaySound = WA.sound.loadSound('music/happy-birthday.mp3');
if (admins.includes(WA.player.name)) {
WA.ui.registerMenuCommand('Happy birthday', {
callback: () => {
happyBirthdaySound.play({});
WA.player.state.saveVariable("HappyBirthdaySong", true, {
public: true,
persist: false,
scope: "room",
});
}
});
WA.ui.registerMenuCommand('Happy birthday stop', {
callback: () => {
happyBirthdaySound.stop();
WA.player.state.saveVariable("HappyBirthdaySong", false, {
public: true,
persist: false,
scope: "room",
});
}
});
WA.ui.registerMenuCommand('Dancer', {
callback: () => {
WA.room.showLayer('dancer');
WA.room.showLayer('dancerFloor');
WA.player.state.saveVariable("Dancer", true, {
public: true,
persist: false,
scope: "room",
});
}
});
WA.ui.registerMenuCommand('Dancer Stop', {
callback: () => {
WA.room.hideLayer('dancer');
WA.room.hideLayer('dancerFloor');
WA.player.state.saveVariable("Dancer", false, {
public: true,
persist: false,
scope: "room",
});
}
});
}
WA.players.onVariableChange("HappyBirthdaySong").subscribe((event) => {
if (event.value) {
happyBirthdaySound.play({});
} else {
happyBirthdaySound.stop();
}
});
WA.players.onVariableChange("Dancer").subscribe((event) => {
if (event.value) {
WA.room.showLayer('dancer');
WA.room.showLayer('dancerFloor');
} else {
WA.room.hideLayer('dancer');
WA.room.hideLayer('dancerFloor');
}
});
//////////////////////////////////
///////////// Jukebox ////////////
//////////////////////////////////
const jukebox = WA.room.area.create({
name: 'Jukebox',
x: 1146,
y: 764,
width: 652,
height: 235,
});
WA.players.onVariableChange("Jukebox").subscribe((event) => {
console.log('Jukebox change = ', event.value);
// Apply update to other users
jukebox.setProperty('playAudio', event.value);
if (!event.value) {
WA.room.hideLayer("disco");
}
});
WA.room.area.onLeave("Jukebox").subscribe(() => {
jukebox.setProperty('playAudio', undefined);
});
/*WA.players.onVariableChange("Disco").subscribe((event) => {
// Apply update to other users
WA.room.showLayer("disco");
timeoutDisco && clearTimeout(timeoutDisco);
timeoutDisco = setTimeout(() => {
WA.room.hideLayer("disco");
timeoutDisco = undefined;
}, 20000);
});*/
// The rest is managed in dialog-jukebox.html
}
script().then();