forked from OpenNeo/impress-2020
Add altColorId support to PetAppearance
This commit is contained in:
parent
a0a7cfba01
commit
8c1de5e901
2 changed files with 39 additions and 7 deletions
|
|
@ -33,12 +33,12 @@ const resolvers = {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Neopets may omit this field entirely; treat "missing" as null.
|
const speciesId = customPetData.custom_pet.species_id;
|
||||||
const altStyleId = customPetData.custom_pet.alt_style ?? null;
|
const baseColorId = customPetData.custom_pet.color_id;
|
||||||
|
|
||||||
const petType = await petTypeBySpeciesAndColorLoader.load({
|
const petType = await petTypeBySpeciesAndColorLoader.load({
|
||||||
speciesId: customPetData.custom_pet.species_id,
|
speciesId,
|
||||||
colorId: customPetData.custom_pet.color_id,
|
colorId: baseColorId,
|
||||||
});
|
});
|
||||||
const petStates = petType
|
const petStates = petType
|
||||||
? await petStatesForPetTypeLoader.load(petType.id)
|
? await petStatesForPetTypeLoader.load(petType.id)
|
||||||
|
|
@ -55,8 +55,33 @@ const resolvers = {
|
||||||
.sort((a, b) => Number(a) - Number(b))
|
.sort((a, b) => Number(a) - Number(b))
|
||||||
.join(",");
|
.join(",");
|
||||||
petState = petStates.find((ps) => ps.swfAssetIds === swfAssetIdsString);
|
petState = petStates.find((ps) => ps.swfAssetIds === swfAssetIdsString);
|
||||||
|
|
||||||
|
// Neopets may omit these fields entirely; treat "missing" as null.
|
||||||
|
const altStyleId = customPetData.custom_pet.alt_style;
|
||||||
|
const altColorId = customPetData.custom_pet.alt_color;
|
||||||
|
|
||||||
if (petState) {
|
if (petState) {
|
||||||
return { id: petState.id, altStyleId };
|
return { id: petState.id, altStyleId, altColorId };
|
||||||
|
}
|
||||||
|
|
||||||
|
// If that didn't work, and Neopets reported an alt color, try looking up
|
||||||
|
// the same exact-assets pet state on the species+altColor pair.
|
||||||
|
if (altColorId != null && altColorId !== baseColorId) {
|
||||||
|
const altColorPetType = await petTypeBySpeciesAndColorLoader.load({
|
||||||
|
speciesId,
|
||||||
|
colorId: altColorId,
|
||||||
|
});
|
||||||
|
if (altColorPetType) {
|
||||||
|
const altColorPetStates = await petStatesForPetTypeLoader.load(
|
||||||
|
altColorPetType.id,
|
||||||
|
);
|
||||||
|
const altColorPetState = altColorPetStates.find(
|
||||||
|
(ps) => ps.swfAssetIds === swfAssetIdsString,
|
||||||
|
);
|
||||||
|
if (altColorPetState) {
|
||||||
|
return { id: altColorPetState.id, altStyleId, altColorId };
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next, look for a pet state matching the same pose. (This can happen if
|
// Next, look for a pet state matching the same pose. (This can happen if
|
||||||
|
|
@ -74,7 +99,7 @@ const resolvers = {
|
||||||
`because it matches pose ${pose}. Actual pet state for these ` +
|
`because it matches pose ${pose}. Actual pet state for these ` +
|
||||||
`assets not found: ${swfAssetIdsString}`,
|
`assets not found: ${swfAssetIdsString}`,
|
||||||
);
|
);
|
||||||
return { id: petState.id, altStyleId };
|
return { id: petState.id, altStyleId, altColorId };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,7 +113,7 @@ const resolvers = {
|
||||||
`as an UNKNOWN fallback pose. Actual pet state for these ` +
|
`as an UNKNOWN fallback pose. Actual pet state for these ` +
|
||||||
`assets not found: ${swfAssetIdsString}`,
|
`assets not found: ${swfAssetIdsString}`,
|
||||||
);
|
);
|
||||||
return { id: petState.id, altStyleId };
|
return { id: petState.id, altStyleId, altColorId };
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we still don't have a pet state, raise an error. (This can happen
|
// If we still don't have a pet state, raise an error. (This can happen
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,12 @@ const typeDefs = gql`
|
||||||
"""
|
"""
|
||||||
altStyleId: ID
|
altStyleId: ID
|
||||||
|
|
||||||
|
"""
|
||||||
|
The ID of the alt color used to render this appearance, if any.
|
||||||
|
Null when this appearance is not using an alt style.
|
||||||
|
"""
|
||||||
|
altColorId: ID
|
||||||
|
|
||||||
species: Species!
|
species: Species!
|
||||||
color: Color!
|
color: Color!
|
||||||
pose: Pose!
|
pose: Pose!
|
||||||
|
|
@ -279,6 +285,7 @@ const resolvers = {
|
||||||
},
|
},
|
||||||
|
|
||||||
PetAppearance: {
|
PetAppearance: {
|
||||||
|
altColorId: ({ altColorId }) => (altColorId),
|
||||||
id: ({ id, altStyleId }) => {
|
id: ({ id, altStyleId }) => {
|
||||||
if (altStyleId != null) {
|
if (altStyleId != null) {
|
||||||
return `${id}-with-alt-style-${altStyleId}`;
|
return `${id}-with-alt-style-${altStyleId}`;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue