refactor: replace the deprecate api 'globEager'

This commit is contained in:
Yu1512 2023-02-15 15:21:00 +08:00
parent 413c17f4cd
commit 41bbbe7c96
2 changed files with 8 additions and 8 deletions

View File

@ -5,7 +5,7 @@
interface ITextures {
name: string
url: string
url: () => Promise<{ default: string }>
}
export interface IResources {
@ -15,14 +15,13 @@ export interface IResources {
const fileSuffix = ['earth', 'gradient', 'redCircle', 'label', 'aperture', 'glow', 'light_column', 'aircraft']
const textures: ITextures[] = []
const modules = import.meta.globEager("../../images/earth/*");
for(let item in modules) {
const modules = import.meta.glob("../../images/earth/*");
for (let item in modules) {
const n = item.split('/').pop()
if(n) {
if (n) {
textures.push({
name: n.split('.')[0],
url: modules[item].default
url: (modules[item] as () => Promise<{ default: string }>)
})
}
}

View File

@ -45,8 +45,9 @@ export class Resources {
*/
private loadResources(): void {
this.textureLoader = new TextureLoader(this.manager)
resources.textures?.forEach(item => {
this.textureLoader.load(item.url, t => {
resources.textures?.forEach(async item => {
const url = (await item.url()).default
this.textureLoader.load(url, t => {
this.textures[item.name] = t
})
})