diff --git a/site/img/eee.png b/site/img/eee.png new file mode 100644 index 0000000..3307297 Binary files /dev/null and b/site/img/eee.png differ diff --git a/site/img/unnamed.jpg b/site/img/unnamed.jpg new file mode 100644 index 0000000..c97a4e9 Binary files /dev/null and b/site/img/unnamed.jpg differ diff --git a/site/js/const.js b/site/js/const.js index de2a723..2e63dd6 100644 --- a/site/js/const.js +++ b/site/js/const.js @@ -1,17 +1,19 @@ //Portes Logiques -const imageHeight = 25; +const imageHeight = 45; const imageWidth = 50; +const imageRotation = 0; //Image const pathImg = "../img/"; -const imageLogiqueEt = "logiqueet.png"; +const imageLogiqueEt = "eee.png"; const imageLogiqueOu = "logiqueou.png"; const imageEnd = "idea_white.png"; //line const colorLineInnactive = "black"; -const colorLineActive = "#f6cd61"; -const lineStroke = 1; +const colorLineActive = "#46FEFE"; +const lineStroke = 3; +const pourcentageBreak = 15; //switch const SwitchHeight = 25; diff --git a/site/js/createElement.js b/site/js/createElement.js index f774173..51968a6 100644 --- a/site/js/createElement.js +++ b/site/js/createElement.js @@ -9,11 +9,17 @@ function createEnd(x, y) { height: 50, id: "end", }); - - layer.add(end); layer.batchDraw(); }; + end = { + name: "end", + x: x, + y: y, + type: "end", + position: 1, + let:1, + } imageObj2.src = pathImg + imageEnd; } @@ -36,8 +42,11 @@ function createSwitch(id, x, y) { } function createLine(points, id) { + let startX = points[0], startY = points[1], endX = points[2], endY = points[3]; + let distance20 = (endX - startX)/100*pourcentageBreak; + let newPoints = [startX, startY,startX + distance20, startY,endX - distance20,endY,endX,endY]; let line = new Konva.Line({ - points: points, + points: newPoints, stroke: colorLineInnactive, strokeWidth: lineStroke, id: id, @@ -46,8 +55,10 @@ function createLine(points, id) { } -function createLink(entre, sortie, lineId) { +function createLink(entre, sortie) { //entre est une porte logique + lineId = lineCount.length; + lineCount.push(1); switch (whatIsElement(entre)) { case "switch": switch (whatIsElement(sortie)) { @@ -91,52 +102,46 @@ function createLink(entre, sortie, lineId) { setLine(entre, "id3", "line" + lineId); break; } + break; + default: + endLines.push(lineId); + createLine([entre.x + imageWidth, entre.y + imageHeight / 2, sortie.x, sortie.y + (imageHeight / end.position+1)*end.let], "line" + lineId); + setLine(entre, "id3", "line" + lineId); + end.let--; + break; } break; + } } function createLogique(x, y, id, type) { - - switch (type) { - case "et": - var imageObj = new Image(); - imageObj.onload = function () { - var et = new Konva.Image({ - x: x, - y: y, - image: imageObj, - width: imageWidth, - height: imageHeight, - id: id, - }); - - - layer.add(et); - layer.batchDraw(); - }; + var imageObj = new Image(); + imageObj.onload = function () { + var et = new Konva.Image({ + x: x, + y: y, + image: imageObj, + width: imageWidth, + height: imageHeight, + id: id, + }); + if (imageRotation != 0) { + et.rotation(imageRotation); + et.x(et.getX() + imageHeight); + } + layer.add(et); + layer.batchDraw(); + }; + switch(type){ + case "et" : imageObj.src = pathImg + imageLogiqueEt; - imageObj.id = id; break; case "ou": - var imageObj = new Image(); - imageObj.onload = function () { - var et = new Konva.Image({ - x: x, - y: y, - image: imageObj, - width: imageWidth, - height: imageHeight, - id: id, - }); - - - layer.add(et); - layer.batchDraw(); - }; imageObj.src = pathImg + imageLogiqueOu; - imageObj.id = id; break; } + + imageObj.id = id; diff --git a/site/js/func.js b/site/js/func.js index 8e3c991..bd58a06 100644 --- a/site/js/func.js +++ b/site/js/func.js @@ -1,5 +1,5 @@ function whatIsElement(element) { - if (findLogique(element.name) == null) { + if (findLogique(element.name) == null || findLogique(element.name) == undefined) { return "switch"; } else { return "logique"; diff --git a/site/js/init.js b/site/js/init.js index ba53bed..0aeeb0e 100644 --- a/site/js/init.js +++ b/site/js/init.js @@ -1,22 +1,38 @@ -function initAllSwitch(){ - switchs.forEach(function(element){ - let switche = stage.findOne("#"+element); - switche.on('click', function () { - let colorrect = switche.fill() == colorSwitchInnactiveBackground ? colorSwitchActiveBackground : colorSwitchInnactiveBackground; - switche.fill(colorrect); - changeLineColor(switche.id3); - checkAllSortieLogique(); - layer.draw(); - }); - switche.on('mouseover', function () { - document.body.style.cursor = "pointer"; - }); - switche.on('mouseout', function () { - document.body.style.cursor = "default"; - }); - +function initAllSwitch() { + switchs.forEach(function (element) { + let switche = stage.findOne("#" + element); + switche.on('click', function () { + let colorrect = switche.fill() == colorSwitchInnactiveBackground ? colorSwitchActiveBackground : colorSwitchInnactiveBackground; + switche.fill(colorrect); + changeLineColor(switche.id3); + checkAllSortieLogique(); + layer.draw(); + }); + switche.on('mouseover', function () { + document.body.style.cursor = "pointer"; }); - } - function initLayer() { - createEnd(500,50); - } \ No newline at end of file + switche.on('mouseout', function () { + document.body.style.cursor = "default"; + }); + + }); +} +function initLayer() { + +} + +function initEnd() { + let countLogique = 0; + logiques.forEach(function (element) { + if(element.id3 == null){ + countLogique++; + } + }); + end.position = countLogique; + end.let = countLogique; + logiques.forEach(function (element) { + if(element.id3 == null){ + createLink(element,end); + } + }); +} \ No newline at end of file diff --git a/site/vues/jeu.html b/site/vues/jeu.html index 133be3e..c16430a 100644 --- a/site/vues/jeu.html +++ b/site/vues/jeu.html @@ -28,7 +28,7 @@