Skip to content

fix: Load smart item asset path #1062

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

Merged
merged 3 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class SceneContext {
return null
}

async getFile(src: string): Promise<Uint8Array | null> {
async getFile(src: string, retryCount = 3): Promise<Uint8Array | null> {
if (!src) return null
try {
// TODO: how we handle this with redux ?
Expand All @@ -161,6 +161,12 @@ export class SceneContext {
const response = await dataLayer.getAssetData({ path: src })
return response.data
} catch (err) {
if (retryCount > 0) {
// Wait for 500ms before retrying
await new Promise((resolve) => setTimeout(resolve, 500))
console.log(`Retrying fetch for ${src}, attempts remaining: ${retryCount - 1}`)
return this.getFile(src, retryCount - 1)
}
console.error('Error fetching file ' + src, err)
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { PBNftShape, ComponentType } from '@dcl/ecs'

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

export const putNftShapeComponent: ComponentOperation = (entity, component) => {
if (component.componentType === ComponentType.LastWriteWinElementSet) {
const newValue = component.getOrNull(entity.entityId) as PBNftShape | null
const gltfValue = newValue ? { src: withAssetDir('builder/nft/nft.glb') } : null
const gltfValue = newValue ? { src: withAssetPacksDir('nft/nft.glb') } : null
updateGltfForEntity(entity, gltfValue)
entity
.onGltfContainerLoaded()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { PBVideoPlayer, ComponentType } from '@dcl/ecs'

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

export const putVideoPlayerComponent: ComponentOperation = (entity, component) => {
if (component.componentType === ComponentType.LastWriteWinElementSet) {
const newValue = component.getOrNull(entity.entityId) as PBVideoPlayer | null
const gltfValue = newValue ? { src: withAssetDir('builder/video_player/video_player.glb') } : null
const gltfValue = newValue ? { src: withAssetPacksDir('video_player/video_player.glb') } : null
updateGltfForEntity(entity, gltfValue)
const scaleMult = 1.55
entity
Expand Down
7 changes: 6 additions & 1 deletion packages/@dcl/inspector/src/lib/data-layer/host/fs-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export const DIRECTORY = {
ASSETS: 'assets',
SCENE: 'scene',
THUMBNAILS: 'thumbnails',
CUSTOM: 'custom'
CUSTOM: 'custom',
ASSET_PACKS: 'asset-packs'
}

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

export function withAssetPacksDir(filePath: string) {
return withAssetDir(`${DIRECTORY.ASSET_PACKS}/${filePath}`)
}

export function isFileInAssetDir(filePath: string = '') {
return filePath.startsWith(DIRECTORY.ASSETS)
}
Expand Down
Loading