add unknown and UC to valid pet poses

This commit is contained in:
Matt Dunn-Rankin 2020-05-23 11:48:53 -07:00
parent 4d6a6faf4c
commit 772917fde6
4 changed files with 71 additions and 16 deletions

View file

@ -1,6 +1,6 @@
import connectToDb from "./db"; import connectToDb from "./db";
import { getEmotion, getGenderPresentation } from "./util"; import { getPose } from "./util";
export default async function getValidPetPoses() { export default async function getValidPetPoses() {
const db = await connectToDb(); const db = await connectToDb();
@ -17,15 +17,14 @@ export default async function getValidPetPoses() {
const poseStrs = new Set(); const poseStrs = new Set();
for (const poseTuple of poseTuples) { for (const poseTuple of poseTuples) {
const { species_id, color_id, mood_id, female } = poseTuple; const { species_id, color_id, mood_id, female, unconverted } = poseTuple;
const emotion = getEmotion(mood_id); const pose = getPose(mood_id, female, unconverted);
const genderPresentation = getGenderPresentation(female); const poseStr = `${species_id}-${color_id}-${pose}`;
const poseStr = `${species_id}-${color_id}-${emotion}-${genderPresentation}`;
poseStrs.add(poseStr); poseStrs.add(poseStr);
} }
function hasPose(speciesId, colorId, emotion, genderPresentation) { function hasPose(speciesId, colorId, pose) {
const poseStr = `${speciesId}-${colorId}-${emotion}-${genderPresentation}`; const poseStr = `${speciesId}-${colorId}-${pose}`;
return poseStrs.has(poseStr); return poseStrs.has(poseStr);
} }
@ -43,17 +42,21 @@ export default async function getValidPetPoses() {
// them first, so that they fill in the currently-empty high bits and // them first, so that they fill in the currently-empty high bits and
// everything else stays in the same position as before! // everything else stays in the same position as before!
let byte = 0; let byte = 0;
byte += hasPose(speciesId, colorId, "SICK", "FEMININE") ? 1 : 0; byte += hasPose(speciesId, colorId, "UNKNOWN") ? 1 : 0;
byte <<= 1; byte <<= 1;
byte += hasPose(speciesId, colorId, "SAD", "FEMININE") ? 1 : 0; byte += hasPose(speciesId, colorId, "UNCONVERTED") ? 1 : 0;
byte <<= 1; byte <<= 1;
byte += hasPose(speciesId, colorId, "HAPPY", "FEMININE") ? 1 : 0; byte += hasPose(speciesId, colorId, "SICK_FEM") ? 1 : 0;
byte <<= 1; byte <<= 1;
byte += hasPose(speciesId, colorId, "SICK", "MASCULINE") ? 1 : 0; byte += hasPose(speciesId, colorId, "SAD_FEM") ? 1 : 0;
byte <<= 1; byte <<= 1;
byte += hasPose(speciesId, colorId, "SAD", "MASCULINE") ? 1 : 0; byte += hasPose(speciesId, colorId, "HAPPY_FEM") ? 1 : 0;
byte <<= 1; byte <<= 1;
byte += hasPose(speciesId, colorId, "HAPPY", "MASCULINE") ? 1 : 0; byte += hasPose(speciesId, colorId, "SICK_MASC") ? 1 : 0;
byte <<= 1;
byte += hasPose(speciesId, colorId, "SAD_MASC") ? 1 : 0;
byte <<= 1;
byte += hasPose(speciesId, colorId, "HAPPY_MASC") ? 1 : 0;
buffer.writeUInt8(byte, speciesIndex * numColors + colorIndex + 2); buffer.writeUInt8(byte, speciesIndex * numColors + colorIndex + 2);
} }
@ -76,8 +79,9 @@ async function getNumColors(db) {
async function getPoseTuples(db) { async function getPoseTuples(db) {
const [rows, _] = await db.query(` const [rows, _] = await db.query(`
SELECT DISTINCT species_id, color_id, mood_id, female FROM pet_states SELECT DISTINCT species_id, color_id, mood_id, female, unconverted
FROM pet_states
INNER JOIN pet_types ON pet_types.id = pet_states.pet_type_id INNER JOIN pet_types ON pet_types.id = pet_states.pet_type_id
WHERE mood_id IS NOT NULL AND female IS NOT NULL AND color_id >= 1`); WHERE glitched IS false AND color_id >= 1`);
return rows; return rows;
} }

View file

@ -9675,6 +9675,14 @@ Object {
"id": "18", "id": "18",
}, },
}, },
Object {
"color": Object {
"id": "108",
},
"species": Object {
"id": "18",
},
},
Object { Object {
"color": Object { "color": Object {
"id": "6", "id": "6",
@ -16531,6 +16539,14 @@ Object {
"id": "31", "id": "31",
}, },
}, },
Object {
"color": Object {
"id": "106",
},
"species": Object {
"id": "31",
},
},
Object { Object {
"color": Object { "color": Object {
"id": "6", "id": "6",
@ -17979,6 +17995,14 @@ Object {
"id": "34", "id": "34",
}, },
}, },
Object {
"color": Object {
"id": "109",
},
"species": Object {
"id": "34",
},
},
Object { Object {
"color": Object { "color": Object {
"id": "-1", "id": "-1",

View file

@ -26,4 +26,31 @@ function getGenderPresentation(modelPetWasFemale) {
} }
} }
module.exports = { capitalize, getEmotion, getGenderPresentation }; function getPose(moodId, modelPetWasFemale, isUnconverted) {
if (isUnconverted) {
return "UNCONVERTED";
} else if (moodId == null || modelPetWasFemale == null) {
return "UNKNOWN";
} else if (String(moodId) === "1" && String(modelPetWasFemale) === "0") {
return "HAPPY_MASC";
} else if (String(moodId) === "1" && String(modelPetWasFemale) === "1") {
return "HAPPY_FEM";
} else if (String(moodId) === "2" && String(modelPetWasFemale) === "0") {
return "SAD_MASC";
} else if (String(moodId) === "2" && String(modelPetWasFemale) === "1") {
return "SAD_FEM";
} else if (String(moodId) === "4" && String(modelPetWasFemale) === "0") {
return "SICK_MASC";
} else if (String(moodId) === "4" && String(modelPetWasFemale) === "1") {
return "SICK_FEM";
} else {
throw new Error(
`could not identify pose: ` +
`moodId=${moodId}, ` +
`modelPetWasFemale=${modelPetWasFemale}, ` +
`isUnconverted=${isUnconverted}`
);
}
}
module.exports = { capitalize, getEmotion, getGenderPresentation, getPose };