diff --git a/.drone.yml b/.drone.yml index 37d3bff..e6b8389 100644 --- a/.drone.yml +++ b/.drone.yml @@ -42,7 +42,7 @@ steps: IMAGENAME: mysql:latest CONTAINERNAME: mysql COMMAND: create - OVERWRITE: true + #OVERWRITE: true PRIVATE: false CODEFIRST_CLIENTDRONE_ENV_MYSQL_ROOT_PASSWORD: from_secret: MYSQL_ROOT_PASSWORD @@ -53,6 +53,9 @@ steps: CODEFIRST_CLIENTDRONE_ENV_MYSQL_PASSWORD: from_secret: MYSQL_PASSWORD ADMINS: thomaschazot2,pierreferreira,baptistemarcel + when: + branch: + - CI/CD - name: container-web image: plugins/docker @@ -70,7 +73,7 @@ steps: #depends_on: [ build ] when: branch: - - master + - CI/CD #container deployment diff --git a/cryptide_project/package.json b/cryptide_project/package.json index 4bf2b23..810e10e 100644 --- a/cryptide_project/package.json +++ b/cryptide_project/package.json @@ -1,7 +1,6 @@ { "name": "cryptide", "version": "1.0.0", - "homepage": "/containers/Crypteam-website/", "dependencies": { "@fortawesome/fontawesome-svg-core": "^6.4.2", "@fortawesome/free-regular-svg-icons": "^6.4.2", diff --git a/cryptide_project/src/AdressSetup.ts b/cryptide_project/src/AdressSetup.ts index a5b4f64..16c848c 100644 --- a/cryptide_project/src/AdressSetup.ts +++ b/cryptide_project/src/AdressSetup.ts @@ -9,7 +9,7 @@ const tmp2 = ADRESSE_WEBSERVER const ADRESSE_WEBSITE = "" -const basePath = process.env.REACT_APP_BASE_PATH || '/containers/Crypteam-website'; +const basePath = process.env.REACT_APP_BASE_PATH || ''; const tmp3 = basePath diff --git a/cryptide_project/src/Components/GraphContainer.tsx b/cryptide_project/src/Components/GraphContainer.tsx index b611207..d8de509 100644 --- a/cryptide_project/src/Components/GraphContainer.tsx +++ b/cryptide_project/src/Components/GraphContainer.tsx @@ -21,6 +21,9 @@ import { json } from "body-parser"; import html2canvas from 'html2canvas'; import jsPDF from 'jspdf'; import {basePath} from "../AdressSetup" +import GameCreator from "../model/GameCreator"; +import Stub from "../model/Stub"; +import EnigmeDuJourCreator from "../model/EnigmeDuJourCreator"; import { useIntl } from "react-intl"; interface MyGraphComponentProps { @@ -33,7 +36,7 @@ interface MyGraphComponentProps { addToHistory: (message : string) => void solo : boolean isDaily : boolean - isEasy: boolean + difficulty: string setNetwork: (network: Network) => void showLast: boolean setNetworkEnigme: (networkEnigme: Map[]>) => void @@ -51,12 +54,15 @@ interface MyGraphComponentProps { putGreyBackground : () => void putCorrectBackground : () => void putImposssibleGrey : () => void + setChangeGraph : (func: (nbNodes: number, nbIndices: number) => void) => void handleTurn :() => void lang: string } +let askedWrongBot = false +let lastSocketId= "" let lastAskingPlayer = 0 let lastNodeId = -1 let first = true @@ -64,14 +70,10 @@ let askedWrongLocal = false let mapIndexPersons: Map = new Map() let touchedPlayer = -1 let botIndex = -1 -let askedWrongBot = false -let lastSocketId= "" let firstLap = true let cptHistory = 0 let lastNodes: NodePerson[] = [] let cptEndgame = 0 -let firstEnigme = true -let firstIndex = true let endgame= false let firstHistory = true let cptSquare = 0 @@ -79,14 +81,14 @@ let cptOnAskedWrong = 0 let cptPlayerLeft = 0 let firstPlayer = 0 let cptBug = 0 -let cptUseEffect = 0 let testPlayers: Player[] = [] let testTemps = 0 let testFirst = false +let gameStartTmp = true +let index = 0 - -const MyGraphComponent: React.FC = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, isEasy, addToHistory, showLast, setNetwork, setNetworkEnigme, setPlayerIndex, askedWrong, setAskedWrong, importToPdf, setImportToPdf, importToJSON, setImportToJSON, setPutCorrectBackground, setPutGreyBackground, setPutImposssibleGrey, putCorrectBackground, putGreyBackground, putImposssibleGrey, handleTurn, lang}) => { - let cptTour: number = 0 +const MyGraphComponent: React.FC = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, difficulty, addToHistory, showLast, setNetwork, setNetworkEnigme, setPlayerIndex, askedWrong, setAskedWrong, importToPdf, setImportToPdf, importToJSON, setImportToJSON, setPutCorrectBackground, setPutGreyBackground, setPutImposssibleGrey, putCorrectBackground, putGreyBackground, putImposssibleGrey, handleTurn, setChangeGraph, lang}) => { + let cptTour: number = 1 //* Gestion du temps : let initMtn = 0 @@ -97,7 +99,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS 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, nodesC, temps} = useGame(); + const { indices, indice, person, personNetwork, setNodeIdData, players, setPlayersData, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex, turnPlayerIndex, setIndicesData, setWinnerData, dailyEnigme, setNbCoupData, settempsData, setNetworkDataData, setSeedData, nodesC, temps, setPersonData, setPersonNetworkData, setDailyEnigmeData, gameStart, setGameStartData} = useGame(); const params = new URLSearchParams(window.location.search); const navigate = useNavigate(); @@ -117,10 +119,12 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS settempsData(testTemps) testTemps += 0.5 - cptBug ++ - if (cptBug > 10){ - cptBug = 0 - socket.emit("who plays", room) + if (!solo){ + cptBug ++ + if (cptBug > 10){ + cptBug = 0 + socket.emit("who plays", room) + } } @@ -138,12 +142,10 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS useEffect(() => { testPlayers = players - console.log(testPlayers) }, [players]) useEffect(() =>{ touchedPlayer=playerTouched - console.log(playerTouched) if (touchedPlayer == -1){ if (!askedWrongLocal){ putCorrectBackground() @@ -182,17 +184,45 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS let playerIndex: number = turnPlayerIndex - if (firstIndex){ - firstIndex=false - setPlayerIndex(playerIndex) - } - let index = 0 - for (let i=0; i { + gameStartTmp=gameStart + if (gameStartTmp){ + setGameStartData(false) + console.log(gameStart) + setLastIndex(turnPlayerIndex) + setPlayerIndex(playerIndex) } - } + for (let i=0; i{ + if (p instanceof Bot && personNetwork!=null){ + p.index=index + p.initiateMap(personNetwork) + } + }) + } + setActualPlayerIndexData(index) + if (playerIndex == actualPlayerIndex){ + handleTurnBarTextChange(intl.formatMessage({ id: 'game.yourTurn' })) + handleShowTurnBar(true) + } + } + }, [gameStart]) + + + + useEffect(() =>{ //* Gestion du sound des tours : @@ -309,31 +339,6 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } }, [lastIndex]) - - - if (first){ - first = false - endgame= false - if (!solo){ - for(let i = 0; i{ - if (p instanceof Bot && personNetwork!=null){ - p.index=index - p.initiateMap(personNetwork) - } - }) - } - setActualPlayerIndexData(index) - if (playerIndex == actualPlayerIndex){ - handleTurnBarTextChange(intl.formatMessage({ id: 'game.yourTurn' })) - handleShowTurnBar(true) - } - } - } - useEffect(() => { if (importToPdf){ setImportToPdf(false) @@ -372,10 +377,29 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } }, [importToJSON]) + const changeGraph = (nbNodes: number, nbIndices: number) => { + //todo différencier les deux + const [networkPerson, choosenPerson, choosenIndices] = GameCreator.CreateGame(nbIndices, nbNodes) + setPersonData(choosenPerson) + setPersonNetworkData(networkPerson) + setIndicesData(choosenIndices) + const map = EnigmeDuJourCreator.createEnigme(networkPerson, choosenIndices, choosenPerson, Stub.GenerateIndice()) + setDailyEnigmeData(map) + addToHistory("<----- [Tour " + 1 +"/"+networkPerson.getPersons().length + "] ----->"); + changecptTour(1) + testTemps=0 + + + } + useEffect(() => { if (personNetwork == null){ return } + + if (solo){ + setChangeGraph(() => changeGraph) + } const graph = GraphCreator.CreateGraph(personNetwork) let n = graph.nodesPerson; @@ -430,7 +454,9 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS if (isDaily){ setNetworkEnigme(dailyEnigme) - if (!isEasy){ + console.log(difficulty) + if (difficulty === "hard" || difficulty=== "intermediate"){ + console.log(dailyEnigme) dailyEnigme.forEach((pairs, index) => { pairs.forEach((pair) => { //@ts-ignore @@ -443,7 +469,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS }) }); } - else{ + else if (difficulty === "easy"){ if (firstHistory){ firstHistory=false indices.forEach((indice, index) => { @@ -573,7 +599,6 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS }) socket.on("node checked",(id, works, askedIndex, newPlayerIndex, socketId) => { - console.log("coucou") cptBug=0 //@ts-ignore const node = nodes.get().find((n) => id == n.id) @@ -582,7 +607,6 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS playerIndex = newPlayerIndex setPlayerIndex(playerIndex) setLastIndex(newPlayerIndex) - console.log(newPlayerIndex) //@ts-ignore if (mapIndexPersons.get(askedIndex)?.find((p) => p.getId() == id) == undefined){ //@ts-ignore @@ -736,7 +760,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS else { if (firstLap){ firstLap=false - if (!isDaily){ + if (solo && (difficulty === "intermediate" || !isDaily)){ addToHistory("<----- ["+ intl.formatMessage({ id: 'turn' }) +" " + 1 +"/"+networkData.nodes.length + "] ----->"); } } @@ -1061,9 +1085,11 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS if(isDaily){ // TODO: verif difficulté et add les stats // TODO: verif pour facile et difficile, si réussi en one shot ou non - if(isEasy){ + if(difficulty==="easy"){ manager.userService.addEasyEnigmaStats(user.pseudo, 1, testTemps - 0.5); } + else if (difficulty === "intermediate"){ + } else{ manager.userService.addHardEnigmaStats(user.pseudo, 1, testTemps - 0.5); } @@ -1093,11 +1119,29 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS navigate(`${basePath}/endgame?solo=true&daily=${isDaily}`) } else{ - addToHistory(personTest.getName() + intl.formatMessage({ id: 'history.NotCoupable' })); - cptTour ++; // On Incrémente le nombre de tour du joueur - const tour = cptTour+1; - addToHistory("<----- ["+ intl.formatMessage({ id: 'turn' }) + " " + tour +"/"+networkData.nodes.length + "] ----->"); - changecptTour(cptTour); // On le transmet a la page précédente avec la fonction + if (isDaily){ + if (difficulty==="intermediate"){ + addToHistory(personTest.getName() + intl.formatMessage({ id: 'history.NotCoupable' })); + cptTour ++; // On Incrémente le nombre de tour du joueur + addToHistory("<----- ["+ intl.formatMessage({ id: 'turn' }) + " " + cptTour +"/"+networkData.nodes.length + "] ----->"); + changecptTour(cptTour); // On le transmet a la page précédente avec la fonction + } + else if (difficulty==="easy"){ + cptTour ++; // On Incrémente le nombre de tour du joueur + changecptTour(cptTour); // On le transmet a la page précédente avec la fonction + } + else{ + navigate(`${basePath}/endgame?solo=true&daily=true`) + setNetworkDataData(networkData) + setWinnerData(null) + } + } + else{ + addToHistory(personTest.getName() + intl.formatMessage({ id: 'history.NotCoupable' })); //TODO préciser le nombre d'indice qu'il a de juste + cptTour ++; // On Incrémente le nombre de tour du joueur + addToHistory("<----- [Tour " + cptTour +"/"+networkData.nodes.length + "] ----->"); + changecptTour(cptTour); // On le transmet a la page précédente avec la fonction + } } } } @@ -1109,7 +1153,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS setPlayerTouched(-1) } }); - }, []); // Le tableau vide signifie que cela ne s'exécutera qu'une fois après le premier rendu + }, [personNetwork]); // Le tableau vide signifie que cela ne s'exécutera qu'une fois après le premier rendu return ( <> diff --git a/cryptide_project/src/Contexts/GameContext.tsx b/cryptide_project/src/Contexts/GameContext.tsx index 9910e73..3b88ded 100644 --- a/cryptide_project/src/Contexts/GameContext.tsx +++ b/cryptide_project/src/Contexts/GameContext.tsx @@ -26,6 +26,8 @@ interface GameContextProps { networkData: any seed: number | string; nodesC: NodePerson[] + gameStart: boolean + setGameStartData : (newStart: boolean) => void setIndicesData: (newIndices: Indice[]) => void; setIndiceData: (newIndice: Indice) => void; setPersonData: (newPerson: Person) => void; @@ -37,7 +39,7 @@ interface GameContextProps { setTurnPlayerIndexData: (newTurnPlayerIndex: number) => void; setRoomData: (newRoom: string) => void; setOnlyFalseData: (newOnlyFalse: boolean) => void - setWinnerData: (winner: Player) => void + setWinnerData: (winner: Player | null) => void reset: () => void setDailyEnigmeData: (map: Map[]>) => void setNbCoupData: (newNbCoup : number) => void @@ -72,8 +74,13 @@ export const GameProvider: React.FC = ({ children }) => { const [networkData, setNetworkData] = useState(null); const [seed, setSeed] = useState(0); const [nodesC, setNodes] = useState([]); + const [gameStart, setGameStart] = useState(true) + const setGameStartData = (newStart: boolean) => { + setGameStart(newStart) + } + const setNodesData = (nodes: NodePerson[]) => { setNodes(nodes) } @@ -131,7 +138,7 @@ export const GameProvider: React.FC = ({ children }) => { setOnlyFalse(newOnlyFalse) } - const setWinnerData = (winner: Player) =>{ + const setWinnerData = (winner: Player | null) =>{ setWinner(winner) } @@ -165,7 +172,7 @@ export const GameProvider: React.FC = ({ children }) => { } return ( - + {children} ); diff --git a/cryptide_project/src/Pages/InGame.tsx b/cryptide_project/src/Pages/InGame.tsx index cc04fe5..4390433 100644 --- a/cryptide_project/src/Pages/InGame.tsx +++ b/cryptide_project/src/Pages/InGame.tsx @@ -92,11 +92,12 @@ const InGame = ({locale, changeLocale}) => { } - let isEasy: boolean = true - const isEasytmp = params.get('easy'); - if (isEasytmp == "false"){ - isEasy=false + let difficulty: string = ""; + let difficultyTmp = params.get('difficulty') + if (difficultyTmp !== null){ + difficulty=difficultyTmp } + //* Historique const [history, setHistory] = useState([]); const [showLast, setShowLast] = useState(false) @@ -107,6 +108,8 @@ const InGame = ({locale, changeLocale}) => { const [putCorrectBackground, setPutCorrectBackground] = useState<() => void>(() => {}); const [putGreyBackgroud, setPutGreyBackground] = useState<() => void>(() => {}); const [putImposssibleGrey, setPutImposssibleGrey] = useState<() => void>(() => {}); + const [changeGraph, setChangeGraph] = useState<(nbNodes: number, nbIndices: number) => void>(() => {}); + const setPutCorrectBackgroundData = (func: () => void) => { @@ -121,6 +124,10 @@ const InGame = ({locale, changeLocale}) => { setPutImposssibleGrey(func) } + const setChangeGraphData = (func: (nbNodes: number, nbIndices: number) => void) => { + setChangeGraph(func) + } + const setImportToJSONData = (imp: boolean) => { setImportToJSON(imp) } @@ -255,7 +262,7 @@ const InGame = ({locale, changeLocale}) => { const handleCloseS = () => setShowS(false); const handleShowS = () => setShowS(true); - const [cptTour, setcptTour] = useState(0); + const [cptTour, setcptTour] = useState(1); const [LastVisible, setLastVisible] = useState(false); @@ -317,6 +324,22 @@ const InGame = ({locale, changeLocale}) => { const [playTurnSound, setPlayTurnSound] = useState(false); const [soundPreference, setSoundPreference] = useState(true); // utilisateur + const [enteredNumber, setEnteredNumber] = useState(25); + const [enteredNumberIndices, setEnteredNumberIndices] = useState(3); + + + //@ts-ignore + const handleNumberChange = (event) => { + const newNumber = Math.max(20, Math.min(50, parseInt(event.target.value, 10))); + setEnteredNumber(newNumber); + }; + + //@ts-ignore + const handleNumberIndicesChange = (event) => { + const newNumber = Math.max(3, Math.min(6, parseInt(event.target.value, 10))); + setEnteredNumberIndices(newNumber); +}; + const handleSoundPreferenceChange = () => { setSoundPreference(!soundPreference); console.log("changement des options du son : "+ soundPreference) @@ -346,7 +369,7 @@ const InGame = ({locale, changeLocale}) => { addToHistory={addToHistory} solo={IsSolo} isDaily={isDaily} - isEasy={isEasy} + difficulty={difficulty} setPlayerTouched={handleSetPlayerTouched} playerTouched={playerTouched} setNetwork={setNetworkData} @@ -366,12 +389,13 @@ const InGame = ({locale, changeLocale}) => { putGreyBackground={putGreyBackgroud} putImposssibleGrey={putImposssibleGrey} handleTurn={handleTurn} - lang={locale}/> + lang={locale} + setChangeGraph={setChangeGraphData}/> {playTurnSound &&