mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 10:20:16 +01:00
Ajout traque-app
This commit is contained in:
33
traque-app/hook/useGame.jsx
Normal file
33
traque-app/hook/useGame.jsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import { useSocket } from "../context/socketContext";
|
||||
import { useTeamConnexion } from "../context/teamConnexionContext";
|
||||
import { useTeamContext } from "../context/teamContext";
|
||||
|
||||
export default function useGame() {
|
||||
const { teamSocket } = useSocket();
|
||||
const { teamId } = useTeamConnexion();
|
||||
const { teamInfos, gameState } = useTeamContext();
|
||||
|
||||
function sendCurrentPosition() {
|
||||
console.log("Reveal position.")
|
||||
teamSocket.emit("send_position");
|
||||
}
|
||||
|
||||
function capture(captureCode) {
|
||||
console.log("Try to capture :", captureCode);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeout = setTimeout(() => {
|
||||
console.warn("Server did not respond to capture emit.");
|
||||
reject();
|
||||
}, 3000);
|
||||
|
||||
teamSocket.emit("capture", captureCode, (response) => {
|
||||
clearTimeout(timeout);
|
||||
console.log(response.message);
|
||||
resolve(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return {...teamInfos, sendCurrentPosition, capture, teamId, gameState};
|
||||
}
|
||||
Reference in New Issue
Block a user