use PetService to determine the correct pose
This commit is contained in:
parent
bcdd9af806
commit
29b9fe48c5
7 changed files with 59 additions and 12 deletions
|
@ -121,6 +121,7 @@ function SubmitPetForm() {
|
||||||
species {
|
species {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
pose
|
||||||
items {
|
items {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
@ -132,12 +133,12 @@ function SubmitPetForm() {
|
||||||
onCompleted: (data) => {
|
onCompleted: (data) => {
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
|
|
||||||
const { species, color, items } = data.petOnNeopetsDotCom;
|
const { species, color, pose, items } = data.petOnNeopetsDotCom;
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
name: petName,
|
name: petName,
|
||||||
species: species.id,
|
species: species.id,
|
||||||
color: color.id,
|
color: color.id,
|
||||||
pose: "HAPPY_FEM", // TODO: Ask PetService
|
pose,
|
||||||
});
|
});
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
params.append("objects[]", item.id);
|
params.append("objects[]", item.id);
|
||||||
|
|
|
@ -103,7 +103,6 @@ function SpeciesColorPicker({
|
||||||
const validPoses = getValidPoses(valids, speciesId, newColorId);
|
const validPoses = getValidPoses(valids, speciesId, newColorId);
|
||||||
const isValid = validPoses.size > 0;
|
const isValid = validPoses.size > 0;
|
||||||
const closestPose = getClosestPose(validPoses, idealPose);
|
const closestPose = getClosestPose(validPoses, idealPose);
|
||||||
console.log(idealPose, closestPose, validPoses);
|
|
||||||
onChange(species, newColor, isValid, closestPose);
|
onChange(species, newColor, isValid, closestPose);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -117,7 +116,6 @@ function SpeciesColorPicker({
|
||||||
const validPoses = getValidPoses(valids, newSpeciesId, colorId);
|
const validPoses = getValidPoses(valids, newSpeciesId, colorId);
|
||||||
const isValid = validPoses.size > 0;
|
const isValid = validPoses.size > 0;
|
||||||
const closestPose = getClosestPose(validPoses, idealPose);
|
const closestPose = getClosestPose(validPoses, idealPose);
|
||||||
console.log(idealPose, closestPose, validPoses);
|
|
||||||
onChange(newSpecies, color, isValid, closestPose);
|
onChange(newSpecies, color, isValid, closestPose);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -181,7 +179,6 @@ function pairIsValid(valids, speciesId, colorId) {
|
||||||
|
|
||||||
function getValidPoses(valids, speciesId, colorId) {
|
function getValidPoses(valids, speciesId, colorId) {
|
||||||
const pairByte = getPairByte(valids, speciesId, colorId);
|
const pairByte = getPairByte(valids, speciesId, colorId);
|
||||||
console.log("pair byte", pairByte.toString(2).padStart(8, "0"));
|
|
||||||
|
|
||||||
const validPoses = new Set();
|
const validPoses = new Set();
|
||||||
if (pairByte & 0b00000001) validPoses.add("HAPPY_MASC");
|
if (pairByte & 0b00000001) validPoses.add("HAPPY_MASC");
|
||||||
|
|
|
@ -6,6 +6,7 @@ const neopets = require("./neopets");
|
||||||
const {
|
const {
|
||||||
capitalize,
|
capitalize,
|
||||||
getPoseFromPetState,
|
getPoseFromPetState,
|
||||||
|
getPoseFromPetData,
|
||||||
getEmotion,
|
getEmotion,
|
||||||
getGenderPresentation,
|
getGenderPresentation,
|
||||||
} = require("./util");
|
} = require("./util");
|
||||||
|
@ -124,6 +125,7 @@ const typeDefs = gql`
|
||||||
type Outfit {
|
type Outfit {
|
||||||
species: Species!
|
species: Species!
|
||||||
color: Color!
|
color: Color!
|
||||||
|
pose: Pose!
|
||||||
items: [Item!]!
|
items: [Item!]!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,11 +356,15 @@ const resolvers = {
|
||||||
return petStates.map((petState) => ({ petType, petState }));
|
return petStates.map((petState) => ({ petType, petState }));
|
||||||
},
|
},
|
||||||
petOnNeopetsDotCom: async (_, { petName }) => {
|
petOnNeopetsDotCom: async (_, { petName }) => {
|
||||||
const petData = await neopets.loadPetData(petName);
|
const [petMetaData, customPetData] = await Promise.all([
|
||||||
|
neopets.loadPetMetaData(petName),
|
||||||
|
neopets.loadCustomPetData(petName),
|
||||||
|
]);
|
||||||
const outfit = {
|
const outfit = {
|
||||||
species: { id: petData.custom_pet.species_id },
|
species: { id: customPetData.custom_pet.species_id },
|
||||||
color: { id: petData.custom_pet.color_id },
|
color: { id: customPetData.custom_pet.color_id },
|
||||||
items: Object.values(petData.object_info_registry).map((o) => ({
|
pose: getPoseFromPetData(petMetaData, customPetData),
|
||||||
|
items: Object.values(customPetData.object_info_registry).map((o) => ({
|
||||||
id: o.obj_info_id,
|
id: o.obj_info_id,
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,13 +1,28 @@
|
||||||
const fetch = require("node-fetch");
|
const fetch = require("node-fetch");
|
||||||
|
|
||||||
async function loadPetData(petName) {
|
async function loadPetMetaData(petName) {
|
||||||
|
const url =
|
||||||
|
`http://www.neopets.com/amfphp/json.php/PetService.getPet` + `/${petName}`;
|
||||||
|
const res = await fetch(url);
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(
|
||||||
|
`for pet meta data, neopets.com returned: ` +
|
||||||
|
`${res.status} ${res.statusText}. (${url})`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const json = await res.json();
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadCustomPetData(petName) {
|
||||||
const url =
|
const url =
|
||||||
`http://www.neopets.com/amfphp/json.php/CustomPetService.getViewerData` +
|
`http://www.neopets.com/amfphp/json.php/CustomPetService.getViewerData` +
|
||||||
`/${petName}`;
|
`/${petName}`;
|
||||||
const res = await fetch(url);
|
const res = await fetch(url);
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`for pet data, neopets.com returned: ` +
|
`for custom pet data, neopets.com returned: ` +
|
||||||
`${res.status} ${res.statusText}. (${url})`
|
`${res.status} ${res.statusText}. (${url})`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -56,4 +71,4 @@ function convertSwfUrlToManifestUrl(swfUrl) {
|
||||||
return `http://images.neopets.com/cp/${type}/data/${folders}/manifest.json`;
|
return `http://images.neopets.com/cp/${type}/data/${folders}/manifest.json`;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { loadPetData, loadAssetManifest };
|
module.exports = { loadPetMetaData, loadCustomPetData, loadAssetManifest };
|
||||||
|
|
|
@ -13,6 +13,7 @@ describe("Pet", () => {
|
||||||
color {
|
color {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
pose
|
||||||
items {
|
items {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ Object {
|
||||||
"id": "48313",
|
"id": "48313",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"pose": "SAD_MASC",
|
||||||
"species": Object {
|
"species": Object {
|
||||||
"id": "54",
|
"id": "54",
|
||||||
},
|
},
|
||||||
|
|
|
@ -57,6 +57,31 @@ function getPoseFromPetState(petState) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPoseFromPetData(petMetaData, petCustomData) {
|
||||||
|
// TODO: Use custom data to decide if Unconverted.
|
||||||
|
const moodId = petMetaData.mood;
|
||||||
|
const genderId = petMetaData.gender;
|
||||||
|
if (String(moodId) === "1" && String(genderId) === "1") {
|
||||||
|
return "HAPPY_MASC";
|
||||||
|
} else if (String(moodId) === "1" && String(genderId) === "2") {
|
||||||
|
return "HAPPY_FEM";
|
||||||
|
} else if (String(moodId) === "2" && String(genderId) === "1") {
|
||||||
|
return "SAD_MASC";
|
||||||
|
} else if (String(moodId) === "2" && String(genderId) === "2") {
|
||||||
|
return "SAD_FEM";
|
||||||
|
} else if (String(moodId) === "4" && String(genderId) === "1") {
|
||||||
|
return "SICK_MASC";
|
||||||
|
} else if (String(moodId) === "4" && String(genderId) === "2") {
|
||||||
|
return "SICK_FEM";
|
||||||
|
} else {
|
||||||
|
throw new Error(
|
||||||
|
`could not identify pose: ` +
|
||||||
|
`moodId=${moodId}, ` +
|
||||||
|
`genderId=${genderId}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeRow(row) {
|
function normalizeRow(row) {
|
||||||
const normalizedRow = {};
|
const normalizedRow = {};
|
||||||
for (let [key, value] of Object.entries(row)) {
|
for (let [key, value] of Object.entries(row)) {
|
||||||
|
@ -74,5 +99,6 @@ module.exports = {
|
||||||
getEmotion,
|
getEmotion,
|
||||||
getGenderPresentation,
|
getGenderPresentation,
|
||||||
getPoseFromPetState,
|
getPoseFromPetState,
|
||||||
|
getPoseFromPetData,
|
||||||
normalizeRow,
|
normalizeRow,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue