From 020ac572e4577a90d153fd8370be7ffadc98cac2 Mon Sep 17 00:00:00 2001 From: Matchu Date: Mon, 12 Apr 2021 18:30:41 -0700 Subject: [PATCH] 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. --- src/server/types/Pet.js | 52 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/src/server/types/Pet.js b/src/server/types/Pet.js index 4655e75..96aa0b1 100644 --- a/src/server/types/Pet.js +++ b/src/server/types/Pet.js @@ -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); + + 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); - const petState = petStates.find((ps) => getPoseFromPetState(ps) === pose); - return { id: petState.id }; + 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) => ({