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
}
}
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,9 +27,10 @@ describe("PetAppearance", () => {
zone {
depth
}
restrictedZones {
id
}
}
restrictedZones {
id
}
}
}
@ -224,9 +225,10 @@ describe("PetAppearance", () => {
zone {
depth
}
restrictedZones {
id
}
}
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,134 +566,134 @@ Object {
Object {
"id": "9941",
"imageUrl": "https://impress-asset-images.s3.amazonaws.com/biology/000/000/013/13024/600x600.png?v2-0",
"restrictedZones": Array [
Object {
"id": "4",
},
Object {
"id": "5",
},
Object {
"id": "6",
},
Object {
"id": "7",
},
Object {
"id": "8",
},
Object {
"id": "9",
},
Object {
"id": "10",
},
Object {
"id": "11",
},
Object {
"id": "12",
},
Object {
"id": "13",
},
Object {
"id": "14",
},
Object {
"id": "15",
},
Object {
"id": "16",
},
Object {
"id": "17",
},
Object {
"id": "18",
},
Object {
"id": "19",
},
Object {
"id": "20",
},
Object {
"id": "21",
},
Object {
"id": "22",
},
Object {
"id": "23",
},
Object {
"id": "24",
},
Object {
"id": "25",
},
Object {
"id": "26",
},
Object {
"id": "27",
},
Object {
"id": "28",
},
Object {
"id": "29",
},
Object {
"id": "30",
},
Object {
"id": "31",
},
Object {
"id": "32",
},
Object {
"id": "33",
},
Object {
"id": "34",
},
Object {
"id": "35",
},
Object {
"id": "36",
},
Object {
"id": "37",
},
Object {
"id": "38",
},
Object {
"id": "39",
},
Object {
"id": "40",
},
Object {
"id": "41",
},
Object {
"id": "42",
},
Object {
"id": "43",
},
],
"svgUrl": "http://images.neopets.com/cp/bio/data/000/000/013/13024_18911a85d1/13024.svg",
"zone": Object {
"depth": 48,
},
},
],
"restrictedZones": Array [
Object {
"id": "4",
},
Object {
"id": "5",
},
Object {
"id": "6",
},
Object {
"id": "7",
},
Object {
"id": "8",
},
Object {
"id": "9",
},
Object {
"id": "10",
},
Object {
"id": "11",
},
Object {
"id": "12",
},
Object {
"id": "13",
},
Object {
"id": "14",
},
Object {
"id": "15",
},
Object {
"id": "16",
},
Object {
"id": "17",
},
Object {
"id": "18",
},
Object {
"id": "19",
},
Object {
"id": "20",
},
Object {
"id": "21",
},
Object {
"id": "22",
},
Object {
"id": "23",
},
Object {
"id": "24",
},
Object {
"id": "25",
},
Object {
"id": "26",
},
Object {
"id": "27",
},
Object {
"id": "28",
},
Object {
"id": "29",
},
Object {
"id": "30",
},
Object {
"id": "31",
},
Object {
"id": "32",
},
Object {
"id": "33",
},
Object {
"id": "34",
},
Object {
"id": "35",
},
Object {
"id": "36",
},
Object {
"id": "37",
},
Object {
"id": "38",
},
Object {
"id": "39",
},
Object {
"id": "40",
},
Object {
"id": "41",
},
Object {
"id": "42",
},
Object {
"id": "43",
},
],
"species": Object {
"id": "1",
"name": "Acara",