Skip to content

Commit

Permalink
fix: add categories priority list for hiding/replacing (adr-239) (#116)
Browse files Browse the repository at this point in the history
* fix: add categories priority list for hiding/replacing (adr-239)

* forceRender applied after computing hides (same as EA)
  • Loading branch information
leanmendoza authored Sep 28, 2024
1 parent 8a0c65c commit b8730e6
Showing 1 changed file with 48 additions and 23 deletions.
71 changes: 48 additions & 23 deletions src/lib/babylon/slots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,40 @@ const categoriesHiddenBySkin = [
BodyPartCategory.HANDS,
]

// based on https://adr.decentraland.org/adr/ADR-239
const categoriesPriority = [
WearableCategory.SKIN,
WearableCategory.UPPER_BODY,
WearableCategory.HANDS_WEAR,
WearableCategory.LOWER_BODY,
WearableCategory.FEET,
WearableCategory.HELMET,
WearableCategory.HAT,
WearableCategory.TOP_HEAD,
WearableCategory.MASK,
WearableCategory.EYEWEAR,
WearableCategory.EARRING,
WearableCategory.TIARA,
WearableCategory.HAIR,
WearableCategory.EYEBROWS,
WearableCategory.EYES,
WearableCategory.MOUTH,
WearableCategory.FACIAL_HAIR,
WearableCategory.BODY_SHAPE
]

function getHides(wearable: WearableDefinition) {
const category = wearable.data.category
const replaced = wearable.data.replaces || []
const hidden = wearable.data.hides || []
if (category === WearableCategory.SKIN) {
hidden.push(...categoriesHiddenBySkin)
}
return Array.from(new Set([...replaced, ...hidden])).filter(
($) => $ !== category
)
}

export function getSlots(config: PreviewConfig) {
const slots = new Map<HideableWearableCategory, WearableDefinition>()

Expand Down Expand Up @@ -63,35 +97,26 @@ export function getSlots(config: PreviewConfig) {
slots.set(slot, wearable)
}
}
let hasSkin = false
// grab only the wearables that ended up in the map, and process in reverse order (last wearables can hide/replace the first ones)
wearables = wearables.filter((wearable) => slots.get(wearable.data.category) === wearable).reverse()
const forceRender = config.forceRender || []
const alreadyRemoved = new Set<HideableWearableCategory>()
for (const wearable of wearables) {
const category = wearable.data.category
if (alreadyRemoved.has(category)) {
for (const category of categoriesPriority) {
const wearable = slots.get(category)
if (!wearable) {
continue
}
const replaced = wearable.data.replaces || []
const hidden = wearable.data.hides || []
const toRemove = Array.from(new Set([...replaced, ...hidden])).filter(
(category) => !config.forceRender?.includes(category)
)
for (const slot of toRemove) {
if (slot !== category) {
slots.delete(slot)
alreadyRemoved.add(slot)
}

if (alreadyRemoved.has(category)) {
continue
}
if (wearable.data.category === WearableCategory.SKIN) {
hasSkin = true

for (const slot of getHides(wearable)) {
alreadyRemoved.add(slot)
}
}
// skins hide all the following slots
if (hasSkin) {
for (const category of categoriesHiddenBySkin) {
slots.delete(category)
}

const toHide = Array.from(alreadyRemoved).filter(category => !forceRender.includes(category))
for (const category of toHide) {
slots.delete(category)
}

return slots
Expand Down

0 comments on commit b8730e6

Please sign in to comment.