Merge branch 'master' of https://codefirst.iut.uca.fr/git/Crypteam/Cryptid into lobbyfix
continuous-integration/drone/push Build is passing Details

pull/93/head
Pierre Ferreira 1 year ago
commit d9c22353e8

6
.gitignore vendored

@ -44,11 +44,11 @@ thumb
sketch sketch
### modules ### ### modules ###
yarn.lock **/yarn.lock
package-lock.json **/package-lock.json
# db # db
socialgraph.db **/socialgraph.db
# build # build
cryptide_project/build/ cryptide_project/build/

@ -37,9 +37,21 @@ io.on('connection', (socket) => {
io.to(playerId).emit("join during game", networkPerson, person, indices, start, map.get(room).tab, nodes) io.to(playerId).emit("join during game", networkPerson, person, indices, start, map.get(room).tab, nodes)
}) })
socket.on("join back game", (player) => {
for (const k of map.keys()){
const tab = map.get(k)
for (let i = 0; i<tab.tab.length; i++){
if (tab.tab[i].pseudo === player.pseudo && tab.tab[i].type !== "User"){
if (tab.started){
io.to(socket.id).emit("join back game", k)
}
}
}
}
})
socket.on("lobby joined", (room, player) =>{ socket.on("lobby joined", (room, player) =>{
if (lastSocketJoined != player.id){
lastSocketJoined=player.id
const game = map.get(room) const game = map.get(room)
if (game !== undefined){ if (game !== undefined){
if (game.tab.length == 6 && !game.started){ if (game.tab.length == 6 && !game.started){
@ -88,7 +100,6 @@ io.on('connection', (socket) => {
const playerArray = Array.from(map.entries()).map(([key, value]) => ({ key, value })) const playerArray = Array.from(map.entries()).map(([key, value]) => ({ key, value }))
const playerJson = JSON.stringify(playerArray); const playerJson = JSON.stringify(playerArray);
io.emit("request lobbies", playerJson) io.emit("request lobbies", playerJson)
}
}) })
@ -134,6 +145,7 @@ io.on('connection', (socket) => {
}) })
socket.on("who plays", (room) => { socket.on("who plays", (room) => {
if (map.get(room) !== undefined){
let player = map.get(room).actualPlayer let player = map.get(room).actualPlayer
if (map.get(room).tab[player].type != "User"){ if (map.get(room).tab[player].type != "User"){
player = player + 1 player = player + 1
@ -143,6 +155,7 @@ io.on('connection', (socket) => {
} }
console.log(player) console.log(player)
io.to(room).emit("who plays", player, map.get(room).lastWorks) io.to(room).emit("who plays", player, map.get(room).lastWorks)
}
}) })
socket.on("disconnect", () =>{ socket.on("disconnect", () =>{

@ -61,6 +61,7 @@ let cptPlayerLeft = 0
let firstPlayer = 0 let firstPlayer = 0
let cptBug = 0 let cptBug = 0
let cptUseEffect = 0 let cptUseEffect = 0
let testPlayers: Player[] = []
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}) => {
@ -102,8 +103,14 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
}, [elapsedTime, endgame]); }, [elapsedTime, endgame]);
useEffect(() => {
testPlayers = players
console.log(testPlayers)
}, [players])
useEffect(() =>{ useEffect(() =>{
touchedPlayer=playerTouched touchedPlayer=playerTouched
console.log(playerTouched)
if (touchedPlayer == -1){ if (touchedPlayer == -1){
if (!askedWrongLocal){ if (!askedWrongLocal){
socket.emit("put correct background", socket.id) socket.emit("put correct background", socket.id)
@ -157,7 +164,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
useEffect(() =>{ useEffect(() =>{
cptBug=0 cptBug=0
if (actualPlayerIndex==firstPlayer){ if (actualPlayerIndex==firstPlayer){
const bot = players[lastIndex] const bot = testPlayers[lastIndex]
if(bot instanceof Bot && botIndex != lastIndex){ if(bot instanceof Bot && botIndex != lastIndex){
botIndex = lastIndex botIndex = lastIndex
if (personNetwork!=null){ if (personNetwork!=null){
@ -181,7 +188,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
} }
const tester = IndiceTesterFactory.Create(indices[playerIndex]) const tester = IndiceTesterFactory.Create(indices[playerIndex])
const works = tester.Works(person) const works = tester.Works(person)
socket.emit("asked all 1by1", person.getId(), players[playerIndex].id) socket.emit("asked all 1by1", person.getId(), testPlayers[playerIndex].id)
if (i==players.length){ if (i==players.length){
socket.emit("node checked", personIndex, works, playerIndex, room, nextPlayerIndex) socket.emit("node checked", personIndex, works, playerIndex, room, nextPlayerIndex)
} }
@ -190,7 +197,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
} }
if(!works){ if(!works){
socket.emit("node checked", personIndex, works, playerIndex, room, nextPlayerIndex) socket.emit("node checked", personIndex, works, playerIndex, room, nextPlayerIndex)
const ind = bot.placeSquare(personNetwork, players) const ind = bot.placeSquare(personNetwork, testPlayers)
if (ind == -1 ){ if (ind == -1 ){
socket.emit("can't put square", lastIndex, room) socket.emit("can't put square", lastIndex, room)
return return
@ -209,7 +216,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
} }
else{ else{
if (person!=undefined){ if (person!=undefined){
if (players[choosedPlayerIndex] instanceof Bot){ if (testPlayers[choosedPlayerIndex] instanceof Bot){
console.log("BOT") console.log("BOT")
const tester = IndiceTesterFactory.Create(indices[choosedPlayerIndex]) const tester = IndiceTesterFactory.Create(indices[choosedPlayerIndex])
const works = tester.Works(person) const works = tester.Works(person)
@ -224,7 +231,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
else{ else{
console.log(lastIndex + " interroge " + choosedPlayerIndex + " a propos de " + person.getName() + " et dit non") console.log(lastIndex + " interroge " + choosedPlayerIndex + " a propos de " + person.getName() + " et dit non")
socket.emit("node checked", personIndex, false, choosedPlayerIndex, room, lastIndex) socket.emit("node checked", personIndex, false, choosedPlayerIndex, room, lastIndex)
const ind = bot.placeSquare(personNetwork, players) const ind = bot.placeSquare(personNetwork, testPlayers)
if (ind == -1 ){ if (ind == -1 ){
socket.emit("can't put square", playerIndex, room) socket.emit("can't put square", playerIndex, room)
return return
@ -239,11 +246,11 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
} }
else{ else{
console.log(choosedPlayerIndex + " => Pas bot" ) console.log(choosedPlayerIndex + " => Pas bot" )
socket.emit("ask player", personIndex, players[choosedPlayerIndex].id, players[lastIndex]) socket.emit("ask player", personIndex, testPlayers[choosedPlayerIndex].id, testPlayers[lastIndex])
console.log(lastIndex + " interroge " + +choosedPlayerIndex + " sur " + personNetwork.getPersons()[personIndex].getName()) console.log(lastIndex + " interroge " + +choosedPlayerIndex + " sur " + personNetwork.getPersons()[personIndex].getName())
const tester = IndiceTesterFactory.Create(indices[choosedPlayerIndex]) const tester = IndiceTesterFactory.Create(indices[choosedPlayerIndex])
if (!tester.Works(person)){ if (!tester.Works(person)){
const ind = bot.placeSquare(personNetwork, players) const ind = bot.placeSquare(personNetwork, testPlayers)
if (ind == -1 ){ if (ind == -1 ){
socket.emit("can't put square", playerIndex, room) socket.emit("can't put square", playerIndex, room)
return return
@ -382,7 +389,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
tmpTab.push(JSONParser.JSONToPlayer(p)) tmpTab.push(JSONParser.JSONToPlayer(p))
} }
else{ else{
tmpTab.push(players[ind]) tmpTab.push(testPlayers[ind])
} }
ind ++ ind ++
} }
@ -399,12 +406,11 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
tmpTab.push(JSONParser.JSONToPlayer(p)) tmpTab.push(JSONParser.JSONToPlayer(p))
} }
else{ else{
tmpTab.push(players[ind]) tmpTab.push(testPlayers[ind])
} }
ind ++ ind ++
} }
if (i==firstPlayer){ if (i==firstPlayer){
console.log(tmpTab)
for(let index = 0; index < tmpTab.length; index++){ for(let index = 0; index < tmpTab.length; index++){
const test = tmpTab[index] const test = tmpTab[index]
if (test instanceof User){ if (test instanceof User){
@ -508,7 +514,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
if (p!=undefined && tab != undefined){ if (p!=undefined && tab != undefined){
tab.push(p) tab.push(p)
if (actualPlayerIndex == 0){ if (actualPlayerIndex == 0){
players.forEach((player) => { testPlayers.forEach((player) => {
if (player instanceof Bot){ if (player instanceof Bot){
player.newInformation(p, askedIndex, works) player.newInformation(p, askedIndex, works)
} }
@ -522,7 +528,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
cptHistory++ cptHistory++
if (cptHistory % 2 == 0){ if (cptHistory % 2 == 0){
lastNodes.push(node) lastNodes.push(node)
addToHistory(players[askedIndex].pseudo + " à mis un " + positionToEmoji(askedIndex, works) + " à " + personNetwork.getPersons()[id].getName()) addToHistory(testPlayers[askedIndex].pseudo + " à mis un " + positionToEmoji(askedIndex, works) + " à " + personNetwork.getPersons()[id].getName())
} }
} }
@ -585,7 +591,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
cptBug=0 cptBug=0
cptOnAskedWrong ++ cptOnAskedWrong ++
if (cptOnAskedWrong % 2 == 0){ if (cptOnAskedWrong % 2 == 0){
addToHistory(players[askingPlayer].pseudo + " ne peut plus poser de carré") addToHistory(testPlayers[askingPlayer].pseudo + " ne peut plus poser de carré")
playerIndex = askingPlayer + 1 playerIndex = askingPlayer + 1
if(playerIndex == players.length){ if(playerIndex == players.length){
playerIndex = 0 playerIndex = 0
@ -630,8 +636,8 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
socket.emit("node checked", nodeId, true, actualPlayerIndex, room, playerIndex) socket.emit("node checked", nodeId, true, actualPlayerIndex, room, playerIndex)
} }
else{ else{
let index = players.findIndex((p) => p.id == askingPlayer.id) let index = testPlayers.findIndex((p) => p.id == askingPlayer.id)
if (players[index] instanceof Bot){ if (testPlayers[index] instanceof Bot){
index = playerIndex + 1 index = playerIndex + 1
if(index == players.length){ if(index == players.length){
index = 0 index = 0
@ -818,9 +824,9 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
network.on("click", async (params) => { network.on("click", async (params) => {
if(params.nodes.length > 0){ if(params.nodes.length > 0){
console.log(actualPlayerIndex + " => " + playerIndex) console.log(touchedPlayer)
console.log(playerTouched)
setNodeIdData(params.nodes[0]) setNodeIdData(params.nodes[0])
console.log(players)
// addToHistory("Le joueur a cliqué") //! TEST DEBUG // addToHistory("Le joueur a cliqué") //! TEST DEBUG
if (!solo){ if (!solo){
if (askedWrongLocal){ if (askedWrongLocal){
@ -851,7 +857,9 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
} }
else if(touchedPlayer != -1 && playerIndex == actualPlayerIndex && touchedPlayer<players.length){ else if(touchedPlayer != -1 && playerIndex == actualPlayerIndex && touchedPlayer<players.length){
botIndex = -1 botIndex = -1
if (players[touchedPlayer] instanceof Bot){ console.log(testPlayers[touchedPlayer])
if (testPlayers[touchedPlayer] instanceof Bot){
console.log("BOT TOUCHÉ")
const ind = indices[touchedPlayer] const ind = indices[touchedPlayer]
const test = IndiceTesterFactory.Create(ind) const test = IndiceTesterFactory.Create(ind)
//@ts-ignore //@ts-ignore
@ -874,7 +882,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
} }
else{ else{
if (touchedPlayer >= 0){ if (touchedPlayer >= 0){
console.log(touchedPlayer) console.log("CE N'EST PAS UN BOT")
//@ts-ignore //@ts-ignore
socket.emit("ask player", params.nodes[0], players[touchedPlayer].id, players.find((p) => p.id === socket.id, actualPlayerIndex)) socket.emit("ask player", params.nodes[0], players[touchedPlayer].id, players.find((p) => p.id === socket.id, actualPlayerIndex))
socket.emit("put correct background", socket.id) socket.emit("put correct background", socket.id)

@ -51,6 +51,7 @@ const PersonStatus: React.FC<PlayerStatusProps> = ({img = Person, state= Person,
function onTouch(){ function onTouch(){
if (IsActualPlayer && !askedWrong){ if (IsActualPlayer && !askedWrong){
setPlayerTouched(index) setPlayerTouched(index)
setTouchedPlayer(index)
} }
} }

@ -10,6 +10,7 @@ import User from '../model/User';
import { socket } from '../SocketConfig'; import { socket } from '../SocketConfig';
import JSONParser from '../JSONParser'; import JSONParser from '../JSONParser';
import Person from '../model/Person'; import Person from '../model/Person';
import { useNavigationType } from 'react-router-dom';
class LobbyDataProps { class LobbyDataProps {
@ -26,6 +27,8 @@ class LobbyDataProps {
} }
} }
let cptNavigation = 0
function Lobbies() { function Lobbies() {
const theme=useTheme(); const theme=useTheme();
@ -62,6 +65,14 @@ function Lobbies() {
setFirst(first) setFirst(first)
} }
const navigationType = useNavigationType()
cptNavigation++
if (cptNavigation % 2 == 0){
if (navigationType.toString() == "POP"){
socket.emit("player quit")
}
}
if (first){ if (first){
setFirst(false) setFirst(false)
socket.emit("request lobbies") socket.emit("request lobbies")

@ -108,6 +108,7 @@ function Play() {
if (loggedIn){ if (loggedIn){
login() login()
setUserData(user) setUserData(user)
socket.emit("join back game", user)
} }
else{ else{
loadImageAsync(defaultImg).then((blob) => { loadImageAsync(defaultImg).then((blob) => {
@ -118,8 +119,19 @@ function Play() {
} }
}) })
} }
else{
socket.emit("join back game", user)
}
}, [isLoggedIn]); }, [isLoggedIn]);
const [goBackRoom, setGoBackRoom] = useState(-1)
useEffect(() => {
socket.on("join back game", (room) => {
setGoBackRoom(room)
})
}, [])
const [room, setRoom] = useState(null); const [room, setRoom] = useState(null);
const navigate = useNavigate(); const navigate = useNavigate();
@ -169,6 +181,10 @@ function Play() {
} }
}, [room, navigate]); }, [room, navigate]);
const goBack = () => {
navigate("/lobby?room=" + goBackRoom)
}
const [showOverlay, setShowOverlay] = useState(false); const [showOverlay, setShowOverlay] = useState(false);
@ -259,7 +275,7 @@ function Play() {
<button onClick={createLobby} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Créer une partie </button> <button onClick={createLobby} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Créer une partie </button>
<button onClick= {() => navigate("/join")} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Rejoindre </button> <button onClick= {() => navigate("/join")} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Rejoindre </button>
{goBackRoom != -1 && <button onClick={goBack} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}>Retourner à la partie</button>}
</div> </div>
</div> </div>
<div className='rightContainer'> <div className='rightContainer'>

@ -1,7 +1,6 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1 # yarn lockfile v1
"@aashutoshrathi/word-wrap@^1.2.3": "@aashutoshrathi/word-wrap@^1.2.3":
version "1.2.6" version "1.2.6"
resolved "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz" resolved "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz"

Loading…
Cancel
Save