1
- import { versionsByMinecraftVersion } from 'minecraft-data'
2
- import minecraftInitialDataJson from '../generated/minecraft-initial-data.json'
1
+ // import { versionsByMinecraftVersion } from 'minecraft-data'
2
+ // import minecraftInitialDataJson from '../generated/minecraft-initial-data.json'
3
3
import { AuthenticatedAccount } from './react/ServersListProvider'
4
4
import { setLoadingScreenStatus } from './utils'
5
5
import { downloadSoundsIfNeeded } from './sounds/botSoundSystem'
6
6
import { miscUiState } from './globalState'
7
+ import { options } from './optionsStorage'
8
+ import supportedVersions from './supportedVersions.mjs'
7
9
8
10
export type ConnectOptions = {
9
11
server ?: string
@@ -24,21 +26,39 @@ export type ConnectOptions = {
24
26
viewerWsConnect ?: string
25
27
}
26
28
27
- export const downloadNeededDataOnConnect = async ( version : string ) => {
28
- // todo expose cache
29
- const initialDataVersion = Object . keys ( minecraftInitialDataJson ) [ 0 ] !
30
- if ( version === initialDataVersion ) {
31
- // ignore cache hit
32
- versionsByMinecraftVersion . pc [ initialDataVersion ] ! . dataVersion ! ++
29
+ export const getVersionAutoSelect = ( autoVersionSelect = options . serversAutoVersionSelect ) => {
30
+ if ( autoVersionSelect === 'auto' ) {
31
+ return '1.20.4'
33
32
}
34
- setLoadingScreenStatus ( `Loading data for ${ version } ` )
35
- if ( ! document . fonts . check ( '1em mojangles' ) ) {
33
+ if ( autoVersionSelect === 'latest' ) {
34
+ return supportedVersions . at ( - 1 ) !
35
+ }
36
+ return autoVersionSelect
37
+ }
38
+
39
+ export const downloadMcDataOnConnect = async ( version : string ) => {
40
+ // setLoadingScreenStatus(`Loading data for ${version}`)
41
+ // // todo expose cache
42
+ // // const initialDataVersion = Object.keys(minecraftInitialDataJson)[0]!
43
+ // // if (version === initialDataVersion) {
44
+ // // // ignore cache hit
45
+ // // versionsByMinecraftVersion.pc[initialDataVersion]!.dataVersion!++
46
+ // // }
47
+
48
+ // await window._MC_DATA_RESOLVER.promise // ensure data is loaded
49
+ // miscUiState.loadedDataVersion = version
50
+ }
51
+
52
+ const loadFonts = async ( ) => {
53
+ const FONT_FAMILY = 'mojangles'
54
+ if ( ! document . fonts . check ( `1em ${ FONT_FAMILY } ` ) ) {
36
55
// todo instead re-render signs on load
37
- await document . fonts . load ( ' 1em mojangles' ) . catch ( ( ) => {
56
+ await document . fonts . load ( ` 1em ${ FONT_FAMILY } ` ) . catch ( ( ) => {
38
57
console . error ( 'Failed to load font, signs wont be rendered correctly' )
39
58
} )
40
59
}
41
- await window . _MC_DATA_RESOLVER . promise // ensure data is loaded
42
- await downloadSoundsIfNeeded ( )
43
- miscUiState . loadedDataVersion = version
60
+ }
61
+
62
+ export const downloadOtherGameData = async ( ) => {
63
+ await Promise . all ( [ loadFonts ( ) , downloadSoundsIfNeeded ( ) ] )
44
64
}
0 commit comments