diff --git a/scripts/build.js b/scripts/build.js index 028a9fdc..2d5e0a2e 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -55,6 +55,7 @@ exports.getSwAdditionalEntries = () => { 'manifest.json', 'worldSaveWorker.js', `textures/entity/squid/squid.png`, + 'sounds.js', // everything but not .map 'static/**/!(*.map)', ] diff --git a/src/connect.ts b/src/connect.ts index 134b86da..b68e4325 100644 --- a/src/connect.ts +++ b/src/connect.ts @@ -70,8 +70,12 @@ export const loadMinecraftData = async (version: string) => { miscUiState.loadedDataVersion = version } -export const downloadAllMinecraftData = async () => { +export type AssetDownloadReporter = (asset: string, isDone: boolean) => void + +export const downloadAllMinecraftData = async (reporter?: AssetDownloadReporter) => { + reporter?.('mc-data', false) await window._LOAD_MC_DATA() + reporter?.('mc-data', true) } const loadFonts = async () => { @@ -84,6 +88,12 @@ const loadFonts = async () => { } } -export const downloadOtherGameData = async () => { - await Promise.all([loadFonts(), downloadSoundsIfNeeded()]) +export const downloadOtherGameData = async (reporter?: AssetDownloadReporter) => { + reporter?.('fonts', false) + reporter?.('sounds', false) + + await Promise.all([ + loadFonts().then(() => reporter?.('fonts', true)), + downloadSoundsIfNeeded().then(() => reporter?.('sounds', true)) + ]) } diff --git a/src/index.ts b/src/index.ts index 8678c26e..3c897619 100644 --- a/src/index.ts +++ b/src/index.ts @@ -302,11 +302,22 @@ export async function connect (connectOptions: ConnectOptions) { const serverOptions = defaultsDeep({}, connectOptions.serverOverrides ?? {}, options.localServerOptions, defaultServerOptions) Object.assign(serverOptions, connectOptions.serverOverridesFlat ?? {}) - await progress.executeWithMessage('Downloading minecraft data', 'download-mcdata', async () => { + await progress.executeWithMessage('Downloading Minecraft data', 'download-mcdata', async () => { loadingTimerState.networkOnlyStart = Date.now() + + let downloadingAssets = [] as string[] + const reportAssetDownload = (asset: string, isDone: boolean) => { + if (isDone) { + downloadingAssets = downloadingAssets.filter(a => a !== asset) + } else { + downloadingAssets.push(asset) + } + progress.setSubStage('download-mcdata', `(${downloadingAssets.join(', ')})`) + } + await Promise.all([ - downloadAllMinecraftData(), - downloadOtherGameData() + downloadAllMinecraftData(reportAssetDownload), + downloadOtherGameData(reportAssetDownload) ]) loadingTimerState.networkOnlyStart = 0 }) @@ -318,7 +329,7 @@ export async function connect (connectOptions: ConnectOptions) { appViewer.resourcesManager.currentConfig = { version, texturesVersion: options.useVersionsTextures || undefined } await progress.executeWithMessage( - 'Loading minecraft data', + 'Processing downloaded Minecraft data', async () => { await appViewer.resourcesManager.loadSourceData(version) }