Compare commits
1 Commits
4.14.0
...
webapplica
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9f7275854 |
@@ -1,13 +1,13 @@
|
|||||||
package components
|
package components
|
||||||
|
|
||||||
import de.knockoutwhist.components.DefaultConfiguration
|
import de.knockoutwhist.components.DefaultConfiguration
|
||||||
import controllers.WebUI
|
import controllers.Gamesession
|
||||||
import de.knockoutwhist.ui.UI
|
import de.knockoutwhist.ui.UI
|
||||||
import de.knockoutwhist.utils.events.EventListener
|
import de.knockoutwhist.utils.events.EventListener
|
||||||
|
|
||||||
class WebApplicationConfiguration extends DefaultConfiguration {
|
class WebApplicationConfiguration extends DefaultConfiguration {
|
||||||
|
|
||||||
override def uis: Set[UI] = super.uis + WebUI
|
override def uis: Set[UI] = super.uis + Gamesession
|
||||||
override def listener: Set[EventListener] = super.listener + WebUI
|
override def listener: Set[EventListener] = super.listener + Gamesession
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
57
knockoutwhistweb/app/controllers/Gamesession.scala
Normal file
57
knockoutwhistweb/app/controllers/Gamesession.scala
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import controllers.sessions.{AdvancedSession, PlayerSession, SimpleSession}
|
||||||
|
import de.knockoutwhist.cards.{Card, CardValue, Hand, Suit}
|
||||||
|
import de.knockoutwhist.control.GameLogic
|
||||||
|
import de.knockoutwhist.control.controllerBaseImpl.BaseGameLogic
|
||||||
|
import de.knockoutwhist.events.*
|
||||||
|
import de.knockoutwhist.events.player.{PlayCardEvent, PlayerEvent, ReceivedHandEvent, RequestTieChoiceEvent, RequestTrumpSuitEvent}
|
||||||
|
import de.knockoutwhist.player.AbstractPlayer
|
||||||
|
import de.knockoutwhist.rounds.Match
|
||||||
|
import de.knockoutwhist.ui.UI
|
||||||
|
import de.knockoutwhist.utils.CustomThread
|
||||||
|
import de.knockoutwhist.utils.events.{EventListener, SimpleEvent}
|
||||||
|
|
||||||
|
import java.util.UUID
|
||||||
|
import scala.collection.mutable
|
||||||
|
|
||||||
|
class Gamesession(id: UUID) extends CustomThread with EventListener with UI {
|
||||||
|
|
||||||
|
setName("Gamesession")
|
||||||
|
private val sessions: mutable.Map[UUID, PlayerSession] = mutable.Map()
|
||||||
|
var init = false
|
||||||
|
var logic: Option[GameLogic] = None
|
||||||
|
override def instance: CustomThread = this
|
||||||
|
|
||||||
|
override def listen(event: SimpleEvent): Unit = {
|
||||||
|
runLater {
|
||||||
|
event match {
|
||||||
|
case event: PlayCardEvent =>
|
||||||
|
PodGameManager.transmit(event.player.id, event)
|
||||||
|
case event: ReceivedHandEvent =>
|
||||||
|
PodGameManager.transmit(event.player.id, event)
|
||||||
|
case event: RequestTieChoiceEvent =>
|
||||||
|
PodGameManager.transmit(event.player.id, event)
|
||||||
|
case event: RequestTrumpSuitEvent =>
|
||||||
|
PodGameManager.transmit(event.player.id, event)
|
||||||
|
case _ =>
|
||||||
|
PodGameManager.transmitAll(event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override def initial(gameLogic: GameLogic): Boolean = {
|
||||||
|
if (init) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
this.logic = Some(gameLogic)
|
||||||
|
init = true
|
||||||
|
start()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
def addSession(session: PlayerSession): Unit = {
|
||||||
|
sessions.put(session.id, session)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import controllers.sessions.SimpleSession
|
import controllers.sessions.SimpleSession
|
||||||
|
import controllers.sessions.AdvancedSession
|
||||||
import com.google.inject.{Guice, Injector}
|
import com.google.inject.{Guice, Injector}
|
||||||
import de.knockoutwhist.KnockOutWhist
|
import de.knockoutwhist.KnockOutWhist
|
||||||
import de.knockoutwhist.components.Configuration
|
import de.knockoutwhist.components.Configuration
|
||||||
|
import de.knockoutwhist.rounds.Match
|
||||||
import di.KnockOutWebConfigurationModule
|
import di.KnockOutWebConfigurationModule
|
||||||
import play.api.*
|
import play.api.*
|
||||||
import play.api.mvc.*
|
import play.api.mvc.*
|
||||||
@@ -53,9 +55,11 @@ class HomeController @Inject()(val controllerComponents: ControllerComponents) e
|
|||||||
NotFound(views.html.tui.apply(List(Html(s"<p>Session with id $id not found!</p>"))))
|
NotFound(views.html.tui.apply(List(Html(s"<p>Session with id $id not found!</p>"))))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val session = PodGameManager.identify(uuid).get
|
val gamesession = PodGameManager.identify(uuid).get
|
||||||
|
val player = session.asInstanceOf[AdvancedSession].player
|
||||||
|
val logic =
|
||||||
Action { implicit request =>
|
Action { implicit request =>
|
||||||
Ok(views.html.tui.apply(session.asInstanceOf[SimpleSession].get()))
|
Ok(views.html.matchy.apply(player, ))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,18 +8,22 @@ import scala.collection.mutable
|
|||||||
|
|
||||||
object PodGameManager {
|
object PodGameManager {
|
||||||
|
|
||||||
private val sessions: mutable.Map[UUID, PlayerSession] = mutable.Map()
|
|
||||||
|
|
||||||
def addSession(session: PlayerSession): Unit = {
|
private val gamesession: mutable.Map[UUID, Gamesession] = mutable.Map()
|
||||||
sessions.put(session.id, session)
|
|
||||||
|
def addGame(session: PlayerSession, gamesession: Gamesession): Unit = {
|
||||||
|
gamesession.put(session.id, gamesession)
|
||||||
|
}
|
||||||
|
def createGame(player: String): Unit = {
|
||||||
|
val game = Gamesession(UUID.randomUUID())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def clearSessions(): Unit = {
|
def clearSessions(): Unit = {
|
||||||
sessions.clear()
|
gamesession.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
def identify(id: UUID): Option[PlayerSession] = {
|
def identify(id: UUID): Option[PlayerSession] = {
|
||||||
sessions.get(id)
|
gamesession.get(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
def transmit(id: UUID, event: SimpleEvent): Unit = {
|
def transmit(id: UUID, event: SimpleEvent): Unit = {
|
||||||
@@ -27,7 +31,7 @@ object PodGameManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def transmitAll(event: SimpleEvent): Unit = {
|
def transmitAll(event: SimpleEvent): Unit = {
|
||||||
sessions.foreach(session => session._2.updatePlayer(event))
|
gamesession.foreach(session => session._2.updatePlayer(event))
|
||||||
}
|
}
|
||||||
|
|
||||||
def listSessions(): List[UUID] = {
|
def listSessions(): List[UUID] = {
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
package controllers
|
|
||||||
|
|
||||||
import controllers.sessions.SimpleSession
|
|
||||||
import de.knockoutwhist.cards.{Card, CardValue, Hand, Suit}
|
|
||||||
import de.knockoutwhist.events.*
|
|
||||||
import de.knockoutwhist.events.ERROR_STATUS.*
|
|
||||||
import de.knockoutwhist.events.GLOBAL_STATUS.*
|
|
||||||
import de.knockoutwhist.events.PLAYER_STATUS.*
|
|
||||||
import de.knockoutwhist.events.ROUND_STATUS.{PLAYERS_OUT, SHOW_START_ROUND, WON_ROUND}
|
|
||||||
import de.knockoutwhist.events.cards.{RenderHandEvent, ShowTieCardsEvent}
|
|
||||||
import de.knockoutwhist.events.round.ShowCurrentTrickEvent
|
|
||||||
import de.knockoutwhist.events.ui.GameState.{INGAME, MAIN_MENU}
|
|
||||||
import de.knockoutwhist.events.ui.{GameState, GameStateUpdateEvent}
|
|
||||||
import de.knockoutwhist.player.AbstractPlayer
|
|
||||||
import de.knockoutwhist.rounds.Match
|
|
||||||
import de.knockoutwhist.ui.UI
|
|
||||||
import de.knockoutwhist.utils.CustomThread
|
|
||||||
import de.knockoutwhist.utils.events.{EventListener, SimpleEvent}
|
|
||||||
|
|
||||||
object WebUI extends CustomThread with EventListener with UI {
|
|
||||||
|
|
||||||
setName("WebUI")
|
|
||||||
|
|
||||||
var init = false
|
|
||||||
private var internState: GameState = GameState.NO_SET
|
|
||||||
|
|
||||||
var latestOutput: String = ""
|
|
||||||
|
|
||||||
override def instance: CustomThread = WebUI
|
|
||||||
|
|
||||||
override def listen(event: SimpleEvent): Unit = {
|
|
||||||
runLater {
|
|
||||||
event match {
|
|
||||||
case event: RenderHandEvent =>
|
|
||||||
PodGameManager.transmit(event.player.id, event)
|
|
||||||
case event: ShowTieCardsEvent =>
|
|
||||||
PodGameManager.transmitAll(event)
|
|
||||||
case event: ShowGlobalStatus =>
|
|
||||||
if (event.status == TECHNICAL_MATCH_STARTED) {
|
|
||||||
val matchImpl = event.objects.head.asInstanceOf[Match]
|
|
||||||
for (player <- matchImpl.totalplayers) {
|
|
||||||
PodGameManager.addSession(SimpleSession(player.id, List()))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
PodGameManager.transmitAll(event)
|
|
||||||
}
|
|
||||||
case event: ShowPlayerStatus =>
|
|
||||||
PodGameManager.transmit(event.player.id, event)
|
|
||||||
case event: ShowRoundStatus =>
|
|
||||||
PodGameManager.transmitAll(event)
|
|
||||||
case event: ShowErrorStatus =>
|
|
||||||
PodGameManager.transmitAll(event)
|
|
||||||
case event: ShowCurrentTrickEvent =>
|
|
||||||
PodGameManager.transmitAll(event)
|
|
||||||
case event: GameStateUpdateEvent =>
|
|
||||||
if (internState != event.gameState) {
|
|
||||||
internState = event.gameState
|
|
||||||
if (event.gameState == MAIN_MENU) {
|
|
||||||
PodGameManager.clearSessions()
|
|
||||||
}
|
|
||||||
Some(true)
|
|
||||||
}
|
|
||||||
case _ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override def initial: Boolean = {
|
|
||||||
if (init) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
init = true
|
|
||||||
start()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package controllers.sessions
|
||||||
|
|
||||||
|
import de.knockoutwhist.rounds.Match
|
||||||
|
import de.knockoutwhist.rounds.Round
|
||||||
|
import de.knockoutwhist.utils.events.SimpleEvent
|
||||||
|
import de.knockoutwhist.player.AbstractPlayer
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
case class AdvancedSession(player: AbstractPlayer) extends PlayerSession {
|
||||||
|
override def id(): UUID = {
|
||||||
|
player.id
|
||||||
|
}
|
||||||
|
}
|
||||||
9
knockoutwhistweb/app/views/matchy.scala.html
Normal file
9
knockoutwhistweb/app/views/matchy.scala.html
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
@(toRender: List[Any])
|
||||||
|
|
||||||
|
@main("Match") {
|
||||||
|
<div id="match">
|
||||||
|
@for(line <- toRender) {
|
||||||
|
@line
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user