Skip to content

Commit

Permalink
fix: game ended still ready
Browse files Browse the repository at this point in the history
  • Loading branch information
npaton committed Mar 31, 2024
1 parent cbccdb7 commit 41df213
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .changeset/game-ended-ready.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@empirica/core": patch
---

Ensure game and players are ready in exit steps.

The presence of the game and players were not checked in the exit steps, as they
are during the game. This could lead to the game or players not being available
in the exit steps callback (to select the steps) or the exit steps themselves.
30 changes: 30 additions & 0 deletions lib/@empirica/core/src/player/classic/react/EmpiricaContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ function Exit({
exitSteps: React.ElementType[] | StepsFunc;
finished: React.ElementType;
}) {
const gameReady = useGameReady();

if (!gameReady) {
return <Loading />;
}

return (
<Steps progressKey="exitStep" doneKey="exitStepDone" steps={exitSteps}>
<Finished />
Expand Down Expand Up @@ -246,3 +252,27 @@ function useAllReady() {

return true;
}

function useGameReady() {
const player = usePlayer();
const players = usePlayers();
const game = useGame();

if (!player || !players || !game || !player.game) {
return false;
}

const playerCount = game.get("actualPlayerCount") as number | undefined;

if (playerCount !== undefined && players.length < playerCount) {
return false;
}

for (const p of players) {
if (!p.game) {
return false;
}
}

return true;
}
5 changes: 3 additions & 2 deletions lib/@empirica/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
"outDir": "./dist" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
Expand Down Expand Up @@ -70,5 +70,6 @@
"skipLibCheck": true /* Skip type checking of declaration files. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
},
"exclude": ["./pkg/**/*", "./*.config.ts"]
"include": ["./src/**/*"],
"exclude": ["./dist/**/*"]
}

0 comments on commit 41df213

Please sign in to comment.