![JAR search and dependency download from the Maven repository](/logo.png)
io.github.pidoveproject.showdown.protocol.client.ChoiceResponse.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scala-showdown-api_3 Show documentation
Show all versions of scala-showdown-api_3 Show documentation
A Scala wrapper of Pokemon Showdown's API
The newest version!
package io.github.pidoveproject.showdown.protocol.client
import io.github.pidoveproject.showdown.protocol.{MessageEncoder, ProtocolError}
case class ChoiceResponse(choice: BattleChoice, requestId: Option[Int] = None)
object ChoiceResponse:
given (using choiceEncoder: MessageEncoder[BattleChoice], requestEncoder: MessageEncoder[Option[Int]]): MessageEncoder[ChoiceResponse] with
override def encode(value: ChoiceResponse): Either[ProtocolError, List[String]] =
for
encodedChoice <- choiceEncoder.encode(value.choice)
encodedRequest <- requestEncoder.encode(value.requestId)
yield
if encodedRequest.isEmpty then List(encodedChoice.mkString(" "))
else List((encodedChoice.dropRight(1) :+ s"${encodedChoice.last}|${encodedRequest.mkString}").mkString(" "))
© 2015 - 2025 Weber Informatics LLC | Privacy Policy