Skip to content

Commit

Permalink
feat(results): Create test results summary page
Browse files Browse the repository at this point in the history
  • Loading branch information
CaedenPH committed Jul 15, 2024
1 parent 6902625 commit 59b91e1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 31 deletions.
6 changes: 2 additions & 4 deletions src/routes/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ export class CogSpeedGame {
*/
public async start(time: number | null = null) {
this.ui?.setupGame(this);

this.startTime = time === null ? performance.now() : time;
this.maxTestTimeout = setTimeout(this.stop.bind(this), this.config.timeouts.max_test_duration);
this.nextRound();
Expand All @@ -548,9 +548,7 @@ export class CogSpeedGame {
const status = info.status;
const message = info.message;

for (var i = this.app.stage.children.length - 1; i >= 0; i--) {
this.app.stage.removeChild(this.app.stage.children[i]);
}
this.ui.removeAllStageChildren();

const round = (num: number, sf: number = 3) => {
return Math.round((num * 10 ** sf) / 10 ** sf);
Expand Down
82 changes: 55 additions & 27 deletions src/routes/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,39 +214,66 @@ export class ProcessResultsPage {
return container;
}

public async show(data: { [key: string]: any }, config: Config) {
const loadingContainer = this.loadingScreen();

const [geolocation, normalizedLocation] = await this.getCurrentPosition();
data.location = {
geolocation,
normalizedLocation,
};

const textObject = new Text(`Test summary
public async showSummaryPage(data: { [key: string]: any }, config: Config) {
const textSummary = new Text(`Test summary
Test version: ${config.version}
Account ID: ...
Test ID: ${data._id}
Date/time: ${data._date}
Location: ${data.location.normalizedLocation}
Status: ${data.status}
Message: ${data.statusCode}
Date/time: ${data._date}
Location: ${normalizedLocation}
Test duration: ${data.testDuration}
No rounds: ${data.numberOfRounds}
No blocks: ${data.blocking.blockCount}
Block range: ${data.blocking.blockRange}
Final block diff: ${data.blocking.finalBlockDiff}
`, {
Blocking duration: ${data.blockingRoundDuration}`, {
fontFamily: "Trebuchet",
fontSize: 18,
fill: 0xffffff,
align: "center",
wordWrap: true,
wordWrapWidth: this.app.screen.width * 0.8
});
textObject.position.set(this.app.screen.width * 0.5,
this.app.screen.height * 0.2);
textSummary.position.set(this.app.screen.width * 0.5,
this.app.screen.height * 0.15);

textObject.anchor.set(0.5);

textSummary.anchor.set(0.5);
this.app.stage.addChild(textSummary);

const backButtonContainer = this.ui.createButton(
"Go back",
this.app.screen.width * 0.5,
this.app.screen.height * 0.85,
this.app.screen.width * 0.6,
this.app.screen.height * 0.2
);
backButtonContainer.on("pointerdown", () => {
this.ui.removeAllStageChildren();
this.show(data, config, {shouldLoad: false});
});
this.app.stage.addChild(backButtonContainer);
}

public async show(data: { [key: string]: any }, config: Config, args: { shouldLoad: boolean} = {shouldLoad: true}) {
let loadingContainer;
if (args.shouldLoad) {
loadingContainer = this.loadingScreen();
}


const [geolocation, normalizedLocation] = await this.getCurrentPosition();
data.location = {
geolocation,
normalizedLocation,
};

const summaryPageButtonContainer = this.ui.createButton(
"View test summary",
this.app.screen.width * 0.5,
this.app.screen.height * 0.3,
this.app.screen.width * 0.6,
this.app.screen.height * 0.2
);
summaryPageButtonContainer.on("pointerdown", () => {
this.ui.removeAllStageChildren();
this.showSummaryPage(data, config);
});

const responseData = JSON.parse(JSON.stringify(data));
delete responseData["answerLogs"];
Expand Down Expand Up @@ -289,13 +316,14 @@ export class ProcessResultsPage {
startUp(config, false);
});

await this.ui.emulateLoadingTime();

loadingContainer.destroy();
if (args.shouldLoad && loadingContainer) {
await this.ui.emulateLoadingTime();
loadingContainer.destroy();
}

this.app.stage.addChild(summaryPageButtonContainer);
this.app.stage.addChild(viewTestLogsButtonContainer);
this.app.stage.addChild(restartTestButtonContainer);
this.app.stage.addChild(homeButton);
this.app.stage.addChild(textObject);
}
}
6 changes: 6 additions & 0 deletions src/ui/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,12 @@ export class CogSpeedGraphicsHandler {
this.app.stage.addChild(background);
}

public removeAllStageChildren() {
for (var i = this.app.stage.children.length - 1; i >= 0; i--) {
this.app.stage.removeChild(this.app.stage.children[i]);
}
}

public createDisplayGear(posX: number, posY: number, gearLocation: string): Container {
const [container] = this.createGear(posX, posY, gearLocation);
return container;
Expand Down

0 comments on commit 59b91e1

Please sign in to comment.