var modal = document.getElementById("myModal"); function setting() { var modal = document.getElementById("myModal"); modal.style.display = "block"; } function closeSetting() { var modal = document.getElementById("myModal"); if (event.target == modal) { modal.style.display = "none"; } } window.onclick = function (event) { closeSetting(); } function darkMode() { var checkbox = document.getElementById("darkcheck"); if (checkbox.checked == true) { setColor("black"); } else { setColor("white"); } } function dysFont() { var checkbox = document.getElementById("dyscheckbox"); var textToChange = document.querySelectorAll(".txt"); var font; if (checkbox.checked == true) { font = "dys"; } else { font = "main"; } textToChange.forEach(function (item) { let currText = item.id; document.getElementById(currText).style.fontFamily = font; }) document.getElementById("jeu-select").style.fontFamily = font; } function setColor(color) { if (color == "black") { document.body.style.color = whiteColor; document.getElementById("body").style.backgroundColor = blackColor; document.getElementById("setting_int").style.color = whiteColor; document.getElementById("setting_int").style.backgroundColor = blackColor; var hr = document.querySelectorAll("#hr"); hr.forEach(function (item) { item.setAttribute("style", "border : 3px solid " + whiteColor); }); document.querySelector(".modal-body").style.border = "5px solid" + whiteColor; } else { document.body.style.color = blackColor; document.getElementById("body").style.backgroundColor = whiteColor; document.getElementById("setting_int").style.color = blackColor; document.getElementById("setting_int").style.backgroundColor = whiteColor; var hr = document.querySelectorAll("#hr"); hr.forEach(function (item) { item.setAttribute("style", "border : 3px solid " + blackColor); }); document.querySelector(".modal-body").style.border = "5px solid" + blackColor; } } function setLang(newLang) { var textToChange = document.querySelectorAll(".txt"); if (newLang === "fr") { textToChange.forEach(function (item) { let currText = item.id; document.getElementById(currText).innerHTML = lang.fr[currText]; }) } else { textToChange.forEach(function (item) { let currText = item.id; document.getElementById(currText).innerHTML = lang.en[currText]; }) } } function calculNombreSwitch() { var entrelibre = 0; logiques.forEach(function (element) { if (element.id1 == null) { entrelibre++; } if (element.id2 == null && element.type != "inv") { entrelibre++; } }); numberOfSwitch = entrelibre; } function whatIsElement(element) { if (findLogique(element.name) == null || findLogique(element.name) == undefined) { return "switch"; } else { return "logique"; } } function setLine(logiqueElement, lineId, lineName) { logiques.forEach(function (element, index) { if (element.name === logiqueElement.name) { Object.keys(element).map(function (objectKey, index) { if (objectKey == lineId) { element[objectKey] = lineName; } }); } }); } function changeLineColor(idLine) { let line = stage.findOne("#" + idLine); var colorline = line.stroke() == colorLineActive ? colorLineInnactive : colorLineActive; line.stroke(colorline); } function changeLineColorInput(idLine,color) { let line = stage.findOne("#" + idLine); console.log("changer"); 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); } function checkAllSortieLogique() { logiques.forEach(function (element) { if (element.id3 != null) checkSortieLogique(element.name); }); } function checkSortieLogique(logiqueId) { let logique = findLogique(logiqueId); logiques.forEach(function (element, index) { if (element.name === logique.name) { let line1State, line2State; let id1Color = stage.findOne("#" + element.id1).stroke(); if (element.type !== "inv") { let id2Color = stage.findOne("#" + element.id2).stroke(); if (id2Color == colorLineInnactive) { line2State = false; } else { line2State = true; } } if (id1Color == colorLineInnactive) { line1State = false; } else { line1State = true; } switch (logique.type) { case "et": if (line1State == true && line2State == true) { changeLineColorYellow(element.id3); } else { changeLineColorBlack(element.id3); } break; case "inv": if (line1State == false) { changeLineColorYellow(element.id3); } else { changeLineColorBlack(element.id3); } break; case "ou": if (line1State == true || line2State == true) { changeLineColorYellow(element.id3); } else { changeLineColorBlack(element.id3); } break; case "nonou": if (line1State == true || line2State == true) { changeLineColorBlack(element.id3); } else { changeLineColorYellow(element.id3); } break; case "etnon": if (line1State == false && line2State == false) { changeLineColorYellow(element.id3); } else if (line1State == false && line2State == true) { changeLineColorYellow(element.id3); } else if (line1State == true && line2State == false) { changeLineColorYellow(element.id3); } else { changeLineColorBlack(element.id3); } break; } } }); } function getRandomArbitrary(min, max) { return Math.floor(Math.random() * (max - min) + min); } function isElementExisting(elementId) { if (stage.findOne("#" + elementId) != null) { return true; } return false; } function checkLineSwitch(switchId) { if (stage.findOne("#" + switchId) != null) { return true; } return false; } function checkEnd() { let ter = true; endLines.forEach(function (element) { if (stage.findOne("#line" + element).stroke() == "black") { ter = false; } }); if (ter) { setTimeout(() => { localStorage.setItem("niveau", parseInt(niveauActuel) + 1); document.location.reload(true); }, 100); } } function calculNombreSwitch() { var entrelibre = 0; logiques.forEach(function (element) { if (element.id1 == null) { entrelibre++; } if (element.id2 == null && element.type != "inv") { entrelibre++; } }); numberOfSwitch = entrelibre; } function resize() { console.log(window.innerWidth); stage.scale({ x: 1, y: 1 }); stage.draw(); console.log(stage); } 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); } document.querySelector("#active_switch_picker").addEventListener("input", activeSwitchInput, false); document.querySelector("#inactive_switch_picker").addEventListener("input", inactiveSwitchInput, false); document.querySelector("#active_line_picker").addEventListener("input", activeLineInput, false); document.querySelector("#inactive_line_picker").addEventListener("input", inactiveLineInput, false); function changeAllSwitchColorActive(color){ switchsInfoCopy.forEach(function(element){ var switche = stage.findOne("#"+element.id); if(switche.fill() == colorSwitchActiveBackground){ switche.fill(color); } }); colorSwitchActiveBackground = color; layer.draw(); } function changeAllSwitchColorInActive(color){ switchsInfoCopy.forEach(function(element){ var switche = stage.findOne("#"+element.id); if(switche.fill() == colorSwitchInnactiveBackground){ switche.fill(color); } }); colorSwitchInnactiveBackground = color; layer.draw(); } function changeAllLineColorActive(color){ var line1 = stage.findOne("#line2"); var line2 = stage.findOne("#line3"); var line3 = stage.findOne("#line4"); if(line1.stroke() === colorLineActive){ line1.stroke(color); } if(line2.stroke() === colorLineActive){ line2.stroke(color); } if(line3.stroke() === colorLineActive){ line3.stroke(color); } colorLineActive = color; layer.draw(); } function changeAllLineColorInActive(color){ var line1 = stage.findOne("#line2"); var line2 = stage.findOne("#line3"); var line3 = stage.findOne("#line4"); if(line1.stroke() === colorLineInnactive){ line1.stroke(color); } if(line2.stroke() === colorLineInnactive){ line2.stroke(color); } if(line3.stroke() === colorLineInnactive){ line3.stroke(color); } colorLineInnactive = color; layer.draw(); }