forked from OpenNeo/impress-2020
Compare commits
No commits in common. "add-altStyleId" and "main" have entirely different histories.
add-altSty
...
main
2 changed files with 5 additions and 46 deletions
|
|
@ -33,12 +33,9 @@ const resolvers = {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const speciesId = customPetData.custom_pet.species_id;
|
|
||||||
const baseColorId = customPetData.custom_pet.color_id;
|
|
||||||
|
|
||||||
const petType = await petTypeBySpeciesAndColorLoader.load({
|
const petType = await petTypeBySpeciesAndColorLoader.load({
|
||||||
speciesId,
|
speciesId: customPetData.custom_pet.species_id,
|
||||||
colorId: baseColorId,
|
colorId: customPetData.custom_pet.color_id,
|
||||||
});
|
});
|
||||||
const petStates = petType
|
const petStates = petType
|
||||||
? await petStatesForPetTypeLoader.load(petType.id)
|
? await petStatesForPetTypeLoader.load(petType.id)
|
||||||
|
|
@ -55,33 +52,8 @@ 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, altColorId };
|
return { id: petState.id };
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
||||||
|
|
@ -99,7 +71,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, altColorId };
|
return { id: petState.id };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,7 +85,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, altColorId };
|
return { id: petState.id };
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
|
|
||||||
|
|
@ -78,18 +78,6 @@ const typeDefs = gql`
|
||||||
"""
|
"""
|
||||||
id: ID!
|
id: ID!
|
||||||
|
|
||||||
"""
|
|
||||||
The ID of the alt style used to render this appearance, if any.
|
|
||||||
Null when this appearance is not using an alt style.
|
|
||||||
"""
|
|
||||||
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!
|
||||||
|
|
@ -285,7 +273,6 @@ 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