Skip to content

Commit 10d594b

Browse files
authored
refactor: composite (#1042)
* feat: refactor to use composite * chore: remove debuggers * chore: upgrade asset-packs * chore: rename enum
1 parent c62a668 commit 10d594b

File tree

13 files changed

+557
-203
lines changed

13 files changed

+557
-203
lines changed

packages/@dcl/inspector/package-lock.json

Lines changed: 358 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@dcl/inspector/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@dcl/inspector",
33
"version": "0.1.0",
44
"dependencies": {
5-
"@dcl/asset-packs": "1.20.2",
5+
"@dcl/asset-packs": "^2.0.0",
66
"ts-deepmerge": "^7.0.0"
77
},
88
"devDependencies": {

packages/@dcl/inspector/src/components/AssetsCatalog/Asset/Asset.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { fetchImage, resizeImage } from '../../../lib/utils/img'
1111
import { useIsMounted } from '../../../hooks/useIsMounted'
1212

1313
const Asset: React.FC<{ value: Asset }> = ({ value }) => {
14-
const [, drag, preview] = useDrag(() => ({ type: 'builder-asset', item: { value } }), [value])
14+
const [, drag, preview] = useDrag(() => ({ type: 'catalog-asset', item: { value } }), [value])
1515
const isSmartItem = isSmart(value)
1616
const isGroundItem = isGround(value)
1717
const imgSrc = getContentsUrl(value.contents['thumbnail.png'])

packages/@dcl/inspector/src/components/EntityInspector/SmartItemBasicView/VideoView/VideoView.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { Entity } from '@dcl/ecs'
55
import { withSdk, WithSdkProps } from '../../../../hoc/withSdk'
66
import { useHasComponent } from '../../../../hooks/sdk/useHasComponent'
77
import { useComponentInput } from '../../../../hooks/sdk/useComponentInput'
8-
import { ProjectAssetDrop, getNode } from '../../../../lib/sdk/drag-drop'
8+
import { LocalAssetDrop, getNode } from '../../../../lib/sdk/drag-drop'
99
import { withAssetDir } from '../../../../lib/data-layer/host/fs-utils'
1010
import { useAppSelector } from '../../../../redux/hooks'
1111
import { selectAssetCatalog } from '../../../../redux/app'
1212
import { Block } from '../../../Block'
1313
import { TextField, CheckboxField, RangeField, InfoTooltip } from '../../../ui'
1414
import { fromVideoPlayer, toVideoPlayer, isValidInput, isVideo, isValidVolume } from '../../VideoPlayerInspector/utils'
1515

16-
const DROP_TYPES = ['project-asset']
16+
const DROP_TYPES = ['local-asset']
1717

1818
export default React.memo(
1919
withSdk<WithSdkProps & { entity: Entity }>(({ sdk, entity }) => {
@@ -44,13 +44,13 @@ export default React.memo(
4444
const [{ isHover }, drop] = useDrop(
4545
() => ({
4646
accept: DROP_TYPES,
47-
drop: ({ value, context }: ProjectAssetDrop, monitor) => {
47+
drop: ({ value, context }: LocalAssetDrop, monitor) => {
4848
if (monitor.didDrop()) return
4949
const node = context.tree.get(value)!
5050
const model = getNode(node, context.tree, isVideo)
5151
if (model) void handleDrop(withAssetDir(model.asset.src))
5252
},
53-
canDrop: ({ value, context }: ProjectAssetDrop) => {
53+
canDrop: ({ value, context }: LocalAssetDrop) => {
5454
const node = context.tree.get(value)!
5555
return !!getNode(node, context.tree, isVideo)
5656
},

packages/@dcl/inspector/src/components/EntityInspector/VideoPlayerInspector/VideoPlayerInspector.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { getComponentValue } from '../../../hooks/sdk/useComponentValue'
99
import { analytics, Event } from '../../../lib/logic/analytics'
1010
import { getAssetByModel } from '../../../lib/logic/catalog'
1111
import { CoreComponents } from '../../../lib/sdk/components'
12-
import { ProjectAssetDrop, getNode } from '../../../lib/sdk/drag-drop'
12+
import { LocalAssetDrop, getNode } from '../../../lib/sdk/drag-drop'
1313
import { withAssetDir } from '../../../lib/data-layer/host/fs-utils'
1414
import { useAppSelector } from '../../../redux/hooks'
1515
import { selectAssetCatalog } from '../../../redux/app'
@@ -19,7 +19,7 @@ import { TextField, CheckboxField, RangeField, InfoTooltip } from '../../ui'
1919
import { fromVideoPlayer, toVideoPlayer, isValidInput, isVideo, isValidVolume } from './utils'
2020
import type { Props } from './types'
2121

22-
const DROP_TYPES = ['project-asset']
22+
const DROP_TYPES = ['local-asset']
2323

2424
export default withSdk<Props>(({ sdk, entity }) => {
2525
const files = useAppSelector(selectAssetCatalog)
@@ -56,13 +56,13 @@ export default withSdk<Props>(({ sdk, entity }) => {
5656
const [{ isHover }, drop] = useDrop(
5757
() => ({
5858
accept: DROP_TYPES,
59-
drop: ({ value, context }: ProjectAssetDrop, monitor) => {
59+
drop: ({ value, context }: LocalAssetDrop, monitor) => {
6060
if (monitor.didDrop()) return
6161
const node = context.tree.get(value)!
6262
const model = getNode(node, context.tree, isVideo)
6363
if (model) void handleDrop(withAssetDir(model.asset.src))
6464
},
65-
canDrop: ({ value, context }: ProjectAssetDrop) => {
65+
canDrop: ({ value, context }: LocalAssetDrop) => {
6666
const node = context.tree.get(value)!
6767
return !!getNode(node, context.tree, isVideo)
6868
},

packages/@dcl/inspector/src/components/ProjectAssetExplorer/ProjectView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface ModalState {
3030

3131
export const ROOT = 'File System'
3232

33-
export const DRAG_N_DROP_ASSET_KEY = 'project-asset'
33+
export const DRAG_N_DROP_ASSET_KEY = 'local-asset'
3434

3535
export type TreeNode = Omit<AssetNode, 'children'> & { children?: string[]; matches?: string[] }
3636

packages/@dcl/inspector/src/components/ProjectAssetExplorer/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { ComponentName } from '@dcl/asset-packs'
2-
import { CoreComponents } from '../../lib/sdk/components'
1+
import { AssetData } from '../../lib/logic/catalog'
32

43
export interface IAsset {
54
src: string
@@ -20,7 +19,7 @@ export interface AssetCellProp {
2019
export type AssetNodeBase = {
2120
name: string
2221
parent: AssetNodeFolder | null
23-
components?: Partial<Record<ComponentName | CoreComponents, any>>
22+
composite?: AssetData['composite']
2423
}
2524

2625
export type AssetNodeItem = AssetNodeBase & {

packages/@dcl/inspector/src/components/Renderer/Renderer.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Entity } from '@dcl/ecs'
88
import { DIRECTORY, withAssetDir } from '../../lib/data-layer/host/fs-utils'
99
import { useAppDispatch, useAppSelector } from '../../redux/hooks'
1010
import { getReloadAssets, importAsset, saveThumbnail } from '../../redux/data-layer'
11-
import { getNode, BuilderAsset, DROP_TYPES, IDrop, ProjectAssetDrop, isDropType } from '../../lib/sdk/drag-drop'
11+
import { getNode, CatalogAssetDrop, DROP_TYPES, IDrop, LocalAssetDrop, isDropType } from '../../lib/sdk/drag-drop'
1212
import { useRenderer } from '../../hooks/sdk/useRenderer'
1313
import { useSdk } from '../../hooks/sdk/useSdk'
1414
import { getPointerCoords } from '../../lib/babylon/decentraland/mouse-utils'
@@ -212,7 +212,7 @@ const Renderer: React.FC = () => {
212212
position,
213213
basePath,
214214
sdk.enumEntity,
215-
asset.components,
215+
asset.composite,
216216
asset.asset.id
217217
)
218218
await operations.dispatch()
@@ -239,10 +239,10 @@ const Renderer: React.FC = () => {
239239
canvasRef.current?.focus()
240240
}
241241

242-
const importBuilderAsset = async (asset: Asset) => {
242+
const importCatalogAsset = async (asset: Asset) => {
243243
const position = await getDropPosition()
244244
const fileContent: Record<string, Uint8Array> = {}
245-
const destFolder = 'builder'
245+
const destFolder = 'asset-packs'
246246
const assetPackageName = asset.name.trim().replaceAll(' ', '_').toLowerCase()
247247
const path = Object.keys(asset.contents).find(($) => isAsset($))
248248
let thumbnail: Uint8Array | undefined
@@ -299,7 +299,7 @@ const Renderer: React.FC = () => {
299299
name: asset.name,
300300
parent: null,
301301
asset: { type: path ? 'gltf' : 'unknown', src: path ?? '', id: asset.id },
302-
components: asset.components
302+
composite: asset.composite
303303
}
304304
const basePath = withAssetDir(`${destFolder}/${assetPackageName}`)
305305
if (isGround(asset) && !placeSingleTile) {
@@ -320,12 +320,12 @@ const Renderer: React.FC = () => {
320320
if (monitor.didDrop()) return
321321
const itemType = monitor.getItemType()
322322

323-
if (isDropType<BuilderAsset>(item, itemType, 'builder-asset')) {
324-
void importBuilderAsset(item.value)
323+
if (isDropType<CatalogAssetDrop>(item, itemType, 'catalog-asset')) {
324+
void importCatalogAsset(item.value)
325325
return
326326
}
327327

328-
if (isDropType<ProjectAssetDrop>(item, itemType, 'project-asset')) {
328+
if (isDropType<LocalAssetDrop>(item, itemType, 'local-asset')) {
329329
const node = item.context.tree.get(item.value)!
330330
const model = getNode(node, item.context.tree, isModel)
331331
if (model) {
@@ -335,7 +335,7 @@ const Renderer: React.FC = () => {
335335
}
336336
},
337337
hover(item, monitor) {
338-
if (isDropType<BuilderAsset>(item, monitor.getItemType(), 'builder-asset')) {
338+
if (isDropType<CatalogAssetDrop>(item, monitor.getItemType(), 'catalog-asset')) {
339339
const asset = item.value
340340
if (isGround(asset)) {
341341
if (!showSingleTileHint) {

packages/@dcl/inspector/src/components/ui/FileUploadField/FileUploadField.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { selectAssetCatalog, selectUploadFile, updateUploadFile } from '../../..
88
import { selectAssetsTab } from '../../../redux/ui'
99
import { AssetsTab } from '../../../redux/ui/types'
1010
import { useAppDispatch, useAppSelector } from '../../../redux/hooks'
11-
import { DropTypesEnum, ProjectAssetDrop, getNode } from '../../../lib/sdk/drag-drop'
11+
import { DropTypesEnum, LocalAssetDrop, getNode } from '../../../lib/sdk/drag-drop'
1212
import { EXTENSIONS, withAssetDir } from '../../../lib/data-layer/host/fs-utils'
1313

1414
import { isModel } from '../../EntityInspector/GltfInspector/utils'
@@ -97,8 +97,8 @@ const FileUploadField: React.FC<Props> = ({
9797

9898
const [{ isHover, canDrop }, drop] = useDrop(
9999
() => ({
100-
accept: [DropTypesEnum.ProjectAsset],
101-
drop: ({ value, context }: ProjectAssetDrop, monitor) => {
100+
accept: [DropTypesEnum.LocalAsset],
101+
drop: ({ value, context }: LocalAssetDrop, monitor) => {
102102
if (monitor.didDrop()) return
103103
const node = context.tree.get(value)!
104104
const element = getNode(node, context.tree, isValid)
@@ -109,7 +109,7 @@ const FileUploadField: React.FC<Props> = ({
109109
setDropError(true)
110110
}
111111
},
112-
canDrop: ({ value, context }: ProjectAssetDrop) => {
112+
canDrop: ({ value, context }: LocalAssetDrop) => {
113113
const node = context.tree.get(value)!
114114
return !!getNode(node, context.tree, isValid)
115115
},

packages/@dcl/inspector/src/lib/logic/catalog.ts

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { ComponentName } from '@dcl/asset-packs'
2-
import * as _catalog from '@dcl/asset-packs/catalog.json'
1+
import { Catalog, AssetPack, Asset, AssetData } from '@dcl/asset-packs'
32
import { CoreComponents } from '../sdk/components'
43
import { getConfig } from './config'
4+
import * as _catalog from '@dcl/asset-packs/catalog.json'
55

6-
export const catalog = _catalog.assetPacks as unknown as AssetPack[]
6+
export const catalog = (_catalog as unknown as Catalog).assetPacks
77

8-
// categories obtained from "builder.decentraland.org" catalog
8+
export { Catalog, AssetPack, Asset, AssetData }
9+
10+
// categories obtained from "builder-items.decentraland.org" catalog
911
export const CATEGORIES = [
1012
'ground',
1113
'utils',
@@ -26,22 +28,6 @@ export const CATEGORIES = [
2628
'health'
2729
]
2830

29-
export type AssetPack = {
30-
id: string
31-
name: string
32-
thumbnail: string
33-
assets: Asset[]
34-
}
35-
36-
export type Asset = {
37-
id: string
38-
name: string
39-
category: string
40-
tags: string[]
41-
contents: Record<string, string>
42-
components: Partial<Record<ComponentName | CoreComponents, any>>
43-
}
44-
4531
export function getContentsUrl(hash: string) {
4632
const config = getConfig()
4733
return `${config.contentUrl}/contents/${hash}`
@@ -57,12 +43,12 @@ export function getAssetsByCategory(assets: Asset[]) {
5743
}
5844

5945
export function isSmart(asset: Partial<Asset>) {
60-
const components = Object.keys(asset?.components ?? {})
46+
const components = asset?.composite?.components ?? []
6147
// when the item has more than one component, it is smart
6248
if (components.length > 1) {
6349
return true
64-
// when the item has a single component but it's not a GltfContainer, then it's also smart (NFTShape, TextShape, MeshRenderers, etc...)
65-
} else if (components.length === 1 && components[0] !== CoreComponents.GLTF_CONTAINER) {
50+
// when the item has a single component but it's not a GltfContainer, then it's also smart
51+
} else if (components.length === 1 && components[0].name !== CoreComponents.GLTF_CONTAINER) {
6652
return true
6753
}
6854
// when the item only has a GltfContainer then it's not smart

packages/@dcl/inspector/src/lib/sdk/drag-drop.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as dnd from './drag-drop'
22

33
describe('sdk drag and drop', () => {
44
it('should return true when identifier equals type', () => {
5-
const drop = { value: 'project-asset', context: { tree: new Map() } }
6-
expect(dnd.isDropType(drop, 'project-asset', 'project-asset')).toBe(true)
7-
expect(dnd.isDropType(drop, 'invalid', 'project-asset')).toBe(false)
5+
const drop = { value: 'local-asset', context: { tree: new Map() } }
6+
expect(dnd.isDropType(drop, 'local-asset', 'local-asset')).toBe(true)
7+
expect(dnd.isDropType(drop, 'invalid', 'local-asset')).toBe(false)
88
})
99
it('should return all drop types list', () => {
1010
expect(dnd.DROP_TYPES).toStrictEqual(expect.arrayContaining(Object.values(dnd.DropTypesEnum)))

packages/@dcl/inspector/src/lib/sdk/drag-drop.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ interface Drop<T, K = object> {
88
context: K
99
}
1010

11-
export type ProjectAssetDrop = Drop<string, { tree: Map<string, TreeNode> }>
12-
export type BuilderAsset = Drop<Asset>
11+
export type LocalAssetDrop = Drop<string, { tree: Map<string, TreeNode> }>
12+
export type CatalogAssetDrop = Drop<Asset>
1313

14-
export type IDrop = ProjectAssetDrop | BuilderAsset
14+
export type IDrop = LocalAssetDrop | CatalogAssetDrop
1515

1616
export enum DropTypesEnum {
17-
ProjectAsset = 'project-asset',
18-
BuilderAsset = 'builder-asset'
17+
LocalAsset = 'local-asset',
18+
CatalogAsset = 'catalog-asset'
1919
}
2020

2121
export type DropTypes = `${DropTypesEnum}`

0 commit comments

Comments
 (0)