-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"fixed nav bar layout for now and added rasberry server (use npm run …
…bootpi -- --host"
- Loading branch information
1 parent
4de0f80
commit 50f1826
Showing
8 changed files
with
110 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
prisma/migrations/20241017205008_player_stats/migration.sql
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
prisma/migrations/20241107231241_player_update/migration.sql
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}`) | ||
} | ||
}) | ||
}) |