Skip to content

Commit

Permalink
Images now generate in a random order
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanDevelops committed Dec 3, 2024
1 parent ef9e26f commit d485391
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 11 additions & 2 deletions app/(gameplay)/game/_context/GameContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,17 @@ export const GameProvider = ({

useEffect(() => {
if(currentLevelId && imageSrcs && imageIds) {
setCurrentImageSrcUrls(imageSrcs.filter((src): src is string => src !== null));
setCurrentImageIds(imageIds);
// Pair the image src and id together
const pairedArray = imageSrcs
.map((src, index) => ( { src, id: imageIds[index] }))
.filter(pair => pair.src !== null);

// shuffle the order
const shuffledArray = pairedArray.sort(() => Math.random() - 0.5);

// set the values
setCurrentImageSrcUrls(shuffledArray.map(pair => pair.src).filter(src => src !== null) as string[]);
setCurrentImageIds(shuffledArray.map(pair => pair.id));
}
}, [currentLevelId, imageSrcs, imageIds]);

Expand Down
2 changes: 0 additions & 2 deletions convex/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,9 @@ export const checkGuess = mutation({
let correct = false;

if(args.selectedImageId === AIGeneratedImageId._id) {
// TODO: Implement correct guess here
score = 50;
correct = true;
} else {
// TODO: Implement incorrect guess here
score = 0;
correct = false;
}
Expand Down

0 comments on commit d485391

Please sign in to comment.