From 01c6cbcfdb2dc4495b3fa37d925a7a1363460049 Mon Sep 17 00:00:00 2001 From: Matt Dunn-Rankin Date: Sun, 3 May 2020 12:58:35 -0700 Subject: [PATCH] reverse bit ordering in getValidPetPoses --- src/server/getValidPetPoses.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/server/getValidPetPoses.js b/src/server/getValidPetPoses.js index 79ab539..e8ea0ca 100644 --- a/src/server/getValidPetPoses.js +++ b/src/server/getValidPetPoses.js @@ -37,18 +37,21 @@ export default async function getValidPetPoses() { for (let colorId = 1; colorId <= numColors; colorId++) { const colorIndex = colorId - 1; + // We fill in the high bits first. If we add more things later, write + // them first, so that they fill in the currently-empty high bits and + // everything else stays in the same position as before! let byte = 0; - byte += hasPose(speciesId, colorId, "HAPPY", "MASCULINE") ? 1 : 0; - byte <<= 1; - byte += hasPose(speciesId, colorId, "SAD", "MASCULINE") ? 1 : 0; - byte <<= 1; - byte += hasPose(speciesId, colorId, "SICK", "MASCULINE") ? 1 : 0; - byte <<= 1; - byte += hasPose(speciesId, colorId, "HAPPY", "FEMININE") ? 1 : 0; + byte += hasPose(speciesId, colorId, "SICK", "FEMININE") ? 1 : 0; byte <<= 1; byte += hasPose(speciesId, colorId, "SAD", "FEMININE") ? 1 : 0; byte <<= 1; - byte += hasPose(speciesId, colorId, "SICK", "FEMININE") ? 1 : 0; + byte += hasPose(speciesId, colorId, "HAPPY", "FEMININE") ? 1 : 0; + byte <<= 1; + byte += hasPose(speciesId, colorId, "SICK", "MASCULINE") ? 1 : 0; + byte <<= 1; + byte += hasPose(speciesId, colorId, "SAD", "MASCULINE") ? 1 : 0; + byte <<= 1; + byte += hasPose(speciesId, colorId, "HAPPY", "MASCULINE") ? 1 : 0; buffer.writeUInt8(byte, speciesIndex * numColors + colorIndex); }