2022-11-28 11:04:49 +00:00
|
|
|
/**
|
|
|
|
* @file This file provides the user with their profilescreen, where they can see their own tests
|
|
|
|
* @author Arlo Filley
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* - change button name
|
|
|
|
* - provide filters for tests
|
|
|
|
* - implement a way to scroll through tests
|
|
|
|
* - create a way to have personal bests and track them
|
|
|
|
* - store tests in localstorage.
|
|
|
|
* - show user tests even if they are not logged in
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class displays all of the test data for a given user
|
|
|
|
*/
|
2022-11-17 11:48:12 +00:00
|
|
|
class ProfileScreen {
|
|
|
|
constructor() {
|
2022-11-18 14:51:05 +00:00
|
|
|
this.menu = new Menu();
|
2022-11-17 11:48:12 +00:00
|
|
|
api.getUserTests();
|
2022-11-29 12:21:38 +00:00
|
|
|
this.testButtons;
|
|
|
|
this.buttons = [
|
2022-12-01 14:41:14 +00:00
|
|
|
new Button(950, 270, 240, 120, "up"),
|
|
|
|
new Button(950, 390, 240, 120, "down"),
|
2022-11-29 12:21:38 +00:00
|
|
|
]
|
|
|
|
this.offset = 0;
|
2022-11-17 11:48:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
draw() {
|
|
|
|
textSize(100);
|
|
|
|
textAlign(CENTER, CENTER);
|
2022-12-01 14:41:14 +00:00
|
|
|
fill(user.colorScheme.text);
|
2022-11-17 12:10:54 +00:00
|
|
|
text("Profile", 0, 100, windowWidth, 120);
|
2022-11-18 11:33:25 +00:00
|
|
|
|
2022-11-18 14:51:05 +00:00
|
|
|
this.menu.draw();
|
2022-11-17 11:48:12 +00:00
|
|
|
|
|
|
|
textSize(20);
|
2022-12-01 14:41:14 +00:00
|
|
|
fill(user.colorScheme.text);
|
2022-11-17 11:48:12 +00:00
|
|
|
if (user.tests != undefined) {
|
2022-11-29 12:21:38 +00:00
|
|
|
if (this.testButtons === undefined) {
|
|
|
|
this.createTestButtons();
|
2022-11-17 11:48:12 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-29 12:21:38 +00:00
|
|
|
|
2022-12-01 14:41:14 +00:00
|
|
|
if (this.testButtons !== undefined && this.testButtons.length > 1) {
|
2022-11-29 12:21:38 +00:00
|
|
|
for (let i = 0; i < this.testButtons.length; i++) {
|
|
|
|
this.testButtons[i][0].draw()
|
|
|
|
this.testButtons[i][1].draw()
|
|
|
|
this.testButtons[i][2].draw()
|
|
|
|
this.testButtons[i][3].draw()
|
|
|
|
}
|
2022-12-01 14:41:14 +00:00
|
|
|
if (this.buttons[0].isPressed()) {
|
|
|
|
if (this.offset > 0) {
|
|
|
|
this.offset--;
|
|
|
|
}
|
|
|
|
this.createTestButtons(this.offset);
|
|
|
|
} else if (this.buttons[1].isPressed()) {
|
|
|
|
if (user.tests.length - 13 - this.offset > 0) {
|
|
|
|
this.offset++;
|
|
|
|
}
|
|
|
|
this.createTestButtons(this.offset);
|
2022-11-29 12:21:38 +00:00
|
|
|
}
|
2022-12-01 14:41:14 +00:00
|
|
|
|
|
|
|
for (let i = 0; i < this.buttons.length; i++) {
|
|
|
|
this.buttons[i].draw();
|
2022-11-29 12:21:38 +00:00
|
|
|
}
|
2022-12-01 14:41:14 +00:00
|
|
|
} else {
|
|
|
|
fill(user.colorScheme.text);
|
|
|
|
text("Looks Like You Don't have any tests :(", windowWidth / 2, 300);
|
2022-11-29 12:21:38 +00:00
|
|
|
}
|
|
|
|
|
2022-12-01 14:41:14 +00:00
|
|
|
fill(user.colorScheme.text);
|
2022-11-29 12:21:38 +00:00
|
|
|
text(`Logged in as ${user.username}`, windowWidth-150, 15);
|
|
|
|
}
|
|
|
|
|
|
|
|
createTestButtons(offset = 0) {
|
|
|
|
this.testButtons = [[
|
2022-12-01 14:41:14 +00:00
|
|
|
new Button(400, 270, 100, 30, "test #"), // test # button
|
|
|
|
new Button(500, 270, 100, 30, "wpm"), // wpm button
|
|
|
|
new Button(600, 270, 100, 30, "accuracy"), // accuracy button
|
|
|
|
new Button(700, 270, 240, 30, "characters typed")
|
2022-11-29 12:21:38 +00:00
|
|
|
]];
|
|
|
|
let j = 300;
|
2022-12-01 14:41:14 +00:00
|
|
|
for (let i = user.tests.length-1-offset; i >= user.tests.length-13-offset && i >= 0; i--) {
|
2022-11-29 12:21:38 +00:00
|
|
|
this.testButtons.push([
|
2022-12-01 14:41:14 +00:00
|
|
|
new Button(400, j, 100, 30, `${i+1}`, true, true , "#000", "#000", "#fff"), // test # button
|
|
|
|
new Button(500, j, 100, 30, `${user.tests[i].accuracy}`, true, true , "#000", "#000", "#fff"), // accuracy button
|
|
|
|
new Button(600, j, 100, 30, `${user.tests[i].wpm}`, true, true , "#000", "#000", "#fff"), // wpm button
|
|
|
|
new Button(700, j, 240, 30, `${user.tests[i].test_length}`, true, true , "#000", "#000", "#fff")
|
2022-11-29 12:21:38 +00:00
|
|
|
])
|
|
|
|
j+=30;
|
|
|
|
}
|
2022-11-17 11:48:12 +00:00
|
|
|
}
|
|
|
|
}
|