Skip to content

Commit

Permalink
feat: assign random dice side when null
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschi committed Sep 26, 2024
1 parent f32ef4c commit 21e1f74
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions services/state/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,19 @@ export function getAllLabelsForSides({ A, B, C }) {
return { focusGroup, topic, medium };
}

function assignRandomSide(cube) {
const random = Math.floor(Math.random() * 6) + 1;
setDiceSide(`${cube}${random}`);
}

/**
* Returns all labels as array for the current dice sides
* @returns {{focusGroup: string[], topic: string[], medium: string[]}}
*/
export function getAllLabelsForCurrentSides() {
if (dices.A.side === null || dices.B.side === null || dices.C.side === null) {
return {
focusGroup: dices.A.side,
topic: dices.B.side,
medium: dices.C.side,
};
}
dices.A.side === null && assignRandomSide("A");
dices.B.side === null && assignRandomSide("B");
dices.C.side === null && assignRandomSide("C");

const A = `A${dices.A.side}`;
const B = `B${dices.B.side}`;
Expand Down

0 comments on commit 21e1f74

Please sign in to comment.