diff --git a/components/BottomNavBar.vue b/components/BottomNavBar.vue
index b7e4b4f..4a49cc1 100644
--- a/components/BottomNavBar.vue
+++ b/components/BottomNavBar.vue
@@ -13,8 +13,11 @@
+
+
diff --git a/package.json b/package.json
index aa734b4..c972fa1 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,9 @@
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"bootgame": "tsx server/Game_Manager/src/index.ts",
- "bootcontrol": "tsx server/Controller/src/index.ts"
+ "bootcontrol": "tsx server/Controller/src/index.ts",
+ "bootpi": "tsx server/Rasberri/src/index.ts"
+
},
"dependencies": {
"axios": "^1.7.7",
diff --git a/prisma/migrations/20241017205008_player_stats/migration.sql b/prisma/migrations/20241017205008_player_stats/migration.sql
deleted file mode 100644
index 049f0b7..0000000
--- a/prisma/migrations/20241017205008_player_stats/migration.sql
+++ /dev/null
@@ -1,18 +0,0 @@
--- RedefineTables
-PRAGMA defer_foreign_keys=ON;
-PRAGMA foreign_keys=OFF;
-CREATE TABLE "new_Player" (
- "user_id" TEXT NOT NULL PRIMARY KEY,
- "username" TEXT NOT NULL,
- "email" TEXT NOT NULL,
- "wins" INTEGER NOT NULL DEFAULT 0,
- "goals" INTEGER NOT NULL DEFAULT 0,
- "games" INTEGER NOT NULL DEFAULT 0
-);
-INSERT INTO "new_Player" ("email", "user_id", "username") SELECT "email", "user_id", "username" FROM "Player";
-DROP TABLE "Player";
-ALTER TABLE "new_Player" RENAME TO "Player";
-CREATE UNIQUE INDEX "Player_username_key" ON "Player"("username");
-CREATE UNIQUE INDEX "Player_email_key" ON "Player"("email");
-PRAGMA foreign_keys=ON;
-PRAGMA defer_foreign_keys=OFF;
diff --git a/prisma/migrations/20241017205926_initial/migration.sql b/prisma/migrations/20241017205926_initial/migration.sql
deleted file mode 100644
index 9e8f1b5..0000000
--- a/prisma/migrations/20241017205926_initial/migration.sql
+++ /dev/null
@@ -1,29 +0,0 @@
--- CreateTable
-CREATE TABLE "Player" (
- "user_id" TEXT NOT NULL PRIMARY KEY,
- "username" TEXT NOT NULL,
- "email" TEXT NOT NULL
-);
-
--- CreateTable
-CREATE TABLE "Match" (
- "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
- "datetime" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
-);
-
--- CreateTable
-CREATE TABLE "PlayersInMatches" (
- "playerID" TEXT NOT NULL,
- "playerScore" INTEGER NOT NULL,
- "matchID" INTEGER NOT NULL,
-
- PRIMARY KEY ("playerID", "matchID"),
- CONSTRAINT "PlayersInMatches_playerID_fkey" FOREIGN KEY ("playerID") REFERENCES "Player" ("user_id") ON DELETE RESTRICT ON UPDATE CASCADE,
- CONSTRAINT "PlayersInMatches_matchID_fkey" FOREIGN KEY ("matchID") REFERENCES "Match" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
-);
-
--- CreateIndex
-CREATE UNIQUE INDEX "Player_username_key" ON "Player"("username");
-
--- CreateIndex
-CREATE UNIQUE INDEX "Player_email_key" ON "Player"("email");
diff --git a/prisma/migrations/20241107231241_player_update/migration.sql b/prisma/migrations/20241107231241_player_update/migration.sql
deleted file mode 100644
index d1d2a3f..0000000
--- a/prisma/migrations/20241107231241_player_update/migration.sql
+++ /dev/null
@@ -1,20 +0,0 @@
--- RedefineTables
-PRAGMA defer_foreign_keys=ON;
-PRAGMA foreign_keys=OFF;
-CREATE TABLE "new_Player" (
- "user_id" TEXT NOT NULL PRIMARY KEY,
- "username" TEXT NOT NULL,
- "email" TEXT NOT NULL,
- "wins" INTEGER NOT NULL DEFAULT 0,
- "goals" INTEGER NOT NULL DEFAULT 0,
- "games" INTEGER NOT NULL DEFAULT 0,
- "losses" INTEGER NOT NULL DEFAULT 0,
- "ratio" REAL
-);
-INSERT INTO "new_Player" ("email", "games", "goals", "user_id", "username", "wins") SELECT "email", "games", "goals", "user_id", "username", "wins" FROM "Player";
-DROP TABLE "Player";
-ALTER TABLE "new_Player" RENAME TO "Player";
-CREATE UNIQUE INDEX "Player_username_key" ON "Player"("username");
-CREATE UNIQUE INDEX "Player_email_key" ON "Player"("email");
-PRAGMA foreign_keys=ON;
-PRAGMA defer_foreign_keys=OFF;
diff --git a/prisma/migrations/20240826000552_init/migration.sql b/prisma/migrations/20241206020508_init_expo/migration.sql
similarity index 81%
rename from prisma/migrations/20240826000552_init/migration.sql
rename to prisma/migrations/20241206020508_init_expo/migration.sql
index 9e8f1b5..a9bf193 100644
--- a/prisma/migrations/20240826000552_init/migration.sql
+++ b/prisma/migrations/20241206020508_init_expo/migration.sql
@@ -2,7 +2,12 @@
CREATE TABLE "Player" (
"user_id" TEXT NOT NULL PRIMARY KEY,
"username" TEXT NOT NULL,
- "email" TEXT NOT NULL
+ "email" TEXT NOT NULL,
+ "wins" INTEGER NOT NULL DEFAULT 0,
+ "goals" INTEGER NOT NULL DEFAULT 0,
+ "games" INTEGER NOT NULL DEFAULT 0,
+ "losses" INTEGER NOT NULL DEFAULT 0,
+ "ratio" REAL
);
-- CreateTable
diff --git a/server/Game_Manager/src/index.ts b/server/Game_Manager/src/index.ts
index 42d58de..52e5e56 100644
--- a/server/Game_Manager/src/index.ts
+++ b/server/Game_Manager/src/index.ts
@@ -34,7 +34,7 @@ let score1: number = 10
let score2: number = 2
enum GAME_STATE { NOT_PLAYING, SEND_CONFIRM, PLAYING, RESETTING }
let game_state: GAME_STATE = GAME_STATE.NOT_PLAYING
-let robots_ready: boolean = true
+let robots_ready: boolean = false
// SECTION: GAME CYCLES
const gameCycle = setInterval( async () => {
@@ -152,7 +152,7 @@ const gameCycle = setInterval( async () => {
else if(game_state == GAME_STATE.PLAYING){
// Check when timer reaches 0
console.log(`TIMER: ${timer} | ${players[0]["username"]} vs ${players[1]["username"]}`)
- timer--;
+ //timer--;
if(timer == 0){
game_state = GAME_STATE.RESETTING
}
@@ -260,10 +260,10 @@ const gameCycle = setInterval( async () => {
players.splice(0, 2)
- robots_ready = true
+ robots_ready = false
timer = 0
score1 = 0
- score2 = 0
+ score2 = 3
game_state = GAME_STATE.NOT_PLAYING
}
}, 1000)
diff --git a/server/Rasberri/src/index.ts b/server/Rasberri/src/index.ts
new file mode 100644
index 0000000..61868c9
--- /dev/null
+++ b/server/Rasberri/src/index.ts
@@ -0,0 +1,94 @@
+import { WebSocketServer } from "ws"
+import dotenv from "dotenv"
+
+// Environment variables
+dotenv.config({ path: "./.env" })
+const LOCALHOST: string = process.env.LOCALHOST ?? "localhost"
+const PORT_GM_RASPBERRY: number = parseInt(`${process.env.PORT_GM_RASPBERRY}`)
+const PORT_WSS_CONTROLLER_RASPBERRY: number = parseInt(`${process.env.PORT_WSS_CONTROLLER_RASPBERRY}`)
+
+// Shared variables
+let ready: boolean = true
+let timer: number = 0
+let score1: number = 10
+let score2: number = 2
+
+// FOR GAME MANAGER
+const wss_gm = new WebSocketServer({ port: PORT_GM_RASPBERRY})
+
+wss_gm.on("listening", () => {
+ console.log(`WebSocket wss_gm is running on ws://${LOCALHOST}:${PORT_GM_RASPBERRY}`)
+})
+
+wss_gm.on("error", (error) => {
+ console.log("WebSocket wss_gm error: " + error)
+})
+
+wss_gm.on("close", () => {
+ console.log("WebSocket wss_gm closed")
+})
+
+wss_gm.on("connection", (ws: any, request) => {
+ ws.on("message", (data: any) => {
+ const { type, payload } = JSON.parse(data)
+ if(type === "CHECK_READY"){ // should already be in
+ console.log(`Telling GM: ready is ${ready}`)
+ ws.send(JSON.stringify({
+ "type": "IS_READY",
+ "payload": ready
+ }))
+ }
+ else if(type === "GAME_START"){
+ timer = payload["timer"]
+ const broadcastTimer = setInterval(() => {
+ if(timer === 0){
+ clearInterval(broadcastTimer)
+ clearInterval(broadcastScore)
+ ws.send(JSON.stringify({
+ "type": "GAME_END",
+ "payload": {"timer": timer, "score1": score1, "score2": score2}
+ }))
+ }
+ else{
+ ws.send(JSON.stringify({
+ "type": "TIMER_UPDATE",
+ "payload": {"timer": timer}
+ }))
+ timer--
+ }
+ }, 1000)
+ const broadcastScore = setInterval(() => {
+ ws.send(JSON.stringify({
+ "type": "SCORE_UPDATE",
+ "payload": {"score1": score1, "score2": score2}
+ }))
+ }, 1000)
+ }
+ })
+})
+
+// FOR CONTROLLER
+const wss_control = new WebSocketServer({ port: PORT_WSS_CONTROLLER_RASPBERRY})
+
+wss_control.on("listening", () => {
+ console.log(`WebSocket wss_control is running on ws://${LOCALHOST}:${PORT_WSS_CONTROLLER_RASPBERRY}`)
+})
+
+wss_control.on("error", (error) => {
+ console.log("WebSocket wss_control error: " + error)
+})
+
+wss_control.on("close", () => {
+ console.log("WebSocket wss_control closed")
+})
+
+wss_control.on("connection", (ws: any, request) => {
+ ws.on("message", (data: any) => {
+ const { type, payload } = JSON.parse(data)
+
+ if(type === "KEY_INPUT"){ // should already be in
+ const { keys, playernumber }: {keys: string, playernumber: number} = payload
+ console.log(`Player ${playernumber} pressed ${keys}`)
+ }
+ })
+})
\ No newline at end of file