addede images display + button to switch to grap view

This commit is contained in:
Pierre Tellier 2024-04-22 22:35:50 +02:00
parent 3c93dc9d42
commit 171f073d63
6 changed files with 85 additions and 20 deletions

View File

@ -1,5 +1,5 @@
parcel: parcel:
npm run parcel src/player.html src/*.ts npm run parcel src/player.html src/*.ts imgs/*.jpg
uncrash: uncrash:
pkill -9 node pkill -9 node

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 53 KiB

View File

@ -73,6 +73,40 @@ function main() {
console.log(crashes); 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 = <HTMLElement>(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) => { window.onload = ((e) => {
main(); main();
clearBoard(); clearBoard();
@ -80,14 +114,19 @@ window.onload = ((e) => {
resizeBoard(); resizeBoard();
const showDataButton = (<HTMLElement>document.getElementById('showData')); const showDataButton = (<HTMLElement>document.getElementById('showData'));
showDataButton.addEventListener( showDataButton.addEventListener(
'click', 'click',
() => { () => {
(<HTMLElement>document.getElementById('jsonData')).classList.toggle("closed"); (<HTMLElement>document.getElementById('jsonData')).classList.toggle("closed");
if (showDataButton.innerText.includes("Afficher")) switchMessage(showDataButton, "les données de parties");
showDataButton.innerText = "Cacher les données de parties"; });
else const showImgsButton = <HTMLElement>document.getElementById("showImages");
showDataButton.innerText = "Afficher les données de parties"; showImgsButton.addEventListener("click", () => {
}); switchToGraph();
switchMessage(showImgsButton, "le graphe");
}
);
}); });
export {games, Move}; export {games, Move, IsImgsDisplayed, switchToGraph};

View File

@ -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"; import {addColumnLeft, addColumnRight, addRowAbove, addRowUnder, clearBoard, resizeBoard} from "./Board";
let min_x = 0; 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 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"]; const nb_to_color = ["green", "gray", "blue", "#964B00", "purple", "gold", "#069AF3", "#420D08", "white", "none"];
for (let i = 0; i < 13; i++) { for (let i = 0; i < 13; i++) {
const subLine = elm.children[idx_to_cord[i][1]]; const subLine = elm.children[idx_to_cord[i][1]];
(<HTMLElement>subLine.children[idx_to_cord[i][0]]).style.background = nb_to_color[tile[i]]; (<HTMLElement>subLine.children[idx_to_cord[i][0]]).style.background = nb_to_color[tile[i]];
(<HTMLElement>subLine.children[idx_to_cord[i][0]]).classList += visible ? "" : " hidden";
} }
} }
@ -138,10 +139,18 @@ function placeMove(move: Move) {
const line = <HTMLElement>document.getElementById("line" + (-move.y - min_y)); const line = <HTMLElement>document.getElementById("line" + (-move.y - min_y));
const box = <HTMLElement>line.children[move.x - min_x]; const box = <HTMLElement>line.children[move.x - min_x];
box.style.border = "dotted 2px " + (inInterval(move.id, 0, 1) === 0 ? playerColors[move.id] : playerColors[2]); box.style.border = "dotted 2px " + (inInterval(move.id, 0, 1) === 0 ? playerColors[move.id] : playerColors[2]);
setInnerTile(box, move.tile.c); const img = document.createElement("img");
// box.style.rotate = move.tile.angle + "deg"; 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) { function removeMove(move: Move) {
console.log(move.y); console.log(move.y);
console.log(move.y - min_y); console.log(move.y - min_y);
@ -172,6 +181,7 @@ lastMoveButton.addEventListener("click", tolastMove);
firstMoveButton.addEventListener("click", toFirstMove); firstMoveButton.addEventListener("click", toFirstMove);
function keyShortcut(e: { keyCode: number, ctrlKey: boolean, shiftKey: boolean }) { function keyShortcut(e: { keyCode: number, ctrlKey: boolean, shiftKey: boolean }) {
console.log(`key ${e.keyCode} pressed`);
switch (e.keyCode) { switch (e.keyCode) {
case 37: case 37:
if (e.shiftKey) { if (e.shiftKey) {
@ -195,6 +205,9 @@ function keyShortcut(e: { keyCode: number, ctrlKey: boolean, shiftKey: boolean }
} }
nextMove(); nextMove();
break; break;
case 71:
switchToGraph();
break;
} }
} }

View File

@ -14,20 +14,20 @@
<body> <body>
<div> <div>
<h1 id="title" class="text-center">Carcassonne viewer</h1> <h1 id="title" class="text-center">Carcassonne viewer</h1>
</div> </div>
<div id="games"> <div id="games">
<div id="board" class="board"> <div id="board" class="board">
</div> </div>
</div> </div>
<div class="header"> <div class="header">
<div class="row"> <div class="row">
<div class="container"> <div class="container">
<div class="row viewer_controls"> <div class="row viewer_controls">
<div class="btn-group " role="group" aria-label="Basic example"> <div class="btn-group " role="group" aria-label="Basic example">
<button type="button" class="btn btn-secondary" id="prevGameButton">|&lt;<&lt;</button> <button type="button" class="btn btn-secondary" id="prevGameButton">|&lt;<&lt;</button>
<button type="button" class="btn btn-secondary" id="firstMoveButton">|&lt;&lt;</button> <button type="button" class="btn btn-secondary" id="firstMoveButton">|&lt;&lt;</button>
<button type="button" class="btn btn-secondary" id="prevMoveButton">&lt;</button> <button type="button" class="btn btn-secondary" id="prevMoveButton">&lt;</button>
<button type="button" class="btn btn-secondary" id="nextMoveButton">&gt;</button> <button type="button" class="btn btn-secondary" id="nextMoveButton">&gt;</button>
@ -63,8 +63,9 @@
</div> </div>
</div> </div>
<div id="data"> <div id="data">
<div class="button interactable" id="showData">Afficher les données de parties</div> <div class="button interactable" id="showData">Afficher les données de parties</div>
<div class="closed" id="jsonData"> <div class="button interactable" id="showImages">Afficher le graphe</div>
<div class="closed" id="jsonData">
<pre> <pre>
[ [
{ {
@ -488,7 +489,7 @@
} }
] ]
</pre> </pre>
</div> </div>
</div> </div>
<div id="error_box" style="display: none"> <div id="error_box" style="display: none">

View File

@ -66,6 +66,7 @@ body {
.subTile { .subTile {
width: 20%; width: 20%;
height: 100%; height: 100%;
z-index: 1;
} }
.button { .button {
@ -97,3 +98,14 @@ body {
.closed#jsonData { .closed#jsonData {
font-size: 0 !important; font-size: 0 !important;
} }
.tileImg {
width: 100%;
height: 100%;
z-index: 0;
margin-top: -100%;
}
.hidden {
opacity: 0;
}