-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Use AssetListLoader to load assets in AppBase.preload #8177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -42,6 +42,7 @@ | |||||||
| RESOLUTION_AUTO, RESOLUTION_FIXED | ||||||||
| } from './constants.js'; | ||||||||
| import { Asset } from './asset/asset.js'; | ||||||||
| import { AssetListLoader } from './asset/asset-list-loader.js'; | ||||||||
| import { AssetRegistry } from './asset/asset-registry.js'; | ||||||||
| import { BundleRegistry } from './bundle/bundle-registry.js'; | ||||||||
| import { ComponentSystemRegistry } from './components/registry.js'; | ||||||||
|
|
@@ -707,9 +708,7 @@ | |||||||
| this.fire('preload:start'); | ||||||||
|
|
||||||||
| // get list of assets to preload | ||||||||
| const assets = this.assets.list({ | ||||||||
| preload: true | ||||||||
| }); | ||||||||
| const assets = this.assets.filter(asset => asset.preload === true && asset.loaded === false) | ||||||||
|
|
||||||||
| if (assets.length === 0) { | ||||||||
| this.fire('preload:end'); | ||||||||
|
|
@@ -719,25 +718,18 @@ | |||||||
|
|
||||||||
| let loadedCount = 0; | ||||||||
|
|
||||||||
| const onAssetLoadOrError = () => { | ||||||||
| const onAssetLoad = () => { | ||||||||
| loadedCount++; | ||||||||
| this.fire('preload:progress', loadedCount / assets.length); | ||||||||
|
|
||||||||
| if (loadedCount === assets.length) { | ||||||||
| this.fire('preload:end'); | ||||||||
| callback(); | ||||||||
| } | ||||||||
| }; | ||||||||
|
|
||||||||
| // for each asset | ||||||||
| assets.forEach((asset) => { | ||||||||
| if (!asset.loaded) { | ||||||||
| asset.once('load', onAssetLoadOrError); | ||||||||
| asset.once('error', onAssetLoadOrError); | ||||||||
| this.assets.load(asset); | ||||||||
| } else { | ||||||||
| onAssetLoadOrError(); | ||||||||
| } | ||||||||
| const assetListLoader = new AssetListLoader(assets, this.assets); | ||||||||
|
|
||||||||
| assetListLoader.on('progress', onAssetLoad); | ||||||||
|
||||||||
| assetListLoader.on('progress', onAssetLoad); | |
| assetListLoader.on('progress', onAssetLoad); | |
| assetListLoader.on('error', onAssetLoad); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There exists no error event for AssetListLoader. We would need to make adjustments to the AssetListLoader class to make this work.
Uh oh!
There was an error while loading. Please reload this page.