feat(14): manual request of house choice

hodgepodge of 2 fragments which are put into house choice depending on
the state.

the alignment is done in a very not nice way.
This commit is contained in:
efim
2023-07-01 20:00:19 +00:00
parent 66013ae1c6
commit de3d4781f0
5 changed files with 176 additions and 68 deletions

View File

@@ -11,6 +11,7 @@ import scala.jdk.CollectionConverters._
import javax.swing.text.Position
import rockpaperscissors.Models.Positioning
import scala.util.Random
import rockpaperscissors.Models.ShowdownState
object Main {
@main def run(
@@ -70,8 +71,13 @@ object Main {
case Some(playersChoiceBadge) =>
val badge = playersChoiceBadge.copy()
badge.p = Positioning.Relative
context.setVariable("playersChoiceData", badge)
val result = templateEngine.process("showdown", Set("showdown-table").asJava, context)
val showdownState = ShowdownState(badge, None, false)
context.setVariable("showdownState", showdownState)
val result = templateEngine.process(
"showdown",
Set("showdown-table").asJava,
context
)
cask.Response(
result,
headers = Seq("Content-Type" -> "text/html;charset=UTF-8")
@@ -82,9 +88,37 @@ object Main {
response
}
@cask.get("/house-choice/:playersChoice")
def requestHouseChoice(playersChoice: String) = {
val context = new Context()
val badge = Models.choiceSelectionItems.find(_.c.name == playersChoice)
val response = badge match {
case Some(playersChoiceBadge) =>
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()
houseChoice.p = Positioning.Relative
println(s"getting house choice $houseChoice")
val showdownState = ShowdownState(badge, Some(houseChoice), false)
context.setVariable("showdownState", showdownState)
val result = templateEngine.process(
"showdown",
Set("showdown-table").asJava,
context
)
cask.Response(
result,
headers = Seq("Content-Type" -> "text/html;charset=UTF-8")
)
case None =>
cask.Response(s"Unknown choice: '${playersChoice}'", 400)
}
response
}
@cask.staticResources("/public")
def publicFiles(req: cask.Request) = {
println(s"getting request for ${req.remainingPathSegments}")
"public"
}

View File

@@ -83,4 +83,9 @@ position: absolute;
)
}
final case class ShowdownState(
var playersChoice: ChoiceBadge,
var houseChoice: Option[ChoiceBadge],
var gameEnded: Boolean
)
}