diff --git a/public/assets/css/board-responsive.css b/public/assets/css/board-responsive.css new file mode 100644 index 0000000..467582d --- /dev/null +++ b/public/assets/css/board-responsive.css @@ -0,0 +1,19 @@ +@media only screen and (max-width: 1280px) { + +} + +@media only screen and (max-width: 820px) { + .boardContainer { + width: 90vw; + aspect-ratio: 1; + } + + .panelContainer { + flex-direction: column-reverse; + } + + .field { + width: 7.5vw; /* still need to test that */ + } +} + diff --git a/public/assets/css/board.css b/public/assets/css/board.css index 617b805..0453828 100644 --- a/public/assets/css/board.css +++ b/public/assets/css/board.css @@ -284,4 +284,8 @@ h1,h2,h3,h4,h5,h6 { #timer.active { animation: timerDanger 1s infinite ease; +} + +.tippyTemplate { + display: none; } \ No newline at end of file diff --git a/public/assets/css/main.css b/public/assets/css/main.css index 5579742..3a16b84 100644 --- a/public/assets/css/main.css +++ b/public/assets/css/main.css @@ -228,6 +228,8 @@ nav span:hover { align-items: center; width: 45vw; justify-content: space-between; + + gap: 1rem; } #profileView .stats { @@ -315,4 +317,8 @@ nav span:hover { #profileView .periodal .stat h1 { margin: 0.5rem; +} + +.tippyTemplate { + display: none; } \ No newline at end of file diff --git a/public/assets/js/socket-game.js b/public/assets/js/socket-game.js index e06d4d0..ee48807 100644 --- a/public/assets/js/socket-game.js +++ b/public/assets/js/socket-game.js @@ -7,14 +7,34 @@ var occupiedFields = []; var lastTimeClick = 0; +tippy('#board .field', { + allowHTML: true, + placement: "top", + theme: "translucent", + animation: "shift-toward-subtle", + interactive: true, + content: (reference) => { + let fieldData = `${$(reference).data('pos-x') }, ${$(reference).data('pos-y') }`; + + return $('#mainTippyTemplate').html().replaceAll("[[FIELDPOS]]", fieldData); + }, +}); + $('#board .field').on('click', function () { - console.log(new Date().getTime() / 1000 - lastTimeClick); if (new Date().getTime() / 1000 - lastTimeClick > 0.3) { - socket.emit("place ship", selectedShip, $(this).data('pos-x'), $(this).data('pos-y'), shipRotation); - lastTimeClick = new Date().getTime() / 1000; + if ($(window).width() > 820) { + socket.emit("place ship", selectedShip, $(this).data('pos-x'), $(this).data('pos-y'), shipRotation); + lastTimeClick = new Date().getTime() / 1000; + } // else { + // } } }); +function manualPlace(posX, posY) { + // console.log(args); + socket.emit("place ship", selectedShip, posX, posY, shipRotation); +} + $('#secondaryBoard .field').on('click', function () { if (new Date().getTime() / 1000 - lastTimeClick > 0.3) { socket.emit("shoot", $(this).data('pos-x'), $(this).data('pos-y')); diff --git a/public/assets/js/socket.js b/public/assets/js/socket.js index 4755bb7..3b76f7c 100644 --- a/public/assets/js/socket.js +++ b/public/assets/js/socket.js @@ -2,6 +2,7 @@ const socket = io(); // Handling server-sent events socket.on("joined", (nick) => { + returnLock = false; lockUI(true); $("#oppNameField").html(nick); switchView("preparingGame"); @@ -21,7 +22,6 @@ socket.on("gameReady", (gameId) => { }); var nickname; -var myProfile; socket.emit("my profile", (profile) => { // General profile data @@ -32,7 +32,7 @@ socket.emit("my profile", (profile) => { // Profile stats $("#monthlyPlayed").html(profile.stats.monthly_matches); $("#totalPlayed").html(profile.stats.alltime_matches); - $("#winrate").html(`${profile.stats.winrate}%`); + $("#winrate").html(profile.stats.winrate !== null ? `${profile.stats.winrate}%` : "-"); // Match history var matchHistory = profile.matchHistory; @@ -53,6 +53,10 @@ socket.emit("my profile", (profile) => { matchHistoryDOM += `