-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
67 lines (59 loc) · 2.04 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
57
58
59
60
61
62
63
64
65
66
67
// https://github.com/FranckFreiburger/vue3-sfc-loader
// https://github.com/FranckFreiburger/vue3-sfc-loader/blob/main/docs/examples.md#use-sfc-custom-blocks-for-i18n
import ca from '/OBSEA/lang/ca.js';
import en from '/OBSEA/lang/en.js';
import es from '/OBSEA/lang/es.js';
// Load classes
// SceneManager
import SceneManager from "/OBSEA/Components/SceneManager.js"
window.SceneManager = SceneManager;
// DataManager
import DataManager from "/OBSEA/data/DataManager.js"
window.DataManager = DataManager;
// Declare translations
const i18n = VueI18n.createI18n({
// https://vue-i18n.intlify.dev/guide/essentials/fallback.html#explicit-fallback-with-one-locale
silentTranslationWarn: true,
silentFallbackWarn: true,
missingWarn: false,
fallbackWarn: false,
});
// Declare event emitter
// https://github.com/developit/mitt
window.eventBus = window.mitt();
const options = {
moduleCache: { vue: Vue },
async getFile(url) {
const res = await fetch(url);
if (!res.ok)
throw Object.assign(new Error(res.statusText + ' ' + url), { res });
return {
getContentData: asBinary => asBinary ? res.arrayBuffer() : res.text(),
}
},
addStyle: (textContent) => {
const style = Object.assign(document.createElement('style'), { textContent });
const ref = document.head.getElementsByTagName('style')[0] || null;
document.head.insertBefore(style, ref);
},
customBlockHandler(block, filename, options) {
if (block.type !== 'i18n')
return
const messages = JSON.parse(block.content);
for (let locale in messages)
i18n.global.mergeLocaleMessage(locale, messages[locale]);
}
}
const { loadModule } = window['vue3-sfc-loader'];
const app = Vue.createApp({
components: {
'app-manager': Vue.defineAsyncComponent(() => loadModule('/OBSEA/Components/AppManager.vue', options)),
},
template: '<app-manager></app-manager>'
});
// Translations
i18n.global.mergeLocaleMessage('ca', ca);
i18n.global.mergeLocaleMessage('en', en);
i18n.global.mergeLocaleMessage('es', es);
app.use(i18n);
app.mount(document.body);