-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsurrender.menu.js
More file actions
32 lines (31 loc) · 919 Bytes
/
surrender.menu.js
File metadata and controls
32 lines (31 loc) · 919 Bytes
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
import eventManager from 'src/utils/eventManager.js';
import { global } from 'src/utils/global.js';
import onPage from 'src/utils/onPage.js';
import * as menu from 'src/utils/menu.js';
import Translation from 'src/structures/constants/translation.ts';
onPage('Game', () => {
// Unbind the "surrender" hotkey
eventManager.on('jQuery', () => {
$(document).off('keyup');
});
function canSurrender() {
return global('turn') >= 5;
}
// Add the "surrender" menu button
menu.addButton({
text: Translation.Menu('surrender'),
enabled: canSurrender,
top: true,
note: () => {
if (!canSurrender()) {
return Translation.Menu('surrender.note');
}
return undefined;
},
action: () => {
const socket = global('socketGame');
if (socket.readyState !== WebSocket.OPEN) return;
socket.send(JSON.stringify({ action: 'surrender' }));
},
});
});