Skip to content

Commit

Permalink
Added hints for setchain and ultraset
Browse files Browse the repository at this point in the history
  • Loading branch information
mathmil authored and eltoder committed Nov 17, 2024
1 parent 88a8582 commit 838bf86
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
3 changes: 1 addition & 2 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ export const finishGame = functions.https.onCall(async (data, context) => {
if (
snapshot.child("enableHint").val() &&
snapshot.child("users").numChildren() === 1 &&
snapshot.child("access").val() === "private" &&
gameMode === "normal"
snapshot.child("access").val() === "private"
) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/GameSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function GameSettings({ game, gameId, userId }) {
</Tooltip>
))}
</RadioGroup>
{gameMode === "normal" && (
{
<Tooltip arrow placement="left" title={hintTip}>
<FormControlLabel
control={<Switch checked={hasHint(game)} onChange={toggleHint} />}
Expand All @@ -59,7 +59,7 @@ function GameSettings({ game, gameId, userId }) {
}
/>
</Tooltip>
)}
}
</div>
);
}
Expand Down
13 changes: 9 additions & 4 deletions src/pages/GamePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ function GamePage({ match }) {

const gameMode = game.mode || "normal";
const spectating = !game.users || !(user.id in game.users);
const maxNumHints = gameMode === "ultraset" ? 4 : 3;

const { current, scores, history, boardSize } = computeState(
gameData,
Expand Down Expand Up @@ -192,7 +193,7 @@ function GamePage({ match }) {
lastSet = [c1, c2, c3];
}
let answer = findSet(current.slice(0, boardSize), gameMode, lastSet);
if (gameMode === "normal" && hasHint(game) && answer) {
if (hasHint(game) && answer) {
answer = answer.slice(0, numHints);
} else {
answer = null;
Expand Down Expand Up @@ -316,7 +317,7 @@ function GamePage({ match }) {

function handleAddHint() {
setNumHints((numHints) => {
if (numHints === 3) {
if (numHints === maxNumHints) {
return numHints;
}
return numHints + 1;
Expand Down Expand Up @@ -441,13 +442,17 @@ function GamePage({ match }) {
leaderboard={leaderboard}
/>
<Box mt={1}>
{gameMode === "normal" && hasHint(game) && (
{hasHint(game) && (
<Button
size="large"
variant="outlined"
color="primary"
fullWidth
disabled={numHints === 3 || !answer || game.status === "done"}
disabled={
numHints === maxNumHints ||
!answer ||
game.status === "done"
}
onClick={handleAddHint}
>
Add hint: {numHints}
Expand Down
3 changes: 1 addition & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ export function hasHint(game) {
game.enableHint &&
game.users &&
Object.keys(game.users).length === 1 &&
game.access === "private" &&
(game.mode || "normal") === "normal"
game.access === "private"
);
}

0 comments on commit 838bf86

Please sign in to comment.