From 6757775fec8fd85c3a6513984f7839368e83db66 Mon Sep 17 00:00:00 2001 From: Matt Dunn-Rankin Date: Sun, 3 May 2020 13:02:28 -0700 Subject: [PATCH] change validPetPoses bit order, add dims to blob --- dev-todos.txt | 1 - src/app/SpeciesColorPicker.js | 10 +++++----- .../getValidPetPoses.test.js.snap | Bin 6284 -> 6284 bytes src/server/getValidPetPoses.js | 6 ++++-- 4 files changed, 9 insertions(+), 8 deletions(-) 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 4028d806617b5c4504c6f5b717ada672278d306f..351b19a755383be6f9191ab7c40027d489d08b64 100644 GIT binary patch literal 6284 zcmZ{oOK%)S6oor@VQeD}L5gJ4fjbH-Ffg)MI8Ng!u|+I`kk}w3JBss=LTuT?toyB7Q^VQvI{@eS@o4YsHtNA}C-_GBxRyTLg7K_){*WbT> zw|Mp9r(b`0zQ2F<-_7;y>h6z=*H^3GFW zzFle1{nhpSa{l7)SFf&a=O-6`&d=u;`%g}98cOL(qpK)#Rn*j*fC8#{6cyeC*izyd zxdS3DFv%n!>}Kbt3{@S+z?XnXQ2BQ6v~;i)o0m}amNT$pnffiuNux!CR+8p}rIpa) zy4O#N_xhF7rtAre4HiAemfsd6sq=R4WQw`!NAQ%8$Yh;F={Rlth|xG*i~3X;oS{zR2Q*Oz3te zH^cyF303pyL5X-Mm`6aXcmf%9&B4}Y0!AscDUP&V>YK#?iCn(D8Bx&$b0(S<0mbM# z8?3{o&DY+xjB7104@Gr84Z8L2#e_5lMrWupyNhnv&rsTO$@D{kb6=?tQ-tWfXziy; zw82k3Kb+xYCP8%cdvwc5mwH_TW9J{tB!)rB?^s}zPdyR)mxJ{1Cj@G zdPb9(v7d$j0|YLroZ?NVT%#z+amd&G=%Yg-F%C-o`7ql(>pf&_stJhcGKZQypB76B zlIQdD>_S1!+z?y?G=9S}({=I_fS*UyV3I&UX?LI2DEnCh&1+=1pL8X2hA67YHX?;> zqqW88r)P$k3K0#}S`mOZN|$Gu_JqQ_&Q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aSDguDnUgKGcW1 zCP~iw^Y`gGZ$crkQPgI?XyS+_l2Lpfn`Q=JxTQm&3@<(|DgD%m=^%@TX&eJp-Cr-Z^%WbMnTLWWiQ+4 z>`Y^#`s54~4i8XPNCH2|haJb6FH&oN%;$qwL6`(jqbvDwcj_xn7s+~XL=r|1XDWQm zhL5mqRzAcxY1IUk$)8X&ANU?xg8F@!4_5v{pANn9!D2@>_5BQJ3O0aXErD#qp!q%^ zLvNP2wC+v2}d`M3z*981HXU^d?{?YC=H;~ zvtRiXBJT>>OvCaWT<4hN@iLz#OW`Sw0biYn@vIGJo&@cnnor_$lh5$$BuRfR@Z~|$ zePtRN1S(6Bts-dBVHpfrf?yI}VSJl+r#SBwpdJq`f#~Y>^h1ch3Sye@E#G*B25+FH z>YbN^-F6kw8IKcky*ojhfL|dhHW`*1R9HK#_+XZjY4>@t->M3qYA0D-+Id9PSQ__( zG5E+_;}elTbnSqvtq!A(W>f*buy(I9K+90yKwm6;WXx8Rg0gFJ1TNbNwkpg0LTaG( zcl_-oahy9e{Hah$)V~-IB-#I}&coDYQ?{pk1J%yfIK(Dd@#6{dcw-Vq1*m3-V}R4l z=Z!~a11B~b34B-?#`-~|E)STPx@V?qCsEmLR{@<}5~xC?qi_Leq3dm$EAxaZd}OG;eu#2$+X5CAnu)EY-gy03Ha~Ep)2VaA2Ies6e_F@I zzi{IjKIFVRfu!T?8HCR#6QY1k6bI^4i?AJX1}`%)2^6k2|0fU&UT&~kVtj(;^G_PA zNukClT^9Usgh1=r<8uTV&+JDydotB@e3{volZy~<8ajMyIHYnPeb7c!Fe#OueHv_pF1=Qr&*+5 OF#Uo$ZckoaJ^C4trTqo~ 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); } }