diff --git a/dev-todos.txt b/dev-todos.txt index bb6cac1..c3084bd 100644 --- a/dev-todos.txt +++ b/dev-todos.txt @@ -12,4 +12,3 @@ Tech/detail improvements: * Use react-virtualized instead of our own scroller, but we need total count known, and we need another solution for the CSS transitions in the outfit case * Restore good download behavior: use crossOrigin for everything, and remove cache-buster in the URL we use for canvas * Undo the local linking we did for @chakra-ui/core, react, and react-dom on Matchu's machine 😅 - * validPetPoses should declare its own dimensions, so that misaligned caches won't misalign the data diff --git a/src/app/SpeciesColorPicker.js b/src/app/SpeciesColorPicker.js index 8844533..6e4c21e 100644 --- a/src/app/SpeciesColorPicker.js +++ b/src/app/SpeciesColorPicker.js @@ -65,7 +65,7 @@ function SpeciesColorPicker({ outfitState, dispatchToOutfit }) { const onChangeColor = (e) => { const speciesId = outfitState.speciesId; const colorId = e.target.value; - if (pairIsValid(valids, meta, speciesId, colorId)) { + if (pairIsValid(valids, speciesId, colorId)) { dispatchToOutfit({ type: "changeColor", colorId: e.target.value }); } else { const species = allSpecies.find((s) => s.id === speciesId); @@ -82,7 +82,7 @@ function SpeciesColorPicker({ outfitState, dispatchToOutfit }) { const onChangeSpecies = (e) => { const colorId = outfitState.colorId; const speciesId = e.target.value; - if (pairIsValid(valids, meta, speciesId, colorId)) { + if (pairIsValid(valids, speciesId, colorId)) { dispatchToOutfit({ type: "changeSpecies", speciesId: e.target.value }); } else { const species = allSpecies.find((s) => s.id === speciesId); @@ -133,12 +133,12 @@ function SpeciesColorPicker({ outfitState, dispatchToOutfit }) { ); } -function pairIsValid(valids, meta, speciesId, colorId) { +function pairIsValid(valids, speciesId, colorId) { // Reading a bit table, owo! const speciesIndex = speciesId - 1; const colorIndex = colorId - 1; - const numColors = meta.allColors.length; - const pairByteIndex = speciesIndex * numColors + colorIndex; + const numColors = valids.getUint8(1); + const pairByteIndex = speciesIndex * numColors + colorIndex + 2; const pairByte = valids.getUint8(pairByteIndex); return pairByte !== 0; } diff --git a/src/server/__snapshots__/getValidPetPoses.test.js.snap b/src/server/__snapshots__/getValidPetPoses.test.js.snap index 4028d80..351b19a 100644 Binary files a/src/server/__snapshots__/getValidPetPoses.test.js.snap and b/src/server/__snapshots__/getValidPetPoses.test.js.snap differ diff --git a/src/server/getValidPetPoses.js b/src/server/getValidPetPoses.js index e8ea0ca..cda8586 100644 --- a/src/server/getValidPetPoses.js +++ b/src/server/getValidPetPoses.js @@ -30,7 +30,9 @@ export default async function getValidPetPoses() { } const numPairs = numSpecies * numColors; - const buffer = Buffer.alloc(numPairs); + const buffer = Buffer.alloc(numPairs + 2); + buffer.writeUInt8(numSpecies, 0); + buffer.writeUInt8(numColors, 1); for (let speciesId = 1; speciesId <= numSpecies; speciesId++) { const speciesIndex = speciesId - 1; @@ -53,7 +55,7 @@ export default async function getValidPetPoses() { byte <<= 1; byte += hasPose(speciesId, colorId, "HAPPY", "MASCULINE") ? 1 : 0; - buffer.writeUInt8(byte, speciesIndex * numColors + colorIndex); + buffer.writeUInt8(byte, speciesIndex * numColors + colorIndex + 2); } }