diff --git a/Makefile b/Makefile index 5ca07b3..94f543d 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ parcel: - npm run parcel src/player.html src/*.ts + npm run parcel src/player.html src/*.ts imgs/*.jpg uncrash: pkill -9 node diff --git a/imgs/turn.jpg b/imgs/turn.jpg index afb2105..c337e5f 100644 Binary files a/imgs/turn.jpg and b/imgs/turn.jpg differ diff --git a/src/index.ts b/src/index.ts index 508beb8..140661d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -73,6 +73,40 @@ function main() { console.log(crashes); } +function switchMessage(elm: HTMLElement, txt: string) { + + if (elm.innerText.includes("Afficher")) + elm.innerText = "Cacher " + txt; + else + elm.innerText = "Afficher " + txt; +} + +function changeDisplayed(className: string) { + const elms = document.getElementsByClassName(className); + for (let i = 0; i < elms.length; i++) { + const elm = (elms[i]); + elm.classList.toggle("hidden"); + } +} + +function switchGraphImgs() { + let imgsDisplayed = true; + + function f() { + changeDisplayed("tileImg"); + changeDisplayed("subTile"); + imgsDisplayed = !imgsDisplayed; + } + + const isImgsDisplayed = () => imgsDisplayed; + + return {switch: f, who: isImgsDisplayed}; +} + +const g = switchGraphImgs(); +const switchToGraph = g.switch; +const IsImgsDisplayed = g.who; + window.onload = ((e) => { main(); clearBoard(); @@ -80,14 +114,19 @@ window.onload = ((e) => { resizeBoard(); const showDataButton = (document.getElementById('showData')); showDataButton.addEventListener( - 'click', - () => { - (document.getElementById('jsonData')).classList.toggle("closed"); - if (showDataButton.innerText.includes("Afficher")) - showDataButton.innerText = "Cacher les données de parties"; - else - showDataButton.innerText = "Afficher les données de parties"; - }); + 'click', + () => { + (document.getElementById('jsonData')).classList.toggle("closed"); + switchMessage(showDataButton, "les données de parties"); + }); + const showImgsButton = document.getElementById("showImages"); + showImgsButton.addEventListener("click", () => { + switchToGraph(); + switchMessage(showImgsButton, "le graphe"); + } + ); + + }); -export {games, Move}; \ No newline at end of file +export {games, Move, IsImgsDisplayed, switchToGraph}; \ No newline at end of file diff --git a/src/moooove.ts b/src/moooove.ts index a60ba3b..541d82b 100644 --- a/src/moooove.ts +++ b/src/moooove.ts @@ -1,4 +1,4 @@ -import {games, Move} from "./index"; +import {games, IsImgsDisplayed, Move, switchToGraph} from "./index"; import {addColumnLeft, addColumnRight, addRowAbove, addRowUnder, clearBoard, resizeBoard} from "./Board"; let min_x = 0; @@ -121,12 +121,13 @@ function addMove(move: Move) { } -function setInnerTile(elm: HTMLElement, tile: number[]) { +function setInnerTile(elm: HTMLElement, tile: number[], angle: string, visible: boolean) { const idx_to_cord = [[1, 0], [2, 0], [3, 0], [4, 1], [4, 2], [4, 3], [3, 4], [2, 4], [1, 4], [0, 3], [0, 2], [0, 1], [2, 2]]; const nb_to_color = ["green", "gray", "blue", "#964B00", "purple", "gold", "#069AF3", "#420D08", "white", "none"]; for (let i = 0; i < 13; i++) { const subLine = elm.children[idx_to_cord[i][1]]; (subLine.children[idx_to_cord[i][0]]).style.background = nb_to_color[tile[i]]; + (subLine.children[idx_to_cord[i][0]]).classList += visible ? "" : " hidden"; } } @@ -138,10 +139,18 @@ function placeMove(move: Move) { const line = document.getElementById("line" + (-move.y - min_y)); const box = line.children[move.x - min_x]; box.style.border = "dotted 2px " + (inInterval(move.id, 0, 1) === 0 ? playerColors[move.id] : playerColors[2]); - setInnerTile(box, move.tile.c); - // box.style.rotate = move.tile.angle + "deg"; + const img = document.createElement("img"); + img.src = './imgs/' + move.tile.name + ".jpg"; + img.className = "tileImg"; + if (!IsImgsDisplayed()) + img.className += " hidden"; + box.append(img); + img.style.rotate = '-' + move.tile.angle + "deg"; + setInnerTile(box, move.tile.c, move.tile.angle, !IsImgsDisplayed()); + } +// TODO: finish remove move function removeMove(move: Move) { console.log(move.y); console.log(move.y - min_y); @@ -172,6 +181,7 @@ lastMoveButton.addEventListener("click", tolastMove); firstMoveButton.addEventListener("click", toFirstMove); function keyShortcut(e: { keyCode: number, ctrlKey: boolean, shiftKey: boolean }) { + console.log(`key ${e.keyCode} pressed`); switch (e.keyCode) { case 37: if (e.shiftKey) { @@ -195,6 +205,9 @@ function keyShortcut(e: { keyCode: number, ctrlKey: boolean, shiftKey: boolean } } nextMove(); break; + case 71: + switchToGraph(); + break; } } diff --git a/src/player.html b/src/player.html index 88b5490..1565326 100644 --- a/src/player.html +++ b/src/player.html @@ -14,20 +14,20 @@
-

Carcassonne viewer

+

Carcassonne viewer

-
+
- + @@ -63,8 +63,9 @@
-
Afficher les données de parties
-
+
Afficher les données de parties
+
Afficher le graphe
+
 [
   {
@@ -488,7 +489,7 @@
   }
 ]
 
-
+