Skip to content

Commit

Permalink
Fix bug when fetching + decompressing brotli'd word data
Browse files Browse the repository at this point in the history
  • Loading branch information
Gyanreyer committed Apr 12, 2023
1 parent f5cf2d0 commit b5eb922
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/js/game.mjs
Expand Up @@ -46,6 +46,24 @@ const openGameDBPromise = import(
})
);

let wordData;
async function loadWordData() {
if (!wordData) {
const importBrotli = import(
"https://cdn.jsdelivr.net/npm/brotli-compress@1.3.3/js.mjs"
);
wordData = await fetch("/words/en.json.br")
.then((res) => res.arrayBuffer())
.then(async (compressedData) => {
const brotli = await importBrotli;
const decompressedData = brotli.decompress(compressedData);
const text = new TextDecoder().decode(decompressedData);
return JSON.parse(text);
});
}
return wordData;
}

Alpine.store("game", {
timestamp: 0,
centerLetter: "",
Expand Down Expand Up @@ -288,18 +306,7 @@ Alpine.store("game", {
);
},
async getNewLetterSet(dateTimestamp) {
const importBrotli = import(
"https://cdn.jsdelivr.net/npm/brotli-compress@1.3.3/js.mjs"
);
const [allWords, letterSets, letterSetVariants] = fetch("/words/en.json.br")
.then((res) => res.arrayBuffer())
.then(async (compressedData) => {
const brotli = await importBrotli;
const decompressedData = brotli.decompress(compressedData);
const text = new TextDecoder().decode(decompressedData);
return JSON.parse(text);
});

const [allWords, letterSets, letterSetVariants] = await loadWordData();
let getRandomNumber = seededRandom(dateTimestamp);

const [[letterSetIndex, centerLetterIndex], validWordIndices] =
Expand Down

0 comments on commit b5eb922

Please sign in to comment.