move restrictedZones from layer to PetAppearance

okay so the PetAppearance restrictions are stored on the asset, because that's how they're defined on Neopets.com too

but I think that's a confusing API, so here I define `PetAppearance.restrictedZones`, which just maps over the layers and aggregates the zones server-side, same as we would have done on the client

I think that's much easier to understand than having layer contain a field, but having to know that item restrictions _don't_ work that way, you know?
This commit is contained in:
Emi Matchu 2020-08-31 23:18:30 -07:00
parent e40ec9bb05
commit 6dc53814c2
4 changed files with 149 additions and 141 deletions

View file

@ -123,10 +123,7 @@ export function getVisibleLayers(petAppearance, itemAppearances) {
.map((a) => a.restrictedZones)
.flat()
.map((z) => z.id);
const petRestrictedZoneIds = petLayers
.map((l) => l.restrictedZones)
.flat()
.map((z) => z.id);
const petRestrictedZoneIds = petAppearance.restrictedZones.map((z) => z.id);
const allRestrictedZoneIds = new Set([
...itemRestrictedZoneIds,
...petRestrictedZoneIds,
@ -174,9 +171,9 @@ export const petAppearanceFragment = gql`
id
depth @client
}
}
restrictedZones {
id
}
}
}
`;

View file

@ -103,6 +103,7 @@ const typeDefs = gql`
bodyId: ID!
layers: [AppearanceLayer!]!
restrictedZones: [Zone!]!
petStateId: ID! # Deprecated, an alias for id
# Whether this PetAppearance is known to look incorrect. This is a manual
@ -165,6 +166,8 @@ const typeDefs = gql`
this is generally empty and the restriction is on the ItemAppearance, not
the individual layers. For pet layers, this is generally used for
Unconverted pets.
Deprecated, aggregated into PetAppearance for a simpler API.
"""
restrictedZones: [Zone!]!
}
@ -384,6 +387,17 @@ const resolvers = {
const swfAssets = await petSwfAssetLoader.load(id);
return swfAssets;
},
restrictedZones: async ({ id }, _, { petSwfAssetLoader }) => {
// The restricted zones are defined on the layers. Load them and aggegate
// the zones, then uniquify and sort them for ease of use.
const swfAssets = await petSwfAssetLoader.load(id);
let restrictedZoneIds = swfAssets
.map((sa) => getRestrictedZoneIds(sa.zonesRestrict))
.flat();
restrictedZoneIds = [...new Set(restrictedZoneIds)];
restrictedZoneIds.sort((a, b) => parseInt(a) - parseInt(b));
return restrictedZoneIds.map((id) => ({ id }));
},
petStateId: ({ id }) => id,
isGlitched: async ({ id }, _, { petStateLoader }) => {
const petState = await petStateLoader.load(id);

View file

@ -27,12 +27,13 @@ describe("PetAppearance", () => {
zone {
depth
}
}
restrictedZones {
id
}
}
}
}
`,
});
@ -224,12 +225,13 @@ describe("PetAppearance", () => {
zone {
depth
}
}
restrictedZones {
id
}
}
}
}
`,
});

View file

@ -13,7 +13,6 @@ Object {
Object {
"id": "5995",
"imageUrl": "https://impress-asset-images.s3.amazonaws.com/biology/000/000/007/7941/600x600.png?v2-0",
"restrictedZones": Array [],
"svgUrl": "http://images.neopets.com/cp/bio/data/000/000/007/7941_2c4cc4b846/7941.svg",
"zone": Object {
"depth": 18,
@ -22,7 +21,6 @@ Object {
Object {
"id": "5996",
"imageUrl": "https://impress-asset-images.s3.amazonaws.com/biology/000/000/007/7942/600x600.png?v2-0",
"restrictedZones": Array [],
"svgUrl": "http://images.neopets.com/cp/bio/data/000/000/007/7942_2eab06fd7b/7942.svg",
"zone": Object {
"depth": 7,
@ -31,7 +29,6 @@ Object {
Object {
"id": "6000",
"imageUrl": "https://impress-asset-images.s3.amazonaws.com/biology/000/000/007/7946/600x600.png?v2-0",
"restrictedZones": Array [],
"svgUrl": "http://images.neopets.com/cp/bio/data/000/000/007/7946_0348dad587/7946.svg",
"zone": Object {
"depth": 40,
@ -40,7 +37,6 @@ Object {
Object {
"id": "16467",
"imageUrl": "https://impress-asset-images.s3.amazonaws.com/biology/000/000/024/24008/600x600.png?v2-0",
"restrictedZones": Array [],
"svgUrl": "http://images.neopets.com/cp/bio/data/000/000/024/24008_a05fe9876a/24008.svg",
"zone": Object {
"depth": 34,
@ -49,7 +45,6 @@ Object {
Object {
"id": "19784",
"imageUrl": "https://impress-asset-images.s3.amazonaws.com/biology/000/000/028/28892/600x600.png?v2-1313418652000",
"restrictedZones": Array [],
"svgUrl": "http://images.neopets.com/cp/bio/data/000/000/028/28892_a8e3a8b430/28892.svg",
"zone": Object {
"depth": 37,
@ -58,13 +53,13 @@ Object {
Object {
"id": "178150",
"imageUrl": "https://impress-asset-images.s3.amazonaws.com/biology/000/000/036/36887/600x600.png?v2-1354240708000",
"restrictedZones": Array [],
"svgUrl": "http://images.neopets.com/cp/bio/data/000/000/036/36887_a335fbba09/36887.svg",
"zone": Object {
"depth": 38,
},
},
],
"restrictedZones": Array [],
"species": Object {
"id": "54",
"name": "Zafara",
@ -571,6 +566,12 @@ Object {
Object {
"id": "9941",
"imageUrl": "https://impress-asset-images.s3.amazonaws.com/biology/000/000/013/13024/600x600.png?v2-0",
"svgUrl": "http://images.neopets.com/cp/bio/data/000/000/013/13024_18911a85d1/13024.svg",
"zone": Object {
"depth": 48,
},
},
],
"restrictedZones": Array [
Object {
"id": "4",
@ -693,12 +694,6 @@ Object {
"id": "43",
},
],
"svgUrl": "http://images.neopets.com/cp/bio/data/000/000/013/13024_18911a85d1/13024.svg",
"zone": Object {
"depth": 48,
},
},
],
"species": Object {
"id": "1",
"name": "Acara",