diff --git a/src/front/static/ts/views/LoginPage.ts b/src/front/static/ts/views/LoginPage.ts
index cffe8fb..be5b8e1 100644
--- a/src/front/static/ts/views/LoginPage.ts
+++ b/src/front/static/ts/views/LoginPage.ts
@@ -27,8 +27,10 @@ export default class extends Aview {
diff --git a/src/front/static/ts/views/Pong.ts b/src/front/static/ts/views/Pong.ts
index 526812c..a1d7bd0 100644
--- a/src/front/static/ts/views/Pong.ts
+++ b/src/front/static/ts/views/Pong.ts
@@ -59,6 +59,9 @@ export default class extends Aview {
let p1_name: string;
let p2_name: string;
+ let p1_displayName: string;
+ let p2_displayName: string;
+
let countdown: number = 3;
let countdownTimer: number = 0;
@@ -203,8 +206,8 @@ export default class extends Aview {
ctx.font = "24px Kubasta";
let text_score = `${p1_score} - ${p2_score}`;
ctx.fillText(text_score, canvas.width / 2 - (ctx.measureText(text_score).width / 2), 25);
- ctx.fillText(p1_name, canvas.width / 4 - (ctx.measureText(p1_name).width / 2), 45);
- ctx.fillText(p2_name, (canvas.width / 4 * 3) - (ctx.measureText(p2_name).width / 2), 45);
+ ctx.fillText(p1_displayName, canvas.width / 4 - (ctx.measureText(p1_name).width / 2), 45);
+ ctx.fillText(p2_displayName, (canvas.width / 4 * 3) - (ctx.measureText(p2_name).width / 2), 45);
if (match_over)
{
@@ -273,23 +276,46 @@ export default class extends Aview {
if (await isLogged())
{
uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2];
- const userdata_req = await fetch(`http://localhost:3002/users/${uuid}`, {
- method: "GET",
- credentials: "include",
- });
- if (userdata_req.status == 404)
- {
- console.error("invalid user");
- return ;
- }
- let userdata = await userdata_req.json();
- p1_input.value = userdata.displayName;
+
+ p1_input.value = uuid;
p1_input.readOnly = true;
}
else
p1_input.value = "player 1";
- document.getElementById("game-start")?.addEventListener("click", () => {
+ document.getElementById("game-start")?.addEventListener("click", async () => {
+ let p1_isvalid = true;
+ let p2_isvalid = true;
+ if (await isLogged()) {
+ const p1_req = await fetch(`http://localhost:3002/users/${p1_input.value}`, {
+ method: "GET",
+ credentials: "include",
+ });
+ const p2_req = await fetch(`http://localhost:3002/users/${p2_input.value}`, {
+ method: "GET",
+ credentials: "include",
+ });
+ if (p1_req.status != 200)
+ p1_isvalid = false;
+ else
+ p1_displayName = (await p1_req.json()).displayName;
+
+ if (p2_req.status != 200)
+ p2_isvalid = false;
+ else
+ p2_displayName = (await p2_req.json()).displayName;
+ }
+ else
+ p1_isvalid = p2_isvalid = false;
+ p1_name = p1_input.value;
+ p2_name = p2_input.value;
+ if (!p1_isvalid)
+ p1_displayName = p1_name;
+ if (!p2_isvalid)
+ p2_displayName = p2_name;
+
+ p1_displayName = p1_displayName.length > 16 ? p1_displayName.substring(0, 16) + "." : p1_displayName;
+ p2_displayName = p2_displayName.length > 16 ? p2_displayName.substring(0, 16) + "." : p2_displayName;
p1_name = p1_input.value.length > 16 ? p1_input.value.substring(0, 16) + "." : p1_input.value;
p2_name = p2_input.value.length > 16 ? p2_input.value.substring(0, 16) + "." : p2_input.value;
document.getElementById("player-inputs").remove();
diff --git a/src/front/static/ts/views/Profile.ts b/src/front/static/ts/views/Profile.ts
index 24faa0a..8da9656 100644
--- a/src/front/static/ts/views/Profile.ts
+++ b/src/front/static/ts/views/Profile.ts
@@ -78,6 +78,12 @@ export default class extends Aview {
if (matches.matchHistory) {
for (let match of matches.matchHistory) {
+ const p2_req = await fetch(`http://localhost:3002/users/${match.score.p2}`, {
+ method: "GET",
+ credentials: "include",
+ });
+ match.score.p1 = userdata.displayName;
+ match.score.p2 = (await p2_req.json()).displayName;
const newEntry = document.createElement("li");
newEntry.classList.add("m-1", "default-button", "bg-neutral-200", "dark:bg-neutral-800", "text-neutral-900", "dark:text-white");
newEntry.innerHTML = match.score.p1Score > match.score.p2Score ? `${match.score.p1} - winner` : `${match.score.p2} - winner`;
@@ -134,6 +140,15 @@ export default class extends Aview {
if (matches.matchHistory) {
for (let match of matches.matchHistory) {
+ if (match.score.p2 != undefined)
+ {
+ const p2_req = await fetch(`http://localhost:3002/users/${match.score.p2}`, {
+ method: "GET",
+ credentials: "include",
+ });
+ match.score.p2 = (await p2_req.json()).displayName;
+ }
+ match.score.p1 = userdata.displayName;
const newEntry = document.createElement("li");
newEntry.classList.add("m-1", "default-button", "bg-neutral-200", "dark:bg-neutral-800", "text-neutral-900", "dark:text-white");
newEntry.innerHTML = match.score.p2 != undefined ?
diff --git a/src/front/static/ts/views/ProfileMenu.ts b/src/front/static/ts/views/ProfileMenu.ts
index 40d68f6..591c96a 100644
--- a/src/front/static/ts/views/ProfileMenu.ts
+++ b/src/front/static/ts/views/ProfileMenu.ts
@@ -68,19 +68,20 @@ export default class extends Aview {
`;
}
+ requestAnimationFrame(async () => {
+ document.getElementById("profile-items").innerHTML = await getMainHTML();
- document.getElementById("profile-items").innerHTML = await getMainHTML();
-
- document.getElementById("menu-logout").addEventListener("click", async () => {
- let req = await fetch("http://localhost:3001/logout", {
- method: "GET",
- credentials: "include",
+ document.getElementById("menu-logout").addEventListener("click", async () => {
+ let req = await fetch("http://localhost:3001/logout", {
+ method: "GET",
+ credentials: "include",
+ });
+ isLogged();
+ if (req.status === 200)
+ this.run();
+ else
+ console.error("logout failed");
});
- isLogged();
- if (req.status === 200)
- this.run();
- else
- console.error("logout failed");
});
}
}
diff --git a/src/front/static/ts/views/RegisterPage.ts b/src/front/static/ts/views/RegisterPage.ts
index 30618f1..2e0493e 100644
--- a/src/front/static/ts/views/RegisterPage.ts
+++ b/src/front/static/ts/views/RegisterPage.ts
@@ -27,8 +27,10 @@ export default class extends Aview {
@@ -75,7 +77,6 @@ export default class extends Aview {
});
let uuid = await uuid_req.json();
document.cookie = `uuid=${uuid.user};max-ages=${60*60*24*7}`;
- console.log(document.cookie);
isLogged();
navigationManager("/");
}
diff --git a/src/front/static/ts/views/TetrisVersus.ts b/src/front/static/ts/views/TetrisVersus.ts
index f9debac..da1805a 100644
--- a/src/front/static/ts/views/TetrisVersus.ts
+++ b/src/front/static/ts/views/TetrisVersus.ts
@@ -65,6 +65,8 @@ export default class extends Aview {
let p2_score: number = 0;
let p1_name: string;
let p2_name: string;
+ let p1_displayName: string;
+ let p2_displayName: string;
const view = this;
@@ -861,7 +863,7 @@ export default class extends Aview {
ctx.fillRect(4, 4, 120, 60);
ctx.fillStyle = "#fff";
ctx.font = "12px Kubasta";
- ctx.fillText(`${this.id == 0 ? p1_name : p2_name}: ${this.id == 0 ? p1_score : p2_score}`, 8, 20);
+ ctx.fillText(`${this.id == 0 ? p1_displayName : p2_displayName}: ${this.id == 0 ? p1_score : p2_score}`, 8, 20);
ctx.fillText(`score: ${this.score}`, 8, 36);
ctx.fillText(`lines: ${this.lines}`, 8, 52);
@@ -931,26 +933,48 @@ export default class extends Aview {
p2_input.value = "player 2";
if (await isLogged())
{
- uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2];
- const userdata_req = await fetch(`http://localhost:3002/users/${uuid}`, {
- method: "GET",
- credentials: "include",
- });
- if (userdata_req.status == 404)
- {
- console.error("invalid user");
- return ;
- }
- let userdata = await userdata_req.json();
- p1_input.value = userdata.displayName;
+ uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2];
+ p1_input.value = uuid;
p1_input.readOnly = true;
}
else
p1_input.value = "player 1";
- document.getElementById("game-start")?.addEventListener("click", () => {
- p1_name = p1_input.value.length > 16 ? p1_input.value.substring(0, 16) + "." : p1_input.value;
- p2_name = p2_input.value.length > 16 ? p2_input.value.substring(0, 16) + "." : p2_input.value;
+ document.getElementById("game-start")?.addEventListener("click", async () => {
+ let p1_isvalid = true;
+ let p2_isvalid = true;
+ if (await isLogged()) {
+ const p1_req = await fetch(`http://localhost:3002/users/${p1_input.value}`, {
+ method: "GET",
+ credentials: "include",
+ });
+ const p2_req = await fetch(`http://localhost:3002/users/${p2_input.value}`, {
+ method: "GET",
+ credentials: "include",
+ });
+ if (p1_req.status != 200)
+ p1_isvalid = false;
+ else
+ p1_displayName = (await p1_req.json()).displayName;
+
+ if (p2_req.status != 200)
+ p2_isvalid = false;
+ else
+ p2_displayName = (await p2_req.json()).displayName;
+ }
+ else
+ p1_isvalid = p2_isvalid = false;
+
+ p1_name = p1_input.value;
+ p2_name = p2_input.value;
+ if (!p1_isvalid)
+ p1_displayName = p1_name;
+ if (!p2_isvalid)
+ p2_displayName = p2_name;
+
+ p1_displayName = p1_displayName.length > 16 ? p1_displayName.substring(0, 16) + "." : p1_displayName;
+ p2_displayName = p2_displayName.length > 16 ? p2_displayName.substring(0, 16) + "." : p2_displayName;
+
document.getElementById("player-inputs").remove();
document.getElementById("game-boards").classList.remove("hidden");
game1 = new Game("board1", 0);
diff --git a/src/front/static/ts/views/TournamentMenu.ts b/src/front/static/ts/views/TournamentMenu.ts
index 00538a8..ddf464b 100644
--- a/src/front/static/ts/views/TournamentMenu.ts
+++ b/src/front/static/ts/views/TournamentMenu.ts
@@ -1,14 +1,17 @@
import Aview from "./Aview.ts"
+import { isLogged } from "../main.js"
import { dragElement } from "./drag.ts";
-import { setOnekoState, setBallPos } from "../oneko.ts"
+import { setOnekoState, setBallPos, setOnekoOffset } from "../oneko.ts"
export default class extends Aview {
+ running: boolean;
constructor()
{
super();
this.setTitle("Tournament");
setOnekoState("default");
+ this.running = true;
}
async getHTML() {
@@ -23,7 +26,8 @@ export default class extends Aview {
-