|
|
|
@ -32,11 +32,17 @@ let lastAskingPlayer = 0
|
|
|
|
|
let lastNodeId = -1
|
|
|
|
|
let first = true
|
|
|
|
|
let askedWrong = false
|
|
|
|
|
let solo: boolean = true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange}) => {
|
|
|
|
|
|
|
|
|
|
const { indices, indice, person, personNetwork, setNodeIdData, players, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex, turnPlayerIndex, onlyFalse, setOnlyFalseData } = useGame();
|
|
|
|
|
|
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
|
|
|
const solotmp = params.get('solo');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let playerIndex: number = turnPlayerIndex
|
|
|
|
|
let index = 0
|
|
|
|
|
for (let i=0; i<players.length; i++){
|
|
|
|
@ -50,15 +56,16 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
|
|
|
|
|
if (first){
|
|
|
|
|
first = false
|
|
|
|
|
if (solotmp == "false"){
|
|
|
|
|
solo=false
|
|
|
|
|
}
|
|
|
|
|
if (!solo){
|
|
|
|
|
setActualPlayerIndexData(index)
|
|
|
|
|
if (playerIndex == thisPlayerIndex){
|
|
|
|
|
handleTurnBarTextChange("À vous de jouer")
|
|
|
|
|
handleShowTurnBar(true)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
indices.forEach(i => {
|
|
|
|
|
console.log(i.ToString("en"))
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
@ -72,7 +79,6 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
console.error("Container not found");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Charger les données dans le graph
|
|
|
|
|
const nodes = new DataSet(graph.nodesPerson);
|
|
|
|
|
|
|
|
|
@ -99,7 +105,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
|
|
|
|
|
const networkData = { nodes: nodes, edges: graph.edges };
|
|
|
|
|
const network = new Network(container, networkData, initialOptions);
|
|
|
|
|
|
|
|
|
|
if (!solo){
|
|
|
|
|
socket.on("asked all", (id) =>{
|
|
|
|
|
const pers = personNetwork.getPersons().find((p) => p.getId() == id)
|
|
|
|
|
if (pers!=undefined){
|
|
|
|
@ -177,6 +183,8 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -209,14 +217,12 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
|
|
|
|
|
if(params.nodes.length > 0){
|
|
|
|
|
setNodeIdData(params.nodes[0])
|
|
|
|
|
// Renvoyer un true pour afficher la choice bar
|
|
|
|
|
if (!solo){
|
|
|
|
|
if (askedWrong){
|
|
|
|
|
console.log(askedWrong)
|
|
|
|
|
const person = personNetwork?.getPersons().find((p) => p.getId() == params.nodes[0])
|
|
|
|
|
if (person !== undefined && indice !== null){
|
|
|
|
|
const tester = IndiceTesterFactory.Create(indice)
|
|
|
|
|
if (!tester.Works(person) && !askedPersons.includes(person)){
|
|
|
|
|
console.log(playerIndex)
|
|
|
|
|
playerIndex = thisPlayerIndex + 1
|
|
|
|
|
if(playerIndex == players.length){
|
|
|
|
|
playerIndex = 0
|
|
|
|
@ -226,7 +232,6 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
askedWrong = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (thisPlayerIndex == playerIndex){
|
|
|
|
|
onNodeClick(true)
|
|
|
|
@ -235,6 +240,21 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
onNodeClick(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
const person = personNetwork?.getPersons().find((p) => p.getId() == params.nodes[0]) //person sélectionnée
|
|
|
|
|
if (person != undefined){
|
|
|
|
|
indices.forEach(async (i, index) =>{
|
|
|
|
|
const tester = IndiceTesterFactory.Create(i)
|
|
|
|
|
const test = tester.Works(person)
|
|
|
|
|
const node = nodes.get().find((n) => params.nodes[0] == n.id)
|
|
|
|
|
if (node!=undefined){
|
|
|
|
|
networkData.nodes.update({id: params.nodes[0], label: node.label + colorToEmoji(positionToColor(index), test)})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Renvoyer un true pour afficher la choice bar
|
|
|
|
|
else{
|
|
|
|
|
// Renvoyer un false pour cacher la choice bar
|
|
|
|
|
onNodeClick(false)
|
|
|
|
@ -247,6 +267,10 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
<div id="graph-container"/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
function delay(ms: number) {
|
|
|
|
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|