change validPetPoses bit order, add dims to blob

This commit is contained in:
Matt Dunn-Rankin 2020-05-03 13:02:28 -07:00
parent 01c6cbcfdb
commit 6757775fec
4 changed files with 9 additions and 8 deletions

View file

@ -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 * 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 * 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 😅 * 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

View file

@ -65,7 +65,7 @@ function SpeciesColorPicker({ outfitState, dispatchToOutfit }) {
const onChangeColor = (e) => { const onChangeColor = (e) => {
const speciesId = outfitState.speciesId; const speciesId = outfitState.speciesId;
const colorId = e.target.value; const colorId = e.target.value;
if (pairIsValid(valids, meta, speciesId, colorId)) { if (pairIsValid(valids, speciesId, colorId)) {
dispatchToOutfit({ type: "changeColor", colorId: e.target.value }); dispatchToOutfit({ type: "changeColor", colorId: e.target.value });
} else { } else {
const species = allSpecies.find((s) => s.id === speciesId); const species = allSpecies.find((s) => s.id === speciesId);
@ -82,7 +82,7 @@ function SpeciesColorPicker({ outfitState, dispatchToOutfit }) {
const onChangeSpecies = (e) => { const onChangeSpecies = (e) => {
const colorId = outfitState.colorId; const colorId = outfitState.colorId;
const speciesId = e.target.value; const speciesId = e.target.value;
if (pairIsValid(valids, meta, speciesId, colorId)) { if (pairIsValid(valids, speciesId, colorId)) {
dispatchToOutfit({ type: "changeSpecies", speciesId: e.target.value }); dispatchToOutfit({ type: "changeSpecies", speciesId: e.target.value });
} else { } else {
const species = allSpecies.find((s) => s.id === speciesId); 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! // Reading a bit table, owo!
const speciesIndex = speciesId - 1; const speciesIndex = speciesId - 1;
const colorIndex = colorId - 1; const colorIndex = colorId - 1;
const numColors = meta.allColors.length; const numColors = valids.getUint8(1);
const pairByteIndex = speciesIndex * numColors + colorIndex; const pairByteIndex = speciesIndex * numColors + colorIndex + 2;
const pairByte = valids.getUint8(pairByteIndex); const pairByte = valids.getUint8(pairByteIndex);
return pairByte !== 0; return pairByte !== 0;
} }

View file

@ -30,7 +30,9 @@ export default async function getValidPetPoses() {
} }
const numPairs = numSpecies * numColors; 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++) { for (let speciesId = 1; speciesId <= numSpecies; speciesId++) {
const speciesIndex = speciesId - 1; const speciesIndex = speciesId - 1;
@ -53,7 +55,7 @@ export default async function getValidPetPoses() {
byte <<= 1; byte <<= 1;
byte += hasPose(speciesId, colorId, "HAPPY", "MASCULINE") ? 1 : 0; byte += hasPose(speciesId, colorId, "HAPPY", "MASCULINE") ? 1 : 0;
buffer.writeUInt8(byte, speciesIndex * numColors + colorIndex); buffer.writeUInt8(byte, speciesIndex * numColors + colorIndex + 2);
} }
} }