Skip to content

Commit 2b88243

Browse files
authored
fix: Load smart item asset path (#1062)
* fix: Load smart items path * fix: Add a small retry when fetching the models to avoid race conditions * fix: Linter
1 parent 86c87c6 commit 2b88243

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

packages/@dcl/inspector/src/lib/babylon/decentraland/SceneContext.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export class SceneContext {
152152
return null
153153
}
154154

155-
async getFile(src: string): Promise<Uint8Array | null> {
155+
async getFile(src: string, retryCount = 3): Promise<Uint8Array | null> {
156156
if (!src) return null
157157
try {
158158
// TODO: how we handle this with redux ?
@@ -161,6 +161,12 @@ export class SceneContext {
161161
const response = await dataLayer.getAssetData({ path: src })
162162
return response.data
163163
} catch (err) {
164+
if (retryCount > 0) {
165+
// Wait for 500ms before retrying
166+
await new Promise((resolve) => setTimeout(resolve, 500))
167+
console.log(`Retrying fetch for ${src}, attempts remaining: ${retryCount - 1}`)
168+
return this.getFile(src, retryCount - 1)
169+
}
164170
console.error('Error fetching file ' + src, err)
165171
return null
166172
}

packages/@dcl/inspector/src/lib/babylon/decentraland/sdkComponents/nft.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { PBNftShape, ComponentType } from '@dcl/ecs'
33

44
import type { ComponentOperation } from '../component-operations'
55
import { updateGltfForEntity } from './gltf-container'
6-
import { withAssetDir } from '../../../data-layer/host/fs-utils'
6+
import { withAssetPacksDir } from '../../../data-layer/host/fs-utils'
77

88
export const putNftShapeComponent: ComponentOperation = (entity, component) => {
99
if (component.componentType === ComponentType.LastWriteWinElementSet) {
1010
const newValue = component.getOrNull(entity.entityId) as PBNftShape | null
11-
const gltfValue = newValue ? { src: withAssetDir('builder/nft/nft.glb') } : null
11+
const gltfValue = newValue ? { src: withAssetPacksDir('nft/nft.glb') } : null
1212
updateGltfForEntity(entity, gltfValue)
1313
entity
1414
.onGltfContainerLoaded()

packages/@dcl/inspector/src/lib/babylon/decentraland/sdkComponents/video-player.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { PBVideoPlayer, ComponentType } from '@dcl/ecs'
33

44
import type { ComponentOperation } from '../component-operations'
55
import { updateGltfForEntity } from './gltf-container'
6-
import { withAssetDir } from '../../../data-layer/host/fs-utils'
6+
import { withAssetPacksDir } from '../../../data-layer/host/fs-utils'
77

88
export const putVideoPlayerComponent: ComponentOperation = (entity, component) => {
99
if (component.componentType === ComponentType.LastWriteWinElementSet) {
1010
const newValue = component.getOrNull(entity.entityId) as PBVideoPlayer | null
11-
const gltfValue = newValue ? { src: withAssetDir('builder/video_player/video_player.glb') } : null
11+
const gltfValue = newValue ? { src: withAssetPacksDir('video_player/video_player.glb') } : null
1212
updateGltfForEntity(entity, gltfValue)
1313
const scaleMult = 1.55
1414
entity

packages/@dcl/inspector/src/lib/data-layer/host/fs-utils.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export const DIRECTORY = {
3131
ASSETS: 'assets',
3232
SCENE: 'scene',
3333
THUMBNAILS: 'thumbnails',
34-
CUSTOM: 'custom'
34+
CUSTOM: 'custom',
35+
ASSET_PACKS: 'asset-packs'
3536
}
3637

3738
export const EXTENSIONS = [
@@ -51,6 +52,10 @@ export function withAssetDir(filePath: string = '') {
5152
return filePath ? `${DIRECTORY.ASSETS}/${filePath}` : DIRECTORY.ASSETS
5253
}
5354

55+
export function withAssetPacksDir(filePath: string) {
56+
return withAssetDir(`${DIRECTORY.ASSET_PACKS}/${filePath}`)
57+
}
58+
5459
export function isFileInAssetDir(filePath: string = '') {
5560
return filePath.startsWith(DIRECTORY.ASSETS)
5661
}

0 commit comments

Comments
 (0)