cache sounds, report downloading assets
This commit is contained in:
parent
b30e7fc152
commit
97533cfddb
3 changed files with 29 additions and 7 deletions
|
|
@ -55,6 +55,7 @@ exports.getSwAdditionalEntries = () => {
|
|||
'manifest.json',
|
||||
'worldSaveWorker.js',
|
||||
`textures/entity/squid/squid.png`,
|
||||
'sounds.js',
|
||||
// everything but not .map
|
||||
'static/**/!(*.map)',
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
])
|
||||
}
|
||||
|
|
|
|||
19
src/index.ts
19
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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue