Skip to content

Commit

Permalink
fix: make player reset in admin work (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
npaton authored Mar 31, 2024
1 parent b84c396 commit db69a0f
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/player-reset-admin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@empirica/core": patch
---

Make player reset in admin UI work again.
22 changes: 22 additions & 0 deletions lib/@empirica/core/src/admin/classic/classic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,28 @@ export function Classic({
game.start();
});

// If a player gets their ended state reset, try to reassign them.
_.on(
"player",
"ended",
async (
ctx,
{ player, ended }: { player: Player; ended: string | undefined }
) => {
const participantID = player.get("participantID");
if (
player.currentGame ||
ended ||
!participantID ||
!online.has(participantID as string)
) {
return;
}

await await assignplayer(ctx, player);
}
);

type BeforeGameStart = { game: Game; start: boolean };
_.unique.before(
"game",
Expand Down
34 changes: 28 additions & 6 deletions lib/admin-ui/src/components/players/PlayerLine.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,33 @@
export let online = false;
function clear() {
$currentAdmin.setAttribute({
key: "ended",
val: JSON.stringify(null),
nodeID: player.id,
});
$currentAdmin.setAttributes([
{
key: "ended",
val: JSON.stringify(null),
nodeID: player.id,
},
{
key: "gameID",
val: JSON.stringify(null),
nodeID: player.id,
},
{
key: "treatment",
val: JSON.stringify(null),
nodeID: player.id,
},
{
key: "treatmentName",
val: JSON.stringify(null),
nodeID: player.id,
},
{
key: "introDone",
val: JSON.stringify(null),
nodeID: player.id,
},
]);
}
</script>

Expand Down Expand Up @@ -49,7 +71,7 @@
/></svg
>
</div>
Clear
Clear player
</Button>
{/if}
</div>
Expand Down
7 changes: 7 additions & 0 deletions tests/stress/experiment/.empirica/treatments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,10 @@ treatments:
roundCount: 10
stageCount: 3
newKeyRate: 0.5
- name: solo
desc: "1 player"
factors:
playerCount: 1
roundCount: 1
stageCount: 1
newKeyRate: 0.5
20 changes: 19 additions & 1 deletion tests/stress/experiment/client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ export default function App() {
const { protocol, host } = window.location;
const url = `${protocol}//${host}/query`;

// const introSteps = [DemoIntro];
const introSteps = [];

return (
<EmpiricaParticipant url={url} ns={playerKey} modeFunc={EmpiricaClassic}>
<div className="h-screen relative">
<EmpiricaMenu position="bottom-left" />
<div className="h-full overflow-auto">
<ErrorBoundarySimple>
<EmpiricaContext disableConsent finished={Finished}>
<EmpiricaContext
disableConsent
finished={Finished}
introSteps={introSteps}
>
<Game />
</EmpiricaContext>
</ErrorBoundarySimple>
Expand All @@ -27,6 +34,17 @@ export default function App() {
);
}

export function DemoIntro({ next }) {
return (
<div>
<h2 data-test="intro-step">Intro</h2>

<button onClick={next}>
<p>Next</p>
</button>
</div>
);
}
export function Finished() {
return (
<div>
Expand Down

0 comments on commit db69a0f

Please sign in to comment.