forked from clach04/tetralegends
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
94 lines (92 loc) · 2.95 KB
/
app.js
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
import menu from './script/menu/menu.js';
import input from './script/input.js';
import settings from './script/settings.js';
import gameHandler from './script/game/game-handler.js';
import * as randomizer from './script/game/modules/randomizers.js';
import {PIECE_SETS} from './script/consts.js';
import $, {hzToMs, framesToMs} from './script/shortcuts.js';
import locale from './script/lang.js';
import sound from './script/sound.js';
input.addMany([
'menuUp',
'menuDown',
'menuLeft',
'menuRight',
'menuOk',
'menuBack',
], [
() => {menu.up();},
() => {menu.down();},
() => {menu.left();},
() => {menu.right();},
() => {menu.ok();},
() => {},
]);
window.onerror = (msg, url, lineNo, columnNo, error) => {
try {
const id = performance.now();
const element = document.createElement('div');
const elementHeader = document.createElement('div');
const elementBody = document.createElement('div');
element.id = `error-${id}`;
elementHeader.id = `error-header-${id}`;
elementBody.id = `error-body-${id}`;
element.classList.add('error');
elementHeader.classList.add('url');
elementBody.classList.add('msg');
elementHeader.textContent = `${url} @ ${lineNo}`;
elementBody.textContent = msg;
element.appendChild(elementHeader);
element.appendChild(elementBody);
element.onclick = () => {
element.parentNode.removeChild(element);
};
$('#error-stack').appendChild(element);
sound.playMenuSe('error');
} catch (e) {
// We don't want an infinite loop of errors
console.log(e);
}
};
document.addEventListener('DOMContentLoaded', () => {
settings.load();
sound.loadMenu();
sound.loadMenuVoice();
sound.loadBgm(['menu'], 'menu');
menu.isLocked = true;
locale.loadLang(settings.settings.language)
.then((test) => {
locale.updateFonts();
locale.updateTitle();
$('#press-container').innerHTML = locale.getString('ui', 'pressKeyboardKey', ['<img src="img/ui/keyboard-enter.svg" class="press-key">']);
$('#press-container').classList.remove('hidden');
window.onblur = () => {
try {
gameHandler.game.pause();
} catch (error) {
// game isn't running yet; no big deal
} finally {
Howler.volume(0);
}
};
const menuOpenTest = (e) => {
if (e.code === 'Enter') {
menuOpen();
}
};
const menuOpen = (e) => {
$('#title-container').classList.add('hidden');
sound.playMenuSe('select');
menu.load('root');
menu.show();
sound.playBgm(['menu'], 'menu');
document.removeEventListener('keydown', menuOpenTest);
document.removeEventListener('mousedown', menuOpen);
};
document.addEventListener('keydown', menuOpenTest);
document.addEventListener('mousedown', menuOpen);
window.onfocus = () => {
Howler.volume(1);
};
});
});