forked from delaford/game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
56 lines (45 loc) · 1.48 KB
/
main.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
// Core libraries
import Vue from 'vue';
// 3rd-party libraries
import VueTippy from 'vue-tippy';
// Import Delaford
import Delaford from './Delaford.vue';
import store from './store';
// Vue configuration
Vue.config.productionTip = false;
Vue.config.devtools = process.env.NODE_ENV !== 'production';
// Vue plugins
Vue.use(VueTippy, {
animation: 'fade',
inertia: true,
size: 'small',
theme: 'translucent',
arrow: true,
followCursor: true,
});
// Import game-panes
const files = require.context('./components/game-panes', true, /\.vue$/i);
const utilFiles = require.context('./components/util', true, /\.vue$/i);
files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default));
utilFiles.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], utilFiles(key).default));
// Start the websocket server client-side
if ('WebSocket' in window) {
const wsurl = {
prod: 'wss://play.delaford.com',
dev: `ws://${window.location.hostname}:4000`,
};
const url = process.env.NODE_ENV === 'production' ? wsurl.prod : wsurl.dev;
window.ws = new WebSocket(url);
}
// Add an event listener to close the websocket
// connection right before the browser closes.
window.addEventListener('beforeunload', () => window.ws.close());
// Focus mouse on game-canvas
window.focusOnGame = () => {
document.querySelector('canvas#game-map.main-canvas').focus();
};
/* eslint-disable no-new */
new Vue({
store,
render: h => h(Delaford),
}).$mount('#delaford');