mirror of
https://github.com/MaciejkaG/statki.git
synced 2024-11-30 00:32:55 +01:00
Minor changes
- Fixed leaving a lobby - Improved CSS compatibility/clarity - Optimised game finishing
This commit is contained in:
parent
ec036c76d7
commit
425fdc621a
32
index.js
32
index.js
@ -209,6 +209,7 @@ io.on('connection', async (socket) => {
|
|||||||
if (playerGame.data.state === 'pregame') {
|
if (playerGame.data.state === 'pregame') {
|
||||||
socket.join(playerGame.id);
|
socket.join(playerGame.id);
|
||||||
if (io.sockets.adapter.rooms.get(playerGame.id).size === 2) {
|
if (io.sockets.adapter.rooms.get(playerGame.id).size === 2) {
|
||||||
|
GInfo.resetTimer(playerGame.id);
|
||||||
io.to(playerGame.id).emit('players ready');
|
io.to(playerGame.id).emit('players ready');
|
||||||
|
|
||||||
const members = [...roomMemberIterator(playerGame.id)];
|
const members = [...roomMemberIterator(playerGame.id)];
|
||||||
@ -243,6 +244,10 @@ io.on('connection', async (socket) => {
|
|||||||
await redis.json.set(`game:${playerGame.id}`, '$.state', "preparation");
|
await redis.json.set(`game:${playerGame.id}`, '$.state', "preparation");
|
||||||
} else if (io.sockets.adapter.rooms.get(playerGame.id).size > 2) {
|
} else if (io.sockets.adapter.rooms.get(playerGame.id).size > 2) {
|
||||||
socket.disconnect();
|
socket.disconnect();
|
||||||
|
} else {
|
||||||
|
GInfo.timer(playerGame.id, 30, () => {
|
||||||
|
AFKEnd(playerGame.id);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,29 +297,14 @@ io.on('connection', async (socket) => {
|
|||||||
|
|
||||||
if (hit.gameFinished) {
|
if (hit.gameFinished) {
|
||||||
const members = [...roomMemberIterator(playerGame.id)];
|
const members = [...roomMemberIterator(playerGame.id)];
|
||||||
let hostNickname;
|
|
||||||
let guestNickname;
|
|
||||||
|
|
||||||
|
let hostSocket = io.sockets.sockets.get(members[0][0]);
|
||||||
|
let hostNickname = hostSocket.request.session.nickname;
|
||||||
|
let guestSocket = io.sockets.sockets.get(members[1][0]);
|
||||||
|
let guestNickname = guestSocket.request.session.nickname;
|
||||||
|
|
||||||
for (let i = 0; i < members.length; i++) {
|
hostSocket.emit("game finished", !enemyIdx ? 1 : 0, guestNickname);
|
||||||
const sid = members[i][0];
|
guestSocket.emit("game finished", !enemyIdx ? 1 : 0, hostNickname);
|
||||||
const socket = io.sockets.sockets.get(sid);
|
|
||||||
if (socket.request.session.id === playerGame.data.hostId) {
|
|
||||||
hostNickname = socket.request.session.nickname;
|
|
||||||
} else {
|
|
||||||
guestNickname = socket.request.session.nickname;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < members.length; i++) {
|
|
||||||
const sid = members[i][0];
|
|
||||||
const socket = io.sockets.sockets.get(sid);
|
|
||||||
if (socket.request.session.id === playerGame.data.hostId) {
|
|
||||||
io.to(sid).emit("game finished", !enemyIdx ? 1 : 0, guestNickname);
|
|
||||||
} else {
|
|
||||||
io.to(sid).emit("game finished", !enemyIdx ? 1 : 0, hostNickname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GInfo.resetTimer(playerGame.id);
|
GInfo.resetTimer(playerGame.id);
|
||||||
endGame(playerGame.id);
|
endGame(playerGame.id);
|
||||||
|
@ -244,7 +244,7 @@ h1,h2,h3,h4,h5,h6 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.cover .dialog button {
|
.cover .dialog button {
|
||||||
padding: 0.5em 3em;
|
padding: 0.5rem 2rem;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
background-color: black;
|
background-color: black;
|
||||||
border: solid 1px white;
|
border: solid 1px white;
|
||||||
@ -252,6 +252,7 @@ h1,h2,h3,h4,h5,h6 {
|
|||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
outline: none;
|
outline: none;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
transition: all 0.3s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cover .dialog button:hover {
|
.cover .dialog button:hover {
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
#mainMenuView .modes div {
|
#mainMenuView .modes div {
|
||||||
height: 10rem;
|
height: 10rem;
|
||||||
width: 10rem;
|
width: 10rem;
|
||||||
background: black;
|
background-color: black;
|
||||||
border: solid 1px white;
|
border: solid 1px white;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
@ -47,7 +47,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#mainMenuView .modes div:hover {
|
#mainMenuView .modes div:hover {
|
||||||
background: white;
|
background-color: white;
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +60,7 @@
|
|||||||
#pvpMenuView .modes div {
|
#pvpMenuView .modes div {
|
||||||
height: 10rem;
|
height: 10rem;
|
||||||
width: 10rem;
|
width: 10rem;
|
||||||
background: black;
|
background-color: black;
|
||||||
border: solid 1px white;
|
border: solid 1px white;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
@ -69,7 +69,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pvpMenuView .modes div:hover {
|
#pvpMenuView .modes div:hover {
|
||||||
background: white;
|
background-color: white;
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +82,7 @@
|
|||||||
#pvpCreateView .modes div {
|
#pvpCreateView .modes div {
|
||||||
height: 17rem;
|
height: 17rem;
|
||||||
width: 15rem;
|
width: 15rem;
|
||||||
background: black;
|
background-color: black;
|
||||||
border: solid 1px white;
|
border: solid 1px white;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
@ -93,7 +93,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pvpCreateView input, #pvpCreateView button {
|
#pvpCreateView input, #pvpCreateView button {
|
||||||
background: black;
|
background-color: black;
|
||||||
color: white;
|
color: white;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
border: 1px solid white;
|
border: 1px solid white;
|
||||||
@ -111,7 +111,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pvpCreateView button:hover {
|
#pvpCreateView button:hover {
|
||||||
background: white;
|
background-color: white;
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +124,7 @@
|
|||||||
#pvpJoinView .modes div {
|
#pvpJoinView .modes div {
|
||||||
height: 7rem;
|
height: 7rem;
|
||||||
width: 15rem;
|
width: 15rem;
|
||||||
background: black;
|
background-color: black;
|
||||||
border: solid 1px white;
|
border: solid 1px white;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
@ -138,7 +138,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pvpJoinView form input {
|
#pvpJoinView form input {
|
||||||
background: black;
|
background-color: black;
|
||||||
color: white;
|
color: white;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
border: 1px solid white;
|
border: 1px solid white;
|
||||||
@ -155,7 +155,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pvpJoinView form input[type=submit]:hover {
|
#pvpJoinView form input[type=submit]:hover {
|
||||||
background: white;
|
background-color: white;
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +168,7 @@
|
|||||||
#preparingGame .modes div {
|
#preparingGame .modes div {
|
||||||
height: 13rem;
|
height: 13rem;
|
||||||
width: 11rem;
|
width: 11rem;
|
||||||
background: black;
|
background-color: black;
|
||||||
border: solid 1px white;
|
border: solid 1px white;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
@ -63,25 +63,26 @@ $("#createGameButton").on("click", function () {
|
|||||||
|
|
||||||
$("#leaveGameButton").on("click", function () {
|
$("#leaveGameButton").on("click", function () {
|
||||||
lockUI(true);
|
lockUI(true);
|
||||||
socket.emit("leave lobby", (response) => {
|
window.location.reload();
|
||||||
switch (response.status) {
|
// socket.emit("leave lobby", (response) => {
|
||||||
case "ok":
|
// switch (response.status) {
|
||||||
switchView("mainMenuView");
|
// case "ok":
|
||||||
lockUI(false);
|
// switchView("mainMenuView");
|
||||||
break;
|
// lockUI(false);
|
||||||
|
// break;
|
||||||
|
|
||||||
case "youreNotInLobby":
|
// case "youreNotInLobby":
|
||||||
switchView("mainMenuView");
|
// switchView("mainMenuView");
|
||||||
lockUI(false);
|
// lockUI(false);
|
||||||
break;
|
// break;
|
||||||
|
|
||||||
default:
|
// default:
|
||||||
alert(`Wystąpił nieznany problem\nStatus: ${response.status}`);
|
// alert(`Wystąpił nieznany problem\nStatus: ${response.status}`);
|
||||||
switchView("mainMenuView");
|
// switchView("mainMenuView");
|
||||||
lockUI(false);
|
// lockUI(false);
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#pvpMenuButton").on("click", function () {
|
$("#pvpMenuButton").on("click", function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user