feat(14): update and persist scores
This commit is contained in:
@@ -97,7 +97,8 @@ object Main {
|
||||
val badge = playersChoiceBadge.copy()
|
||||
badge.p =
|
||||
Positioning.Relative // this probably should be set in enclosing html tag
|
||||
val houseChoice = Models.choiceSelectionItems(Random.nextInt(3)).copy()
|
||||
val houseChoice =
|
||||
Models.choiceSelectionItems(Random.nextInt(3)).copy()
|
||||
houseChoice.p = Positioning.Relative
|
||||
println(s"getting house choice $houseChoice")
|
||||
val showdownState = ShowdownState(badge, Some(houseChoice), false)
|
||||
@@ -109,7 +110,10 @@ object Main {
|
||||
)
|
||||
cask.Response(
|
||||
result,
|
||||
headers = Seq("Content-Type" -> "text/html;charset=UTF-8")
|
||||
headers = Seq(
|
||||
"Content-Type" -> "text/html;charset=UTF-8",
|
||||
"HX-Trigger-After-Settle" -> s"""{"updateScore": ${showdownState.scoreChange}}"""
|
||||
)
|
||||
)
|
||||
case None =>
|
||||
cask.Response(s"Unknown choice: '${playersChoice}'", 400)
|
||||
|
||||
@@ -124,5 +124,16 @@ position: absolute;
|
||||
} else "lose"
|
||||
})
|
||||
}
|
||||
def scoreChange: Int = {
|
||||
houseChoice.map(houseSelectedChoice => {
|
||||
val player = playersChoice.c
|
||||
val house = houseSelectedChoice.c
|
||||
if (player == house) {
|
||||
0
|
||||
} else if (player.isBeating(house)) {
|
||||
1
|
||||
} else -1
|
||||
}).getOrElse(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user