Skip to content

Commit

Permalink
feat: add forceRenderer property (#5259)
Browse files Browse the repository at this point in the history
* feat: add `forceRenderer` property

* chore: undo change in default profile

* chore: upgrade schema version

* fix: correct entity build

* fix: string as wearable category

* fix: optional property

* Minor changes for forceRender

* Minor change

* Fix

* Added DTOs to allow serialization of hashsets

* forceRender various fixes

* Minor changes

---------

Co-authored-by: davidejensen <[email protected]>
  • Loading branch information
Julieta11 and davidejensen authored May 31, 2023
1 parent 33ea951 commit ba1a149
Show file tree
Hide file tree
Showing 22 changed files with 272 additions and 30 deletions.
78 changes: 71 additions & 7 deletions browser-interface/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion browser-interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@dcl/protocol": "1.0.0-5112230174.commit-a71a7e0",
"@dcl/rpc": "^1.1.1",
"@dcl/scene-runtime": "7.0.6-20230529131607.commit-637ca18",
"@dcl/schemas": "^6.11.1",
"@dcl/schemas": "^7.2.0",
"@dcl/urn-resolver": "^2.0.3",
"@types/mocha": "^10.0.1",
"@types/redux-logger": "^3.0.9",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { Snapshots, WearableId } from '@dcl/schemas'
import type { Snapshots, WearableCategory, WearableId } from '@dcl/schemas'

export type AvatarForUserData = {
bodyShape: WearableId
skinColor: string
hairColor: string
eyeColor: string
wearables: WearableId[]
forceRender?: WearableCategory[]
emotes?: {
slot: number
urn: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export function sceneRuntimeCompatibleAvatar(avatar: AvatarInfo): AvatarForUserD
...avatar,
bodyShape: avatar?.bodyShape,
wearables: avatar?.wearables || [],
forceRender: avatar?.forceRender || [],
snapshots: {
...avatar.snapshots,
face: avatar.snapshots.face256,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function defaultAvatar(): Omit<AvatarInfo, 'snapshots'> {
function prepareAvatar(avatar?: Partial<AvatarInfo>) {
return {
wearables: avatar?.wearables || [],
forceRender: avatar?.forceRender || [],
emotes: avatar?.emotes || [],
bodyShape: avatar?.bodyShape || '',
eyeColor: convertToRGBObject(avatar?.eyes?.color),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function ensureAvatarCompatibilityFormat(profile: Readonly<Avatar | OldAv
// These mappings from legacy id are here just in case they still have the legacy id in local storage
avatarInfo.bodyShape = mapLegacyIdToUrn(avatar?.bodyShape) || 'urn:decentraland:off-chain:base-avatars:BaseFemale'
avatarInfo.wearables = (avatar?.wearables || []).map(mapLegacyIdToUrn).filter(Boolean) as string[]
avatarInfo.forceRender = avatar?.forceRender
avatarInfo.emotes = avatar?.emotes
avatarInfo.snapshots = avatar?.snapshots

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Authenticator } from '@dcl/crypto'
import { hashV1 } from '@dcl/hashing'
import { Avatar, EntityType, Profile, Snapshots } from '@dcl/schemas'
import { ContentClient } from 'dcl-catalyst-client/dist/ContentClient'
import {
BuildEntityOptions,
BuildEntityWithoutFilesOptions,
ContentClient
} from 'dcl-catalyst-client/dist/ContentClient'
import type { DeploymentData } from 'dcl-catalyst-client/dist/utils/DeploymentBuilder'
import { base64ToBuffer } from 'lib/encoding/base64ToBlob'
import { call, put, select } from 'redux-saga/effects'
Expand Down Expand Up @@ -110,11 +114,18 @@ async function deploy(
pointers: [identity.address],
hashesByKey: contentHashes,
metadata
}
} as BuildEntityWithoutFilesOptions

const entity = {
type: EntityType.PROFILE,
pointers: [identity.address],
files: contentFiles,
metadata
} as BuildEntityOptions

// Build entity and group all files
const preparationData = await (contentFiles.size
? catalyst.buildEntity({ type: EntityType.PROFILE, pointers: [identity.address], files: contentFiles, metadata })
? catalyst.buildEntity(entity)
: catalyst.buildEntityWithoutNewFiles(entityWithoutNewFilesPayload))
// sign the entity id
const authChain = Authenticator.signPayload(identity, preparationData.entityId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EcsMathReadOnlyQuaternion, EcsMathReadOnlyVector3 } from '@dcl/ecs-math'

import { Authenticator } from '@dcl/crypto'
import { Avatar, generateLazyValidator, JSONSchema } from '@dcl/schemas'
import { Avatar, generateLazyValidator, JSONSchema, WearableCategory } from '@dcl/schemas'
import { DEBUG, ethereumConfigurations, playerHeight, WORLD_EXPLORER } from 'config'
import { isAddress } from 'eth-connect'
import future, { IFuture } from 'fp-future'
Expand Down Expand Up @@ -150,6 +150,7 @@ export type RendererSaveProfile = {
a: number
}
wearables: string[]
forceRender?: string[]
emotes: {
slot: number
urn: string
Expand Down Expand Up @@ -197,6 +198,7 @@ export const rendererSaveProfileSchemaV0: JSONSchema<RendererSaveProfile> = {
hairColor: color3Schema,
skinColor: color3Schema,
wearables: { type: 'array', items: { type: 'string' } },
forceRender: { type: 'array', items: { type: 'string' }, nullable: true },
emotes: { type: 'array', items: emoteSchema }
}
}
Expand All @@ -220,6 +222,7 @@ export const rendererSaveProfileSchemaV1: JSONSchema<RendererSaveProfile> = {
hairColor: color3Schema,
skinColor: color3Schema,
wearables: { type: 'array', items: { type: 'string' } },
forceRender: { type: 'array', items: { type: 'string' }, nullable: true },
emotes: { type: 'array', items: emoteSchema }
}
}
Expand Down Expand Up @@ -436,6 +439,7 @@ export class BrowserInterface {
hair: { color: changes.avatar.hairColor },
skin: { color: changes.avatar.skinColor },
wearables: changes.avatar.wearables,
forceRender: (changes.avatar.forceRender ?? []).map((category) => category as WearableCategory),
snapshots: {
body: changes.body,
face256: changes.face256
Expand All @@ -452,6 +456,7 @@ export class BrowserInterface {
hair: { color: changes.avatar.hairColor },
skin: { color: changes.avatar.skinColor },
wearables: changes.avatar.wearables,
forceRender: (changes.avatar.forceRender ?? []).map((category) => category as WearableCategory),
emotes: (changes.avatar.emotes ?? []).map((value, index) => ({ slot: index, urn: value as any as string })),
snapshots: {
body: changes.body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public override IEnumerator ApplyChanges(BaseModel newModel)
isGlobalSceneAvatar = scene.sceneData.sceneNumber == EnvironmentSettings.AVATAR_GLOBAL_SCENE_NUMBER;

var model = (AvatarModel) newModel;

bool needsLoading = !model.HaveSameWearablesAndColors(currentAvatar);
currentAvatar.CopyFrom(model);

Expand Down Expand Up @@ -214,6 +213,7 @@ public override IEnumerator ApplyChanges(BaseModel newModel)
eyesColor = model.eyeColor,
skinColor = model.skinColor,
hairColor = model.hairColor,
forceRender = new HashSet<string>(userProfileBridge.Get(model.id).avatar.forceRender ?? new HashSet<string>()),
}, loadingCts.Token);

// Yielding a UniTask doesn't do anything, we manually wait until the avatar is ready
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ async UniTaskVoid LoadUserProfileAsync(UserProfile userProfile, CancellationToke
model.skinColor = userProfile.avatar.skinColor;
model.hairColor = userProfile.avatar.hairColor;
model.eyesColor = userProfile.avatar.eyeColor;

model.forceRender = new HashSet<string>(userProfile.avatar.forceRender);
model.wearables.Clear();
previewEquippedWearables.Clear();

Expand All @@ -243,9 +243,10 @@ async UniTaskVoid LoadUserProfileAsync(UserProfile userProfile, CancellationToke
}
}

EquipWearable(wearable, EquipWearableSource.None, false, false);
EquipWearable(wearable, EquipWearableSource.None, false, false, false);
}

avatarSlotsHUDController.Recalculate(model.forceRender);
view.UpdateAvatarPreview(model.ToAvatarModel());
}
catch (OperationCanceledException) { }
Expand Down Expand Up @@ -395,21 +396,23 @@ private void UnEquipWearableFromSlot(string wearableId, UnequipWearableSource so
private void EquipWearable(string wearableId,
EquipWearableSource source = EquipWearableSource.None,
bool setAsDirty = true,
bool updateAvatarPreview = true)
bool updateAvatarPreview = true,
bool resetOverride = true)
{
if (!wearablesCatalogService.WearablesCatalog.TryGetValue(wearableId, out WearableItem wearable))
{
Debug.LogError($"Cannot equip wearable {wearableId}");
return;
}

EquipWearable(wearable, source, setAsDirty, updateAvatarPreview);
EquipWearable(wearable, source, setAsDirty, updateAvatarPreview, resetOverride);
}

private void EquipWearable(WearableItem wearable,
EquipWearableSource source = EquipWearableSource.None,
bool setAsDirty = true,
bool updateAvatarPreview = true)
bool updateAvatarPreview = true,
bool resetOverride = true)
{
string wearableId = wearable.id;

Expand All @@ -432,7 +435,8 @@ private void EquipWearable(WearableItem wearable,
model.wearables.Add(wearableId, wearable);
previewEquippedWearables.Add(wearableId);

ResetOverridesOfAffectedCategories(wearable, setAsDirty);
if (resetOverride)
ResetOverridesOfAffectedCategories(wearable, setAsDirty);

avatarSlotsHUDController.Equip(wearable, ownUserProfile.avatar.bodyShape, model.forceRender);
wearableGridController.Equip(wearableId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public AvatarModel ToAvatarModel()
hairColor = hairColor,
skinColor = skinColor,
eyeColor = eyesColor,
forceRender = forceRender
forceRender = new HashSet<string>(forceRender)
};
}

Expand All @@ -36,6 +36,7 @@ public void Update(BackpackEditorHUDModel newModel)
hairColor = newModel.hairColor;
skinColor = newModel.skinColor;
eyesColor = newModel.eyesColor;
forceRender = new HashSet<string>(newModel.forceRender);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private async UniTask UpdateModelAsync(AvatarModel newModel, CancellationToken c
eyesColor = newModel.eyeColor,
hairColor = newModel.hairColor,
skinColor = newModel.skinColor,
forceRender = newModel.forceRender
forceRender = new HashSet<string>(newModel.forceRender)
}, ct);
}
catch (Exception e) when (e is not OperationCanceledException) { Debug.LogException(e); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ private async UniTaskVoid LoadingAvatarRoutine(UserProfile profile, Cancellation
eyesColor = profile.avatar.eyeColor,
skinColor = profile.avatar.skinColor,
hairColor = profile.avatar.hairColor,
forceRender = new HashSet<string>(profile.avatar.forceRender)
}, ct);

if (avatar.lodLevel <= 1)
Expand Down
Loading

0 comments on commit ba1a149

Please sign in to comment.