Skip to content

Commit

Permalink
fix(display-correct-answer): Don't break if clicked during ripple ani…
Browse files Browse the repository at this point in the history
…mation
  • Loading branch information
CaedenPH committed Apr 1, 2024
1 parent 77fb07a commit db678f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 4 additions & 8 deletions src/routes/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,9 @@ export class CogSpeedGame {
this.isInPause = this.answer;

const answerSprite = this.ui.inputButtons[6 - this.answer];
for (let i = 0; i < 3; i ++){
this.ui.rippleAnimation(answerSprite);
await new Promise(resolve => setTimeout(resolve, 500));
}


// TODO: Exit if incorrect button was pressed immediately
if (await this.ui.waitForKeyPress(answerSprite, this.config.practice_mode.no_response_duration)) {
if (await this.ui.waitForKeyPressCorrectAnswer(answerSprite, this.config.practice_mode.no_response_duration)) {
this.isInPause = null;
return
}
Expand Down Expand Up @@ -408,7 +404,7 @@ export class CogSpeedGame {
* @param {number} timeClicked The time (performance.now) the button was clicked
*/
public buttonClicked(location: number | null = null, timeClicked: number | null = null): boolean {
if (this.ui && this.isInPause !== null && this.isInPause != location) {
if (this.ui && this.isInPause !== null && this.isInPause !== location) {
// It should only respond to one in this mode
this.ui.rippleAnimation(this.ui.inputButtons[6 - this.answer]);
return false;
Expand All @@ -429,7 +425,7 @@ export class CogSpeedGame {
previousAnswer &&
previousAnswer.status === "no response" &&
this.config.machine_paced.minimum_response_time > timeTaken &&
location != null
location !== null
) {
if (location === previousAnswer.answerLocation) {
// The answer is correct for the previous answer
Expand Down
8 changes: 6 additions & 2 deletions src/ui/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ export class CogSpeedGraphicsHandler {
/**
* Wait for a click on a sprite
*/
public async waitForKeyPress(sprite: Sprite, timeout: number) {
public async waitForKeyPressCorrectAnswer(sprite: Sprite, timeout: number) {
const container = new Container();
const startTime = performance.now();

Expand All @@ -430,10 +430,14 @@ export class CogSpeedGraphicsHandler {
});

// Block until the start page is removed
let i = 0;
while (container.destroyed === false) {
// Ripple 3 times every 300 ms
if (i % 6 == 0 && i < 20) this.rippleAnimation(sprite);
// Timed out
if (performance.now() > startTime + timeout) return null;
await new Promise((resolve) => setTimeout(resolve, 100));
await new Promise((resolve) => setTimeout(resolve, 50));
i ++;
}
return true;
}
Expand Down

0 comments on commit db678f3

Please sign in to comment.