Use asset IDs when looking up pet's PetAppearance

This was causing a bug where unlabeled poses would cause pet lookups to fail!

Now, we return the actual pet appearance for the pet, if we have it, by matching against asset IDs first.
This commit is contained in:
Emi Matchu 2021-04-12 18:30:41 -07:00
parent 4cb47f3c7c
commit 020ac572e4

View file

@ -32,7 +32,7 @@ const resolvers = {
pose: ({ customPetData, petMetaData }) =>
getPoseFromPetData(petMetaData, customPetData),
petAppearance: async (
{ customPetData, petMetaData },
{ name, customPetData, petMetaData },
_,
{ petTypeBySpeciesAndColorLoader, petStatesForPetTypeLoader }
) => {
@ -41,9 +41,55 @@ const resolvers = {
colorId: customPetData.custom_pet.color_id,
});
const petStates = await petStatesForPetTypeLoader.load(petType.id);
const pose = getPoseFromPetData(petMetaData, customPetData);
const petState = petStates.find((ps) => getPoseFromPetState(ps) === pose);
let petState;
// First, look for a pet state containing exactly the same assets as this
// one.
const swfAssetIdsString = Object.values(
customPetData.custom_pet.biology_by_zone
)
.map((b) => b.part_id)
.sort((a, b) => Number(a) - Number(b))
.join(",");
petState = petStates.find((ps) => ps.swfAssetIds === swfAssetIdsString);
if (petState) {
return { id: petState.id };
}
// Next, look for a pet state matching the same pose. (This can happen if
// modeling data for this pet hasn't saved yet.)
const pose = getPoseFromPetData(petMetaData, customPetData);
petState = petStates.find((ps) => getPoseFromPetState(ps) === pose);
if (petState) {
console.warn(
`Warning: For pet "${name}", fell back to pet state ${petState.id} ` +
`because it matches pose ${pose}. Actual pet state for these ` +
`assets not found: ${swfAssetIdsString}`
);
return { id: petState.id };
}
// Finally, look for an UNKNOWN pet state. (This can happen if modeling
// data for this pet hasn't saved yet, and we haven't manually labeled a
// matching pose.)
petState = petStates.find((ps) => getPoseFromPetState(ps) === "UNKNOWN");
if (petState) {
console.warn(
`Warning: For pet "${name}", fell back to pet state ${petState.id} ` +
`as an UNKNOWN fallback pose. Actual pet state for these ` +
`assets not found: ${swfAssetIdsString}`
);
return { id: petState.id };
}
// If we still don't have a pet state, raise an error. (This can happen
// for a brand new new species/color combination, when the modeling data
// hasn't been saved yet.)
throw new Error(
`This pet's modeling data isn't loaded into our database yet, ` +
`sorry! Try using the Modeling Hub on Classic DTI to upload it first?`
);
},
wornItems: ({ customPetData }) =>
Object.values(customPetData.object_info_registry).map((o) => ({