diff --git a/site/vue/index.html b/site/vue/index.html index b0aaf75..ba483a7 100644 --- a/site/vue/index.html +++ b/site/vue/index.html @@ -35,6 +35,10 @@ Personnalisé +
+ Test Nouveau Générateur + +
Caméléon @@ -508,10 +512,7 @@ diff --git a/site/vue/js/func.js b/site/vue/js/func.js index 6bdab73..462bc34 100644 --- a/site/vue/js/func.js +++ b/site/vue/js/func.js @@ -1,10 +1,10 @@ - function openModal(modalId) { var modal = document.getElementById(modalId); modal.style.display = "block"; } + function closeModal(modal) { var modal = document.getElementById(modal); modal.style.display = "none"; @@ -13,8 +13,7 @@ function closeModal(modal) { function showBarTimer(checkbox) { if (checkbox.checked == true) { document.getElementById("progress_bar").style.display = 'block'; - } - else { + } else { document.getElementById("progress_bar").style.display = 'none'; } } @@ -23,8 +22,7 @@ function darkMode() { var checkbox = document.getElementById("darkcheck"); if (checkbox.checked == true) { setColor("black"); - } - else { + } else { setColor("white"); } } @@ -32,8 +30,7 @@ function darkMode() { function symbole(checkbox) { if (checkbox.checked == true) { pathImg = "img/sym/"; - } - else { + } else { pathImg = "img/txt_en/"; } saveStage(); @@ -45,8 +42,7 @@ function dysFont() { var font; if (checkbox.checked == true) { font = "dys"; - } - else { + } else { font = "main"; } textToChange.forEach(function (item) { @@ -135,8 +131,7 @@ function setLang(newLang) { }); document.querySelector(".img_france").style.opacity = 1; document.querySelector(".img_usa").style.opacity = 0.2; - } - else { + } else { textToChange.forEach(function (item) { let currText = item.id; document.getElementById(currText).innerHTML = lang.en[currText]; @@ -145,6 +140,7 @@ function setLang(newLang) { document.querySelector(".img_usa").style.opacity = 1; } } + function calculNombreSwitch() { var entrelibre = 0; logiques.forEach(function (element) { @@ -158,6 +154,7 @@ function calculNombreSwitch() { }); numberOfSwitch = entrelibre; } + function whatIsElement(element) { if (findLogique(element.name) == null || findLogique(element.name) == undefined) { return "switch"; @@ -192,14 +189,17 @@ function changeLineColor(idLine) { var colorline = line.stroke() == colorLineActive ? colorLineInnactive : colorLineActive; line.stroke(colorline); } + function changeLineColorInput(idLine, color) { let line = stage.findOne("#" + idLine); line.stroke(color); } + function changeLineColorBlack(idLine) { let line = stage.findOne("#" + idLine); line.stroke(colorLineInnactive); } + function changeLineColorYellow(idLine) { let line = stage.findOne("#" + idLine); line.stroke(colorLineActive); @@ -260,8 +260,7 @@ function checkEntreCroisement(logiqueId) { createLink(logique1, logique); createLink(logique2, logique); - } - else if (getSwitchFromLine(logique.id1) != null && getLogiqueFromLine(logique.id2) != null) { + } else if (getSwitchFromLine(logique.id1) != null && getLogiqueFromLine(logique.id2) != null) { let logique1 = getLogiqueFromLine(logique.id2); let switch1 = getSwitchFromLine(logique.id1).id; removeLine(logique.id1); @@ -270,8 +269,7 @@ function checkEntreCroisement(logiqueId) { logique.id2 = null; createLink(logique1, logique); createLink(stage.findOne("#" + switch1), logique); - } - else if (getLogiqueFromLine(logique.id1) != null && getSwitchFromLine(logique.id2) != null) { + } else if (getLogiqueFromLine(logique.id1) != null && getSwitchFromLine(logique.id2) != null) { let logique1 = getLogiqueFromLine(logique.id1); let switch1 = getSwitchFromLine(logique.id2).id; removeLine(logique.id1); @@ -280,8 +278,7 @@ function checkEntreCroisement(logiqueId) { logique.id2 = null; createLink(stage.findOne("#" + switch1), logique); createLink(logique1, logique); - } - else { + } else { croisement = true; } @@ -337,8 +334,7 @@ function checkSortieLogique(logiqueId) { element.id3.forEach(function (line) { changeLineColorYellow(line); }); - } - else { + } else { element.id3.forEach(function (line) { changeLineColorBlack(line); }); @@ -349,8 +345,7 @@ function checkSortieLogique(logiqueId) { element.id3.forEach(function (line) { changeLineColorYellow(line); }); - } - else { + } else { element.id3.forEach(function (line) { changeLineColorBlack(line); }); @@ -361,8 +356,7 @@ function checkSortieLogique(logiqueId) { element.id3.forEach(function (line) { changeLineColorYellow(line); }); - } - else { + } else { element.id3.forEach(function (line) { changeLineColorBlack(line); }); @@ -373,8 +367,7 @@ function checkSortieLogique(logiqueId) { element.id3.forEach(function (line) { changeLineColorBlack(line); }); - } - else { + } else { element.id3.forEach(function (line) { changeLineColorYellow(line); }); @@ -467,7 +460,9 @@ function checkEnd(mode) { } }); if (ter && !isTuto) { - setTimeout(() => { success(mode); }, 100); + setTimeout(() => { + success(mode); + }, 100); } } @@ -479,7 +474,10 @@ function success(mode) { if (successPanel) { openModal("success"); document.querySelector("#click_number").innerHTML = click; - document.querySelector("#next_level_button").onclick = function () { closeModal('success'); nextLevel(mode); } + document.querySelector("#next_level_button").onclick = function () { + closeModal('success'); + nextLevel(mode); + } var previewStage = new Konva.Stage({ container: 'show_stage', width: window.innerWidth / 1.5, @@ -487,11 +485,15 @@ function success(mode) { scaleX: 1 / 1.5, scaleY: 1 / 1.5 }); - let previewLayer = layer.clone({ hitGraphEnabled: false }); + let previewLayer = layer.clone({ + hitGraphEnabled: false + }); previewStage.add(previewLayer); previewLayer.batchDraw(); } else { - setTimeout(() => { nextLevel(mode); }, 1000); + setTimeout(() => { + nextLevel(mode); + }, 1000); } } @@ -526,22 +528,29 @@ function calculNombreSwitch() { function resize() { - stage.scale({ x: 1, y: 1 }); + stage.scale({ + x: 1, + y: 1 + }); stage.draw(); } function activeSwitchInput(event) { changeAllSwitchColorActive(event.target.value); } + function inactiveSwitchInput(event) { changeAllSwitchColorInActive(event.target.value); } + function activeLineInput(event) { changeAllLineColorActive(event.target.value); } + function inactiveLineInput(event) { changeAllLineColorInActive(event.target.value); } + function inactiveEndInput(event) { changeEndColorInActive(event.target.value); } @@ -562,11 +571,13 @@ function changeAllSwitchColorActive(color) { colorSwitchActiveBackground = color; layer.draw(); } + function changeEndColorInActive(color) { colorEnd = color; stage.findOne("#end").fill(color); layer.draw(); } + function changeAllSwitchColorInActive(color) { switchsInfoCopy.forEach(function (element) { var switche = stage.findOne("#" + element.id); @@ -594,6 +605,7 @@ function changeAllLineColorActive(color) { colorLineActive = color; layer.draw(); } + function changeAllLineColorInActive(color) { var line1 = stage.findOne("#line2"); var line2 = stage.findOne("#line3"); @@ -610,9 +622,11 @@ function changeAllLineColorInActive(color) { colorLineInnactive = color; layer.draw(); } + function hideDiv(div) { div.style.display = 'none'; } + function showDiv(div) { if (div.id == "levelSelectionPage") { document.querySelectorAll("#right_select").forEach(function (element) { @@ -626,11 +640,13 @@ function play() { hideDiv(document.querySelector("#mainPage")); showDiv(document.querySelector("#levelSelectionPage")); } + function modePerso() { document.querySelector("#generate_button_perso").childNodes[3].classList = "fa fa-arrow-right"; hideDiv(document.querySelector("#levelSelectionPage")); showDiv(document.querySelector("#PersoSetupPage")); } + function playNormal() { hideDiv(document.querySelector("#levelSelectionPage")); showDiv(document.querySelector("#playPage")); @@ -638,6 +654,7 @@ function playNormal() { timeTot = 0; launchGameOne(); } + function modeTuto() { hideDiv(document.querySelector("#levelSelectionPage")); showDiv(document.querySelector("#playPage")); @@ -645,6 +662,15 @@ function modeTuto() { timeTot = 0; launchTuto(); } + +function modeTest() { + hideDiv(document.querySelector("#levelSelectionPage")); + showDiv(document.querySelector("#playPage")); + niveauActuel = 1; + timeTot = 0; + launchTest(); +} + function wait(mode, btn) { var time = 300; spin(btn); @@ -658,6 +684,9 @@ function wait(mode, btn) { case "tuto": setTimeout(modeTuto, time); break; + case "test": + setTimeout(modeTest, time); + break; } } @@ -685,6 +714,7 @@ function colonne_check_setup(value) { } refresh_input(); } + function refresh_input() { document.querySelector("#colonne_number_setup_global").value = "0"; document.querySelectorAll(".input_refresh").forEach(function (element) { @@ -718,6 +748,7 @@ function launchGameOne() { resetAllTabs(false); gameOne(); } + function launchTuto() { document.querySelector(".niveau").innerHTML = niveauActuel; timer.stop(); @@ -726,6 +757,14 @@ function launchTuto() { tuto(); } +function launchTest() { + document.querySelector(".niveau").innerHTML = niveauActuel; + timer.stop(); + timer.reset(); + resetAllTabs(false); + generate2(); +} + function clearArray(arr) { while (arr.length > 0) { arr.pop(); @@ -745,11 +784,13 @@ function closeSelection() { showDiv(document.querySelector("#mainPage")); hideDiv(document.querySelector("#levelSelectionPage")); } + function closePerso() { showDiv(document.querySelector("#levelSelectionPage")); hideDiv(document.querySelector("#PersoSetupPage")); } var rotated = false; + function flip() { document.querySelectorAll(".fa").forEach(function (element) { deg = rotated ? 0 : 360; diff --git a/site/vue/js/generateGame.js b/site/vue/js/generateGame.js index a5e1e6b..108e07a 100644 --- a/site/vue/js/generateGame.js +++ b/site/vue/js/generateGame.js @@ -31,6 +31,7 @@ function generate_perso_level() { createLinkAuto(element.name); }); initEndGame(); + timer.stop(); } @@ -38,7 +39,13 @@ function generate_perso_level() { function loadPerso() { - arrayPorte = [[document.querySelector("#logique1").checked, "et"], [document.querySelector("#logique2").checked, "ou"], [document.querySelector("#logique3").checked, "inv"], [document.querySelector("#logique4").checked, "etnon"], [document.querySelector("#logique5").checked, "nonou"]]; + arrayPorte = [ + [document.querySelector("#logique1").checked, "et"], + [document.querySelector("#logique2").checked, "ou"], + [document.querySelector("#logique3").checked, "inv"], + [document.querySelector("#logique4").checked, "etnon"], + [document.querySelector("#logique5").checked, "nonou"] + ]; document.querySelector("#PersoSetupPage").style.display = 'none'; document.querySelector("#playPage").style.display = 'block'; resetAllTabs(false); @@ -63,7 +70,9 @@ function loadPerso() { numberPerColonne.push(parseInt(element.value)); }); } - arrayPorte = arrayPorte.filter(function (e) { if (e[0] === true) return e; }) + arrayPorte = arrayPorte.filter(function (e) { + if (e[0] === true) return e; + }) generate_perso_level(); isLineCollapsing() click = 0; @@ -82,13 +91,17 @@ function loadPerso() { if (error) { document.location.reload(true); } + } + function spin(button) { button.childNodes[3].classList = "fa fa-spinner"; } + function stopspin(button) { button.childNodes[3].classList = "fa fa-arrow-right"; } + function buttonSpin(button) { spin(document.querySelector("#generate_button_perso")); setTimeout(loadPerso, 1000); @@ -181,7 +194,7 @@ function createGameOne(niveau) { numberColonne2 = 1; timeEnd = 20; break; - //Fin premiere serie + //Fin premiere serie case 5: firstTime.push("inv"); isNotAllowed = true; @@ -301,19 +314,33 @@ function createGameOne(niveau) { function generate2() { - var matchs = [[3, 2], [2, 2]]; - var fork = [[2, 1], [1, 1]]; + var matchs = [ + [3, 2], + [2, 2] + ]; + var fork = [ + [2, 1], + [1, 1] + ]; + var numberCol = 3; var numberPerCol = [5, 3, 2]; + + colonneTot = 3; + numberPerColonne = [5, 3, 2]; var compt = new Array(); + var listeSame = []; + let num = 1; + //attribution for (let i = numberCol; i > 0; i--) { - let num = 1; + matchs.forEach(function (element) { if (element[0] == i) { for (let j = 0; j < element[1]; j++) { compt.push([i, "same" + num]); numberPerCol[i - 1]--; + listeSame.push(["same" + num, null]); } num++; } @@ -334,7 +361,6 @@ function generate2() { id2: null, id3: null, matchId1: null, - matchId2: null, type: null, }); } else { @@ -345,13 +371,71 @@ function generate2() { id2: null, id3: null, matchId1: element[1], - matchId2: null, type: null, }); } i++; }); - console.log(listeLogiqueObj); + //Attribution des types + //num = liste de comptatibilité + + let num2 = getRandomArbitrary(0, 3); + for (x in compt) { + if (listeLogiqueObj[x].matchId1 !== null) { + if (getElementArray(listeLogiqueObj[x].matchId1, listeSame)[1] === null) { + getElementArray(listeLogiqueObj[x].matchId1, listeSame)[1] = num2; + num2 = getRandomArbitrary(0, 3); + } else { + listeSame[x] = getElementArray(listeLogiqueObj[x].matchId1, listeSame); + } + } + } + createStage("play_container"); + stage.add(layer); + timeEnd = 1000; + + for (let i = 0; i < colonneTot; i++) { + liveColonneNumber.push([]); + } + initTimer(); + //creation logique + listeLogiqueObj.forEach(function (logique) { + if (getTypeFromSameMatch(listeSame, logique.matchId1) === null) logique.type = getRandomArbitrary(0, 3); + else logique.type = getTypeFromSameMatch(listeSame, logique.matchId1); + switch (logique.type) { + case 0: + console.log(logique.id + " type : " + logique.type + " col : " + logique.col); + insertLogiqueColonne(logique.id, "et", logique.col - 1); + break; + case 1: + console.log(logique.id + " type : " + logique.type + " col : " + logique.col); + insertLogiqueColonne(logique.id, "ou", logique.col - 1); + break; + case 2: + console.log(logique.id + " type : " + logique.type + " col : " + logique.col); + insertLogiqueColonne(logique.id, "inv", logique.col - 1); + break; + } + }); +} + +function getElementArray(one, array) { + retour = null; + array.forEach(function (element) { + if (element[0] === one && retour === null) { + retour = element; + } + }); + return retour; +} + +function getTypeFromSameMatch(listeMatch, sameId) { + retour = null; + listeMatch.forEach(function (element) { + if (element[0] === sameId) + retour = element[1]; + }); + return retour; } @@ -359,7 +443,11 @@ function generate2() { function generateFromBottom() { var NombrecolonneTest = 2; var numberPerColonneTest = [3, 2]; - var porteBool = [[true, "et"], [true, "ou"], [true, "inv"]]; + var porteBool = [ + [true, "et"], + [true, "ou"], + [true, "inv"] + ]; var logiquesTest = []; for (let i = NombrecolonneTest; i > 0; i--) { diff --git a/site/vue/js/main.js b/site/vue/js/main.js index da10982..8598f7a 100644 --- a/site/vue/js/main.js +++ b/site/vue/js/main.js @@ -6,7 +6,14 @@ function initAll() { } var mobile = false; -var switchs = [], lineCount = [], logiques = [], lines = [], endLines = [], end, switchsInfo = [], switchsInfoCopy = [], lineRemove = []; +var switchs = [], + lineCount = [], + logiques = [], + lines = [], + endLines = [], + end, switchsInfo = [], + switchsInfoCopy = [], + lineRemove = []; var width = window.innerWidth - window.innerWidth / 100 * 30; var height = window.innerHeight / 2.5; var stage = new Konva.Stage({ @@ -114,7 +121,9 @@ function initEndGame(mode) { function resetCache() { openModal("reset_cache"); - setTimeout(() => { location.reload(); }, 3000); + setTimeout(() => { + location.reload(); + }, 3000); } window.addEventListener('resize', saveStage); @@ -174,4 +183,4 @@ function showInfo() { if (document.querySelector("#info_check_input").checked) allowedInfoPorte = false; else allowedInfoPorte = true; -} +} \ No newline at end of file