|
|
@ -17,6 +17,7 @@ import Pair from "../model/Pair";
|
|
|
|
import Player from "../model/Player";
|
|
|
|
import Player from "../model/Player";
|
|
|
|
import JSONParser from "../JSONParser";
|
|
|
|
import JSONParser from "../JSONParser";
|
|
|
|
import User from "../model/User";
|
|
|
|
import User from "../model/User";
|
|
|
|
|
|
|
|
import { json } from "body-parser";
|
|
|
|
|
|
|
|
|
|
|
|
interface MyGraphComponentProps {
|
|
|
|
interface MyGraphComponentProps {
|
|
|
|
onNodeClick: (shouldShowChoiceBar: boolean) => void;
|
|
|
|
onNodeClick: (shouldShowChoiceBar: boolean) => void;
|
|
|
@ -59,6 +60,7 @@ let cptOnAskedWrong = 0
|
|
|
|
let cptPlayerLeft = 0
|
|
|
|
let cptPlayerLeft = 0
|
|
|
|
let firstPlayer = 0
|
|
|
|
let firstPlayer = 0
|
|
|
|
let cptBug = 0
|
|
|
|
let cptBug = 0
|
|
|
|
|
|
|
|
let cptUseEffect = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, isEasy, addToHistory, showLast, setNetwork, setNetworkEnigme, setPlayerIndex, askedWrong, setAskedWrong}) => {
|
|
|
|
const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, isEasy, addToHistory, showLast, setNetwork, setNetworkEnigme, setPlayerIndex, askedWrong, setAskedWrong}) => {
|
|
|
@ -68,7 +70,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
let initMtn = 0
|
|
|
|
let initMtn = 0
|
|
|
|
|
|
|
|
|
|
|
|
const {isLoggedIn, user, manager} = useAuth();
|
|
|
|
const {isLoggedIn, user, manager} = useAuth();
|
|
|
|
const { indices, indice, person, personNetwork, setNodeIdData, players, setPlayersData, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex, turnPlayerIndex, setTurnPlayerIndexData, setWinnerData, dailyEnigme, setNbCoupData, settempsData, setNetworkDataData, setSeedData} = useGame();
|
|
|
|
const { indices, indice, person, personNetwork, setNodeIdData, players, setPlayersData, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex, turnPlayerIndex, setTurnPlayerIndexData, setWinnerData, dailyEnigme, setNbCoupData, settempsData, setNetworkDataData, setSeedData, nodesC} = useGame();
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
|
|
|
|
|
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
const navigate = useNavigate();
|
|
|
@ -83,7 +85,6 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
settempsData(elapsedTime)
|
|
|
|
settempsData(elapsedTime)
|
|
|
|
|
|
|
|
|
|
|
|
cptBug ++
|
|
|
|
cptBug ++
|
|
|
|
console.log(cptBug)
|
|
|
|
|
|
|
|
if (cptBug > 10){
|
|
|
|
if (cptBug > 10){
|
|
|
|
cptBug = 0
|
|
|
|
cptBug = 0
|
|
|
|
socket.emit("who plays", room)
|
|
|
|
socket.emit("who plays", room)
|
|
|
@ -287,19 +288,6 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//* fonction qui reinitialise le graphe
|
|
|
|
|
|
|
|
const resGraph = () => { //? comment accéder au nework ??
|
|
|
|
|
|
|
|
const savedGraphStateString = localStorage.getItem('graphState');
|
|
|
|
|
|
|
|
if (savedGraphStateString !== null) {
|
|
|
|
|
|
|
|
const savedGraphState = JSON.parse(savedGraphStateString);
|
|
|
|
|
|
|
|
//network.setData(savedGraphState);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// La clé 'graphState' n'existe pas dans le localStorage, prenez une action en conséquence.
|
|
|
|
|
|
|
|
console.log("ayoooooo");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
if (personNetwork == null){
|
|
|
|
if (personNetwork == null){
|
|
|
|
return
|
|
|
|
return
|
|
|
@ -319,7 +307,10 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Charger les données dans le graph
|
|
|
|
// Charger les données dans le graph
|
|
|
|
const nodes = new DataSet(graph.nodesPerson);
|
|
|
|
let nodes = new DataSet(graph.nodesPerson);
|
|
|
|
|
|
|
|
if (nodesC.length != 0){
|
|
|
|
|
|
|
|
nodes = new DataSet(nodesC)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Configuration des options du Graphe
|
|
|
|
// Configuration des options du Graphe
|
|
|
|
const initialOptions = {
|
|
|
|
const initialOptions = {
|
|
|
@ -379,13 +370,39 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
socket.on("give network", (playerId) => {
|
|
|
|
|
|
|
|
socket.emit("give network", JSON.stringify(personNetwork, null, 2), JSON.stringify(person), JSON.stringify(indices), playerIndex, room, JSON.stringify(nodes.get()), playerId);
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
socket.on("player joined ingame", (tab) => {
|
|
|
|
|
|
|
|
const tmpTab: Player[] = []
|
|
|
|
|
|
|
|
let ind =0
|
|
|
|
|
|
|
|
for (const p of tab){
|
|
|
|
|
|
|
|
if (p.type === "User"){
|
|
|
|
|
|
|
|
tmpTab.push(JSONParser.JSONToPlayer(p))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
tmpTab.push(players[ind])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ind ++
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setPlayersData(tmpTab)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
socket.on("player left ingame", (tab, i) => {
|
|
|
|
socket.on("player left ingame", (tab, i) => {
|
|
|
|
cptPlayerLeft ++
|
|
|
|
cptPlayerLeft ++
|
|
|
|
if (cptPlayerLeft % 2 == 0){
|
|
|
|
if (cptPlayerLeft % 2 == 0){
|
|
|
|
const tmpTab: Player[] = []
|
|
|
|
const tmpTab: Player[] = []
|
|
|
|
|
|
|
|
let ind =0
|
|
|
|
for (const p of tab.tab){
|
|
|
|
for (const p of tab.tab){
|
|
|
|
|
|
|
|
if (ind === i || p.type === "User"){
|
|
|
|
tmpTab.push(JSONParser.JSONToPlayer(p))
|
|
|
|
tmpTab.push(JSONParser.JSONToPlayer(p))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
tmpTab.push(players[ind])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ind ++
|
|
|
|
|
|
|
|
}
|
|
|
|
if (i==firstPlayer){
|
|
|
|
if (i==firstPlayer){
|
|
|
|
console.log(tmpTab)
|
|
|
|
console.log(tmpTab)
|
|
|
|
for(let index = 0; index < tmpTab.length; index++){
|
|
|
|
for(let index = 0; index < tmpTab.length; index++){
|
|
|
@ -395,7 +412,6 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log(firstPlayer)
|
|
|
|
|
|
|
|
if (actualPlayerIndex==firstPlayer){
|
|
|
|
if (actualPlayerIndex==firstPlayer){
|
|
|
|
tmpTab.forEach((p, index) =>{
|
|
|
|
tmpTab.forEach((p, index) =>{
|
|
|
|
if (p instanceof Bot && personNetwork!=null){
|
|
|
|
if (p instanceof Bot && personNetwork!=null){
|
|
|
@ -762,6 +778,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
socket.off("put correct background")
|
|
|
|
socket.off("put correct background")
|
|
|
|
socket.off("put grey background")
|
|
|
|
socket.off("put grey background")
|
|
|
|
socket.off("put imossible grey")
|
|
|
|
socket.off("put imossible grey")
|
|
|
|
|
|
|
|
socket.off("who plays")
|
|
|
|
|
|
|
|
|
|
|
|
navigate("/endgame")
|
|
|
|
navigate("/endgame")
|
|
|
|
}
|
|
|
|
}
|
|
|
|