Skip to content

Commit

Permalink
Новые фичи в вебе
Browse files Browse the repository at this point in the history
  • Loading branch information
Штенгауэр Никита Дмитриевич committed Oct 31, 2023
1 parent 35b50a1 commit f884cbe
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 10 deletions.
51 changes: 45 additions & 6 deletions MyOwnGame.Frontend/pages/lobby/lobby.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ function addPlayer(player){
`;
}
profilePane.querySelector(".player-image").style.backgroundImage = `url('${imageUrl}')`;
profilePane.querySelector(".player-name").innerHTML = player.name;
profilePane.querySelector(".player-score").innerHTML = player.score;
profilePane.querySelector(".player-name").innerHTML = player.name;;
const scoreElement = profilePane.querySelector(".player-score")
scoreElement.innerHTML = player.score;
scoreElement.addEventListener("click", () => editPlayerScore(session.players.find(a => a.id == player.id)));

if(player.isDisconnected)
setPlayerOffline(player);
Expand Down Expand Up @@ -112,9 +114,18 @@ function setRound(roundInfo){
`;

theme.prices.forEach((price, r) => {
themePanel.innerHTML += `
<div class="price ${price.isAnswered ? "answered" : ""}" id="price-${r}" onclick="requestPrice(${i}, ${r})">${roundInfo.isFinal ? "удалить" : price.price}</div>
`;
const button = document.createElement("div");
button.id = `price-${r}`;
button.classList.add("price");
button.classList.toggle("answered", price.isAnswered);
button.addEventListener("click", () => {
if(roundInfo.isFinal)
requestRemoveTheme(i);
else if(!price.isAnswered)
requestPrice(i, r)
});
button.textContent = roundInfo.isFinal ? "удалить" : price.price;
themePanel.appendChild(button);
});
});

Expand Down Expand Up @@ -178,6 +189,16 @@ function skipQuestion(answer) {
showAnswer(answer);
}

function updateScore(player, score){
updatePlayers();
}

function finalThemeRemoved(themes){
setRound({
themes: themes
});
}

/*
======================
Functions
Expand Down Expand Up @@ -206,7 +227,12 @@ function updatePlayers() {
if(profilePane){
profilePane.querySelector(".player-image").style.backgroundImage = `url('${imageUrl}')`;
profilePane.querySelector(".player-name").innerHTML = player.name;
profilePane.querySelector(".player-score").innerHTML = player.score;
const scoreElement = profilePane.querySelector(".player-score");
if(scoreElement.textContent != player.score){
scoreElement.classList.add("changed");
setTimeout(() => scoreElement.classList.remove("changed"), 1000);
}
scoreElement.innerHTML = player.score;
}

if(session.respondingPlayer &&
Expand Down Expand Up @@ -255,6 +281,11 @@ function requestAnswer(){
connection.invoke("ReadyToAnswer", new Date().toISOString());
}

function requestRemoveTheme(themeId){
console.log(`Removing theme: ${themeId}`);
connection.invoke("RemoveFinalTheme", parseInt(themeId));
}

function setVolume(volume){
window.music.volume = volume / 100;
}
Expand Down Expand Up @@ -322,4 +353,12 @@ function showAnswer(answer) {
showContent(null, null);
});
updatePlayers();
}

function editPlayerScore(player){
if(session.players.find(a => a.id == userId).isAdmin){
const newScore = prompt("Введите новый счет", player.score);
if(newScore)
connection.invoke("SetScore", player.id, parseInt(newScore));
}
}
20 changes: 17 additions & 3 deletions MyOwnGame.Frontend/pages/lobby/lobby.scss
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
color: rgba(120, 120, 120, 1.0);
}

.can-choose-price &:hover{
.can-choose-price &:hover:not(.answered){
background: rgba(240, 240, 240, 1);
cursor: pointer;
}
Expand Down Expand Up @@ -309,9 +309,9 @@
background: rgba(240, 240, 240, 1);
border-radius: 10px;
box-shadow: 0 0 2px 3px rgba(0, 0, 0, 0.2);
z-index: 1;

.player-image {
background: url("http://fooxboy.ru:3000/avatars/78afb4bd-1ff8-4d81-8975-715cdc5884fe.png");
background-size: cover;
border-radius: 999px;

Expand Down Expand Up @@ -339,7 +339,6 @@
border-radius: 0 0 10px 10px;
margin-top: -10px;
padding-top: 10px;
z-index: -1;

height: 45px;
font-family: segments;
Expand All @@ -350,6 +349,21 @@
border: 2px solid rgba(0, 80, 0, 1);

box-sizing: border-box;
user-select: none;

&.changed {
animation: 0.5s ease selectedAnimation;
}

@keyframes selectedAnimation {
50% {
font-size: 17pt;
color: lightgreen;
}
100% {
font-size: 12pt;
}
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion MyOwnGame.Frontend/scripts/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ async function connectToSession(sessionId){
connection.on("AcceptAnswer", (player, score, answer) => acceptAnswer(player, score, answer));
connection.on("RejectAnswer", (player, score, answer) => rejectAnswer(player, score, answer));
connection.on("SkipQuestion", answer => skipQuestion(answer));

connection.on("ScoreChanged", (player, score) => updateScore(player, score));
connection.on("FinalThemeRemoved", (themes) => finalThemeRemoved(themes));

session["id"] = sessionId;
setCookie("last-session", sessionId);
Expand Down

0 comments on commit f884cbe

Please sign in to comment.