Skip to content

Commit a84ab1e

Browse files
feat: support blobs that are ADR74 emotes (#2314)
* feat: support blobs that are ADR74 emotes * chore: bump decentraland-ui * chore: remove any * chore: remove unused WearableWithBlobs type * fix: check if type is emote and use right helper to generate blob * chore: remove main image file since emotes can't be images Co-authored-by: Juanma Hidalgo <juanma06@gmail.com>
1 parent 5324c6d commit a84ab1e

File tree

6 files changed

+65
-38
lines changed

6 files changed

+65
-38
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"@dcl/content-hash-tree": "^1.1.3",
1010
"@dcl/crypto": "^3.0.1",
1111
"@dcl/hashing": "^1.1.0",
12-
"@dcl/schemas": "^5.13.0",
12+
"@dcl/schemas": "^5.17.1",
1313
"@dcl/ui-env": "^1.2.0",
1414
"@testing-library/jest-dom": "^5.16.4",
1515
"@testing-library/react": "^11.0.0",
@@ -31,7 +31,7 @@
3131
"decentraland-ecs": "file:ecs/decentraland-ecs-6.6.1-20201020183014.commit-bdc29ef-hotfix.tgz",
3232
"decentraland-experiments": "^1.0.2",
3333
"decentraland-transactions": "^1.37.0",
34-
"decentraland-ui": "^3.49.0",
34+
"decentraland-ui": "^3.52.0",
3535
"ethers": "^5.6.8",
3636
"file-saver": "^2.0.1",
3737
"graphql": "^15.8.0",

src/components/Modals/CreateSingleItemModal/CreateSingleItemModal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import {
5353
} from 'modules/item/utils'
5454
import ImportStep from './ImportStep/ImportStep'
5555
import EditThumbnailStep from './EditThumbnailStep/EditThumbnailStep'
56-
import { getThumbnailType, toWearableWithBlobs } from './utils'
56+
import { getThumbnailType, toEmoteWithBlobs, toWearableWithBlobs } from './utils'
5757
import EditPriceAndBeneficiaryModal from '../EditPriceAndBeneficiaryModal'
5858
import {
5959
Props,
@@ -603,7 +603,7 @@ export default class CreateSingleItemModal extends React.PureComponent<Props, St
603603
renderWearablePreview = () => {
604604
const { type, contents } = this.state
605605
const isEmote = type === ItemType.EMOTE
606-
const blob = contents ? toWearableWithBlobs({ contents, isEmote }) : undefined
606+
const blob = contents ? (isEmote ? toEmoteWithBlobs({ contents }) : toWearableWithBlobs({ contents })) : undefined
607607
if (!blob) {
608608
return null
609609
}
@@ -945,7 +945,7 @@ export default class CreateSingleItemModal extends React.PureComponent<Props, St
945945
return (
946946
<EditThumbnailStep
947947
isLoading={!!isLoading}
948-
blob={contents ? toWearableWithBlobs({ contents, isEmote: true }) : undefined}
948+
blob={contents ? toEmoteWithBlobs({ contents }) : undefined}
949949
title={this.renderModalTitle()}
950950
onBack={() => this.setState({ view: CreateItemView.DETAILS })}
951951
onSave={this.handleOnScreenshotTaken}

src/components/Modals/CreateSingleItemModal/EditThumbnailStep/EditThumbnailStep.types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IPreviewController, WearableWithBlobs } from '@dcl/schemas'
1+
import { EmoteWithBlobs, IPreviewController } from '@dcl/schemas'
22
import { Item } from 'modules/item/types'
33
import React from 'react'
44

@@ -18,7 +18,7 @@ export enum ControlOptionAction {
1818
export type Props = {
1919
title: string
2020
isLoading: boolean
21-
blob?: WearableWithBlobs
21+
blob?: EmoteWithBlobs
2222
base64s?: string[]
2323
wearablePreviewComponent?: React.ReactNode
2424
wearablePreviewController?: IPreviewController
@@ -31,7 +31,7 @@ export type State = {
3131
hasBeenUpdated: boolean
3232
playingIntervalId?: NodeJS.Timer
3333
previewController?: IPreviewController
34-
blob?: WearableWithBlobs
34+
blob?: EmoteWithBlobs
3535
zoom: number
3636
offsetY?: number
3737
}

src/components/Modals/CreateSingleItemModal/utils.ts

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BodyShape, WearableCategory, WearableWithBlobs } from '@dcl/schemas'
1+
import { BodyShape, EmoteCategory, EmoteWithBlobs, WearableCategory, WearableWithBlobs } from '@dcl/schemas'
22
import { ThumbnailType } from 'lib/getModelData'
33
import { isImageFile, isModelFile } from 'modules/item/utils'
44

@@ -18,15 +18,7 @@ export const getThumbnailType = (category: WearableCategory) => {
1818
}
1919
}
2020

21-
export function toWearableWithBlobs({
22-
contents,
23-
file,
24-
isEmote = false
25-
}: {
26-
contents?: Record<string, Blob>
27-
file?: File
28-
isEmote: boolean
29-
}): WearableWithBlobs {
21+
export function toWearableWithBlobs({ contents, file }: { contents?: Record<string, Blob>; file?: File }): WearableWithBlobs {
3022
const mainGLBFile = contents && Object.keys(contents).find(content => isModelFile(content))
3123
const mainPNGFile = contents && Object.keys(contents).find(content => isImageFile(content))
3224
const mainFile = mainGLBFile || mainPNGFile
@@ -63,7 +55,42 @@ export function toWearableWithBlobs({
6355
overrideReplaces: []
6456
}
6557
]
66-
},
67-
...(isEmote ? { emoteDataV0: { loop: false } } : {})
58+
}
59+
}
60+
}
61+
62+
export function toEmoteWithBlobs({ contents, file }: { contents?: Record<string, Blob>; file?: File }): EmoteWithBlobs {
63+
const mainFile = contents && Object.keys(contents).find(content => isModelFile(content))
64+
if (contents && !mainFile) {
65+
throw Error('Not valid main content')
66+
}
67+
return {
68+
id: 'some-id',
69+
name: '',
70+
description: '',
71+
image: '',
72+
thumbnail: '',
73+
i18n: [],
74+
emoteDataADR74: {
75+
category: EmoteCategory.DANCE,
76+
tags: [],
77+
representations: [
78+
{
79+
bodyShapes: [BodyShape.MALE, BodyShape.FEMALE],
80+
mainFile: mainFile || 'model.glb',
81+
contents: contents
82+
? Object.entries(contents).map(([key, value]) => ({ key, blob: value }))
83+
: file
84+
? [
85+
{
86+
key: 'model.glb',
87+
blob: file
88+
}
89+
]
90+
: []
91+
}
92+
],
93+
loop: false
94+
}
6895
}
6996
}

src/components/Modals/EditThumbnailModal/EditThumbnailModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { toBase64 } from 'modules/editor/utils'
55
import ImportStep from 'components/Modals/CreateSingleItemModal/ImportStep/ImportStep'
66
import EditThumbnailStep from 'components/Modals/CreateSingleItemModal/EditThumbnailStep/EditThumbnailStep'
77
import { AcceptedFileProps, CreateItemView } from 'components/Modals/CreateSingleItemModal/CreateSingleItemModal.types'
8-
import { toWearableWithBlobs } from 'components/Modals/CreateSingleItemModal/utils'
8+
import { toEmoteWithBlobs } from 'components/Modals/CreateSingleItemModal/utils'
99
import { Props, State } from './EditThumbnailModal.types'
1010
import './EditThumbnailModal.css'
1111

@@ -61,7 +61,7 @@ export default class EditThumbnailModal extends React.PureComponent<Props, State
6161

6262
let wearablePreviewProp
6363
if (file) {
64-
wearablePreviewProp = { blob: toWearableWithBlobs({ file, isEmote: true }) }
64+
wearablePreviewProp = { blob: toEmoteWithBlobs({ file }) }
6565
} else if (item) {
6666
wearablePreviewProp = { base64s: [toBase64(item)] }
6767
}

0 commit comments

Comments
 (0)