omit glitched pet states, add IDs

This commit is contained in:
Matt Dunn-Rankin 2020-05-02 20:48:32 -07:00
parent da82dba294
commit d9b447bbb4
4 changed files with 37 additions and 10 deletions

View file

@ -47,8 +47,10 @@ const typeDefs = gql`
} }
type PetAppearance { type PetAppearance {
id: ID!
genderPresentation: GenderPresentation genderPresentation: GenderPresentation
emotion: Emotion emotion: Emotion
approximateThumbnailUrl: String!
layers: [AppearanceLayer!]! layers: [AppearanceLayer!]!
} }
@ -159,6 +161,7 @@ const resolvers = {
}, },
}, },
PetAppearance: { PetAppearance: {
id: ({ petState }) => petState.id,
genderPresentation: ({ petState }) => { genderPresentation: ({ petState }) => {
if (petState.female === 1) { if (petState.female === 1) {
return "FEMININE"; return "FEMININE";
@ -187,6 +190,9 @@ const resolvers = {
); );
} }
}, },
approximateThumbnailUrl: ({ petType, petState }) => {
return `http://pets.neopets.com/cp/${petType.basicImageHash}/${petState.moodId}/1.png`;
},
layers: async ({ petState }, _, { petSwfAssetLoader }) => { layers: async ({ petState }, _, { petSwfAssetLoader }) => {
const swfAssets = await petSwfAssetLoader.load(petState.id); const swfAssets = await petSwfAssetLoader.load(petState.id);
return swfAssets; return swfAssets;
@ -280,26 +286,26 @@ const resolvers = {
petAppearance: async ( petAppearance: async (
_, _,
{ speciesId, colorId }, { speciesId, colorId },
{ petTypeLoader, petStateLoader, petSwfAssetLoader } { petTypeLoader, petStateLoader }
) => { ) => {
const petType = await petTypeLoader.load({ const petType = await petTypeLoader.load({
speciesId, speciesId,
colorId, colorId,
}); });
const petStates = await petStateLoader.load(petType.id); const petStates = await petStateLoader.load(petType.id);
return { petState: petStates[0] }; return { petType, petState: petStates[0] };
}, },
petAppearances: async ( petAppearances: async (
_, _,
{ speciesId, colorId }, { speciesId, colorId },
{ petTypeLoader, petStateLoader, petSwfAssetLoader } { petTypeLoader, petStateLoader }
) => { ) => {
const petType = await petTypeLoader.load({ const petType = await petTypeLoader.load({
speciesId, speciesId,
colorId, colorId,
}); });
const petStates = await petStateLoader.load(petType.id); const petStates = await petStateLoader.load(petType.id);
return petStates.map((petState) => ({ petState })); return petStates.map((petState) => ({ petType, petState }));
}, },
petOnNeopetsDotCom: async (_, { petName }) => { petOnNeopetsDotCom: async (_, { petName }) => {
const petData = await neopets.loadPetData(petName); const petData = await neopets.loadPetData(petName);

View file

@ -229,8 +229,9 @@ const buildPetStateLoader = (db) =>
new DataLoader(async (petTypeIds) => { new DataLoader(async (petTypeIds) => {
const qs = petTypeIds.map((_) => "?").join(","); const qs = petTypeIds.map((_) => "?").join(",");
const [rows, _] = await db.execute( const [rows, _] = await db.execute(
`SELECT * FROM pet_states WHERE pet_type_id IN (${qs}) `SELECT * FROM pet_states
ORDER BY glitched ASC, (mood_id = 1) DESC`, WHERE pet_type_id IN (${qs}) AND glitched = 0
ORDER BY (mood_id = 1) DESC`,
petTypeIds petTypeIds
); );

View file

@ -31,8 +31,9 @@ describe("PetAppearance", () => {
], ],
], ],
Array [ Array [
"SELECT * FROM pet_states WHERE pet_type_id IN (?) "SELECT * FROM pet_states
ORDER BY glitched ASC, (mood_id = 1) DESC", WHERE pet_type_id IN (?) AND glitched = 0
ORDER BY (mood_id = 1) DESC",
Array [ Array [
"2", "2",
], ],
@ -67,8 +68,10 @@ describe("PetAppearance", () => {
query: gql` query: gql`
query { query {
petAppearances(speciesId: "54", colorId: "75") { petAppearances(speciesId: "54", colorId: "75") {
id
genderPresentation genderPresentation
emotion emotion
approximateThumbnailUrl
layers { layers {
id id
imageUrl(size: SIZE_600) imageUrl(size: SIZE_600)
@ -93,8 +96,9 @@ describe("PetAppearance", () => {
], ],
], ],
Array [ Array [
"SELECT * FROM pet_states WHERE pet_type_id IN (?) "SELECT * FROM pet_states
ORDER BY glitched ASC, (mood_id = 1) DESC", WHERE pet_type_id IN (?) AND glitched = 0
ORDER BY (mood_id = 1) DESC",
Array [ Array [
"2", "2",
], ],

View file

@ -55,8 +55,10 @@ exports[`PetAppearance loads multiple for species and color 1`] = `
Object { Object {
"petAppearances": Array [ "petAppearances": Array [
Object { Object {
"approximateThumbnailUrl": "http://pets.neopets.com/cp/vghhzlgf/1/1.png",
"emotion": "HAPPY", "emotion": "HAPPY",
"genderPresentation": "FEMININE", "genderPresentation": "FEMININE",
"id": "17723",
"layers": Array [ "layers": Array [
Object { Object {
"id": "5995", "id": "5995",
@ -103,8 +105,10 @@ Object {
], ],
}, },
Object { Object {
"approximateThumbnailUrl": "http://pets.neopets.com/cp/vghhzlgf/1/1.png",
"emotion": "HAPPY", "emotion": "HAPPY",
"genderPresentation": "MASCULINE", "genderPresentation": "MASCULINE",
"id": "17742",
"layers": Array [ "layers": Array [
Object { Object {
"id": "5995", "id": "5995",
@ -151,8 +155,10 @@ Object {
], ],
}, },
Object { Object {
"approximateThumbnailUrl": "http://pets.neopets.com/cp/vghhzlgf/4/1.png",
"emotion": "SICK", "emotion": "SICK",
"genderPresentation": "FEMININE", "genderPresentation": "FEMININE",
"id": "10014",
"layers": Array [ "layers": Array [
Object { Object {
"id": "5995", "id": "5995",
@ -199,8 +205,10 @@ Object {
], ],
}, },
Object { Object {
"approximateThumbnailUrl": "http://pets.neopets.com/cp/vghhzlgf/4/1.png",
"emotion": "SICK", "emotion": "SICK",
"genderPresentation": "MASCULINE", "genderPresentation": "MASCULINE",
"id": "11089",
"layers": Array [ "layers": Array [
Object { Object {
"id": "5995", "id": "5995",
@ -247,8 +255,10 @@ Object {
], ],
}, },
Object { Object {
"approximateThumbnailUrl": "http://pets.neopets.com/cp/vghhzlgf/2/1.png",
"emotion": "SAD", "emotion": "SAD",
"genderPresentation": "FEMININE", "genderPresentation": "FEMININE",
"id": "5991",
"layers": Array [ "layers": Array [
Object { Object {
"id": "5995", "id": "5995",
@ -295,8 +305,10 @@ Object {
], ],
}, },
Object { Object {
"approximateThumbnailUrl": "http://pets.neopets.com/cp/vghhzlgf/2/1.png",
"emotion": "SAD", "emotion": "SAD",
"genderPresentation": "MASCULINE", "genderPresentation": "MASCULINE",
"id": "436",
"layers": Array [ "layers": Array [
Object { Object {
"id": "5995", "id": "5995",
@ -343,8 +355,10 @@ Object {
], ],
}, },
Object { Object {
"approximateThumbnailUrl": "http://pets.neopets.com/cp/vghhzlgf/null/1.png",
"emotion": null, "emotion": null,
"genderPresentation": null, "genderPresentation": null,
"id": "2",
"layers": Array [ "layers": Array [
Object { Object {
"id": "5995", "id": "5995",
@ -398,8 +412,10 @@ Object {
], ],
}, },
Object { Object {
"approximateThumbnailUrl": "http://pets.neopets.com/cp/vghhzlgf/null/1.png",
"emotion": null, "emotion": null,
"genderPresentation": null, "genderPresentation": null,
"id": "4751",
"layers": Array [ "layers": Array [
Object { Object {
"id": "5995", "id": "5995",