Skip to content

Commit

Permalink
feat: custom component and icon
Browse files Browse the repository at this point in the history
  • Loading branch information
cazala committed Dec 16, 2024
1 parent 9ff710e commit ed57ef7
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
background-image: url(./icons/camera.svg);
}

.Hierarchy .custom-icon {
background-image: url(./icons/custom.svg);
}

.Hierarchy .smart-icon {
background-image: url(./icons/smart.svg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const HierarchyIcon = withSdk<{ value: Entity }>(({ sdk, value }) => {
[sdk, value]
)

const isCustom = useMemo(() => sdk.components.CustomAsset.has(value), [sdk, value])

const isTile = useMemo(() => sdk.components.Tile.has(value), [sdk, value])

const isGroup = useMemo(() => {
Expand All @@ -35,6 +37,8 @@ const HierarchyIcon = withSdk<{ value: Entity }>(({ sdk, value }) => {
return <span className="tree-icon player-icon"></span>
} else if (value === CAMERA) {
return <span className="tree-icon camera-icon"></span>
} else if (isCustom) {
return <span className="tree-icon custom-icon"></span>
} else if (isSmart) {
return <span className="tree-icon smart-icon"></span>
} else if (isTile) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 8 additions & 6 deletions packages/@dcl/inspector/src/components/Renderer/Renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ const Renderer: React.FC = () => {
return snapPosition(new Vector3(fixedNumber(pointerCoords.x), 0, fixedNumber(pointerCoords.z)))
}

const addAsset = async (asset: AssetNodeItem, position: Vector3, basePath: string) => {
const addAsset = async (asset: AssetNodeItem, position: Vector3, basePath: string, isCustom: boolean) => {
if (!sdk) return
const { operations } = sdk
operations.addAsset(
Expand All @@ -222,14 +222,16 @@ const Renderer: React.FC = () => {
basePath,
sdk.enumEntity,
asset.composite,
asset.asset.id
asset.asset.id,
isCustom
)
await operations.dispatch()
analytics.track(Event.ADD_ITEM, {
itemId: asset.asset.id,
itemName: asset.name,
itemPath: asset.asset.src,
isSmart: isSmart(asset)
isSmart: isSmart(asset),
isCustom
})
canvasRef.current?.focus()
}
Expand Down Expand Up @@ -303,7 +305,7 @@ const Renderer: React.FC = () => {
console.log('model', model)

dispatch(importAsset({ content, basePath, assetPackageName: '', reload: true }))
await addAsset(model, position, basePath)
await addAsset(model, position, basePath, true)
}

const importCatalogAsset = async (asset: Asset) => {
Expand Down Expand Up @@ -376,7 +378,7 @@ const Renderer: React.FC = () => {
if (isGround(asset)) {
position.y += 0.25
}
await addAsset(model, position, basePath)
await addAsset(model, position, basePath, false)
}
}

Expand All @@ -397,7 +399,7 @@ const Renderer: React.FC = () => {
const model = getNode(node, item.context.tree, isModel)
if (model) {
const position = await getDropPosition()
await addAsset(model, position, DIRECTORY.ASSETS)
await addAsset(model, position, DIRECTORY.ASSETS, false)
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/@dcl/inspector/src/lib/logic/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type Events = {
itemName: string
itemPath: string
isSmart: boolean
isCustom: boolean
}
[Event.ADD_COMPONENT]: {
componentName: string
Expand Down
17 changes: 15 additions & 2 deletions packages/@dcl/inspector/src/lib/sdk/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export enum EditorComponentNames {
Lock = 'inspector::Lock',
Config = 'inspector::Config',
Ground = 'inspector::Ground',
Tile = 'inspector::Tile'
Tile = 'inspector::Tile',
CustomAsset = 'inspector::CustomAsset'
}

export enum SceneAgeRating {
Expand Down Expand Up @@ -118,6 +119,10 @@ export type GroundComponent = {}
// eslint-disable-next-line @typescript-eslint/ban-types
export type TileComponent = {}

export type CustomAssetComponent = {
assetId: string
}

export enum SceneCategory {
ART = 'art',
GAME = 'game',
Expand Down Expand Up @@ -148,6 +153,7 @@ export type EditorComponentsTypes = {
Config: ConfigComponent
Ground: GroundComponent
Tile: TileComponent
CustomAsset: CustomAssetComponent
}

export type EditorComponents = {
Expand All @@ -166,6 +172,7 @@ export type EditorComponents = {
Config: LastWriteWinElementSetComponentDefinition<EditorComponentsTypes['Config']>
Ground: LastWriteWinElementSetComponentDefinition<EditorComponentsTypes['Ground']>
Tile: LastWriteWinElementSetComponentDefinition<EditorComponentsTypes['Tile']>
CustomAsset: LastWriteWinElementSetComponentDefinition<EditorComponentsTypes['CustomAsset']>
}

export type SdkComponents = {
Expand Down Expand Up @@ -344,6 +351,9 @@ export function createEditorComponents(engine: IEngine): EditorComponents {

const Ground = engine.defineComponent(EditorComponentNames.Ground, {})
const Tile = engine.defineComponent(EditorComponentNames.Tile, {})
const CustomAsset = engine.defineComponent(EditorComponentNames.CustomAsset, {
assetId: Schemas.String
})

return {
Selection,
Expand All @@ -362,6 +372,9 @@ export function createEditorComponents(engine: IEngine): EditorComponents {
States: States as unknown as LastWriteWinElementSetComponentDefinition<EditorComponentsTypes['States']>,
CounterBar: CounterBar as unknown as LastWriteWinElementSetComponentDefinition<EditorComponentsTypes['CounterBar']>,
Ground: Ground as unknown as LastWriteWinElementSetComponentDefinition<EditorComponentsTypes['Ground']>,
Tile: Tile as unknown as LastWriteWinElementSetComponentDefinition<EditorComponentsTypes['Tile']>
Tile: Tile as unknown as LastWriteWinElementSetComponentDefinition<EditorComponentsTypes['Tile']>,
CustomAsset: CustomAsset as unknown as LastWriteWinElementSetComponentDefinition<
EditorComponentsTypes['CustomAsset']
>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ export function addAsset(engine: IEngine) {
base: string,
enumEntityId: EnumEntity,
composite?: AssetData['composite'],
assetId?: string
assetId?: string,
custom?: boolean
): Entity {
const Transform = engine.getComponent(TransformEngine.componentId) as typeof TransformEngine
const GltfContainer = engine.getComponent(GltfEngine.componentId) as typeof GltfEngine
const NetworkEntity = engine.getComponent(NetworkEntityEngine.componentId) as typeof NetworkEntityEngine
const Nodes = engine.getComponent(EditorComponentNames.Nodes) as EditorComponents['Nodes']
const CustomAsset = engine.getComponent(EditorComponentNames.CustomAsset) as EditorComponents['CustomAsset']

if (composite) {
// Get all unique entity IDs from components
Expand Down Expand Up @@ -317,6 +319,10 @@ export function addAsset(engine: IEngine) {
throw new Error('No main entity found')
}

if (assetId && custom) {
CustomAsset.createOrReplace(mainEntity, { assetId })
}

// update selection
updateSelectedEntity(engine)(mainEntity)
return mainEntity
Expand Down

0 comments on commit ed57ef7

Please sign in to comment.