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 { interface ITextures {
name: string name: string
url: string url: () => Promise<{ default: string }>
} }
export interface IResources { export interface IResources {
@ -15,14 +15,13 @@ export interface IResources {
const fileSuffix = ['earth', 'gradient', 'redCircle', 'label', 'aperture', 'glow', 'light_column', 'aircraft'] const fileSuffix = ['earth', 'gradient', 'redCircle', 'label', 'aperture', 'glow', 'light_column', 'aircraft']
const textures: ITextures[] = [] const textures: ITextures[] = []
const modules = import.meta.globEager("../../images/earth/*"); const modules = import.meta.glob("../../images/earth/*");
for (let item in modules) { for (let item in modules) {
const n = item.split('/').pop() const n = item.split('/').pop()
if (n) { if (n) {
textures.push({ textures.push({
name: n.split('.')[0], 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 { private loadResources(): void {
this.textureLoader = new TextureLoader(this.manager) this.textureLoader = new TextureLoader(this.manager)
resources.textures?.forEach(item => { resources.textures?.forEach(async item => {
this.textureLoader.load(item.url, t => { const url = (await item.url()).default
this.textureLoader.load(url, t => {
this.textures[item.name] = t this.textures[item.name] = t
}) })
}) })