Compare commits

...

2 Commits
4.1.0 ... 4.2.0

Author SHA1 Message Date
TeamCity
576e5af87e ci: bump version to v4.2.0 2025-11-26 12:37:57 +00:00
3c0828fdbe feat(api): Implemented card played event via websocket (#85)
Reviewed-on: #85
Reviewed-by: lq64 <lq@blackhole.local>
Co-authored-by: Janis <janis.e.20@gmx.de>
Co-committed-by: Janis <janis.e.20@gmx.de>
2025-11-26 13:35:05 +01:00
6 changed files with 69 additions and 4 deletions

View File

@@ -149,3 +149,8 @@
* **api:** Implement received hand event handling and UI updates ([#83](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/83)) ([52e5033](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/52e5033afca344ae40a644196555a9655913710a)), closes [#76](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/76)
* **base:** Fixed logic for websockets and added GameStateEvent. Might've caused instability on other feature branches! ([#84](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/84)) ([b81bb3d](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/b81bb3d0aeb8500a9d7417a10e24e7f8a17d71d2))
## (2025-11-26)
### Features
* **api:** Implemented card played event via websocket ([#85](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/85)) ([3c0828f](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/3c0828fdbeb507706b86f1662476c46e760533e4))

View File

@@ -6,7 +6,7 @@ import model.sessions.UserSession
import play.api.libs.json.{JsValue, Json}
import tools.jackson.databind.json.JsonMapper
import tools.jackson.module.scala.ScalaModule
import util.mapper.{GameStateEventMapper, ReceivedHandEventMapper, SimpleEventMapper}
import util.mapper.{CardPlayedEventMapper, GameStateEventMapper, ReceivedHandEventMapper, SimpleEventMapper}
object WebsocketEventMapper {
@@ -26,6 +26,7 @@ object WebsocketEventMapper {
// Register all custom mappers here
registerCustomMapper(ReceivedHandEventMapper)
registerCustomMapper(GameStateEventMapper)
registerCustomMapper(CardPlayedEventMapper)
def toJson(obj: SimpleEvent, session: UserSession): JsValue = {
val data: Option[JsValue] = if (customMappers.contains(obj.id)) {

View File

@@ -0,0 +1,20 @@
package util.mapper
import de.knockoutwhist.events.global.CardPlayedEvent
import model.sessions.UserSession
import play.api.libs.json.{JsArray, JsObject, Json}
import util.WebUIUtils
object CardPlayedEventMapper extends SimpleEventMapper[CardPlayedEvent]{
override def id: String = "CardPlayedEvent"
override def toJson(event: CardPlayedEvent, session: UserSession): JsObject = {
Json.obj(
"firstCard" -> (if (event.trick.firstCard.isDefined) WebUIUtils.cardtoString(event.trick.firstCard.get) else "BLANK"),
"playedCards" -> JsArray(event.trick.cards.map { case (card, player) =>
Json.obj("cardId" -> WebUIUtils.cardtoString(card), "player" -> player.name)
}.toList)
)
}
}

View File

@@ -45,6 +45,45 @@ function receiveGameStateChange(eventData) {
exchangeBody(content, title);
}
function receiveCardPlayedEvent(eventData) {
const firstCard = eventData.firstCard;
const playedCards = eventData.playedCards;
const trickCardsContainer = $('#trick-cards-container');
const firstCardContainer = $('#first-card-container')
let trickHTML = '';
playedCards.forEach(cardCombo => {
trickHTML += `
<div class="col-auto">
<div class="card text-center shadow-sm border-0 bg-transparent" style="width: 7rem; backdrop-filter: blur(4px);">
<div class="p-2">
<img src="/assets/images/cards/${cardCombo.cardId}.png" width="100%" alt="${cardCombo.cardId}"/>
</div>
<div class="card-body p-2 bg-transparent">
<small class="fw-semibold text-secondary">${cardCombo.player}</small>
</div>
</div>
</div>
`;
});
trickCardsContainer.html(trickHTML);
let altText;
let imageSrc;
if (firstCard === "BLANK") {
imageSrc = "/assets/images/cards/1B.png";
altText = "Blank Card";
} else {
imageSrc = `/assets/images/cards/${firstCard}.png`;
altText = `Card ${firstCard}`;
}
const newFirstCardHTML = `
<img src="${imageSrc}" alt="${altText}" width="80px" style="border-radius: 6px"/>
`;
firstCardContainer.html(newFirstCardHTML);
}
onEvent("ReceivedHandEvent", receiveHandEvent)
onEvent("GameStateChangeEvent", receiveGameStateChange)
onEvent("GameStateChangeEvent", receiveGameStateChange)
onEvent("CardPlayedEvent", receiveCardPlayedEvent)

View File

@@ -1,3 +1,3 @@
MAJOR=4
MINOR=1
MINOR=2
PATCH=0