Skip to content

Commit

Permalink
Small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eltoder committed Feb 4, 2025
1 parent f54093a commit cf6ecda
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 29 deletions.
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"tabWidth": 2,
"useTabs": false,
"trailingComma": "es5",
"proseWrap": "always"
}
2 changes: 1 addition & 1 deletion database.rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"events": {
"$eventId": {
".write": "!data.exists() && newData.exists() && auth != null && root.hasChild('games/' + $gameId + '/users/' + auth.uid) && root.child('games/' + $gameId + '/status').val() == 'ingame'",
".validate": "newData.hasChildren(['user', 'time', 'c1', 'c2', 'c3']) && (newData.hasChild('c4') == (root.child('games/' + $gameId + '/mode').val().matches(/^ultraset|ultrachain|ultra9|ghostset$/))) && (newData.hasChildren(['c5', 'c6']) == (root.child('games/' + $gameId + '/mode').val() == 'ghostset'))",
".validate": "newData.hasChildren(['user', 'time', 'c1', 'c2', 'c3']) && (newData.hasChild('c4') == root.child('games/' + $gameId + '/mode').val().matches(/^ultraset|ultrachain|ultra9|ghostset$/)) && (newData.hasChildren(['c5', 'c6']) == (root.child('games/' + $gameId + '/mode').val() == 'ghostset'))",
"user": {
".validate": "newData.isString() && newData.val() == auth.uid"
},
Expand Down
19 changes: 5 additions & 14 deletions functions/src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,9 @@ interface GameEvent {
c6?: string;
}

export type GameMode =
| "normal"
| "junior"
| "setchain"
| "ultraset"
| "ultrachain"
| "ultra9"
| "megaset"
| "ghostset"
| "memory";
export type GameMode = keyof typeof modes;

type SetType = "Set" | "UltraSet" | "GhostSet";
type SetType = keyof typeof setTypes;

interface GameModeInfo {
setType: SetType;
Expand Down Expand Up @@ -241,7 +232,7 @@ const setTypes = {
},
};

const modes: Record<string, GameModeInfo> = {
export const modes = {
normal: {
setType: "Set",
traits: 4,
Expand Down Expand Up @@ -287,7 +278,7 @@ const modes: Record<string, GameModeInfo> = {
traits: 4,
chain: 0,
},
};
} satisfies Record<string, GameModeInfo>;

/**
* Compute remaining cards (arbitrary order) left in the deck after some
Expand All @@ -298,7 +289,7 @@ export function replayEvents(
gameMode: GameMode
) {
if (!modes.hasOwnProperty(gameMode)) {
throw new Error(`invalid gameMode: ${gameMode}`);
throw new Error(`Invalid gameMode: ${gameMode}`);
}
const events: GameEvent[] = [];
gameData.child("events").forEach((e) => {
Expand Down
8 changes: 7 additions & 1 deletion functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const stripe = !functions.config().stripe
apiVersion: "2020-08-27",
});

import { generateSeed, replayEvents, findSet, GameMode } from "./game";
import { generateSeed, replayEvents, findSet, GameMode, modes } from "./game";

const MAX_GAME_ID_LENGTH = 64;
const MAX_UNFINISHED_GAMES_PER_HOUR = 4;
Expand Down Expand Up @@ -237,6 +237,12 @@ export const createGame = functions.https.onCall(async (data, context) => {
'argument `access` given value "public" or "private".'
);
}
if (!modes.hasOwnProperty(mode)) {
throw new functions.https.HttpsError(
"invalid-argument",
`Invalid gameMode: ${mode}`
);
}
if (enableHint && access !== "private") {
throw new functions.https.HttpsError(
"invalid-argument",
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"devDependencies": {
"@google-cloud/pubsub": "^2.19.0",
"cross-env": "^7.0.3",
"prettier": "2.6.0"
"prettier": "^3.4.2"
},
"eslintConfig": {
"extends": "react-app"
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<title>Set with Friends</title>
Expand Down
4 changes: 2 additions & 2 deletions src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ export const modes = {
setchain: {
name: "Set-Chain",
color: "teal",
description: "In every Set, you have to use 1 card from the previous Set.",
description: "In every Set you have to use 1 card from the previous Set.",
setType: "Set",
traits: 4,
chain: 1,
Expand All @@ -414,7 +414,7 @@ export const modes = {
name: "UltraSet-Chain",
color: "orange",
description:
"In every UltraSet, you have to use one pair from the previous Set.",
"In every UltraSet you have to use 2 cards from the previous Set.",
setType: "UltraSet",
traits: 4,
chain: 2,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/GamePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ function GamePage({ match }) {
game.status === "done"
? game.endedAt
: !answer && history.length > 0
? history[history.length - 1].time
: 0
? history[history.length - 1].time
: 0
}
/>
</Box>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ProfilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const datasetVariants = {
};

const gameModes = {
...modes,
all: { name: "All Modes" },
...modes,
};

const useStyles = makeStyles((theme) => ({
Expand Down

0 comments on commit cf6ecda

Please sign in to comment.