From 10366ca0240bc6bb5d66cd06a0c18373c2c8e875 Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Tue, 9 Mar 2021 00:06:23 +0100 Subject: Unify game events --- .../org/luxons/sevenwonders/model/api/Lobby.kt | 25 ----------- .../luxons/sevenwonders/model/api/events/Events.kt | 30 ------------- .../sevenwonders/model/api/events/GameEvents.kt | 51 ++++++++++++++++++++++ .../model/api/events/GameListEvents.kt | 29 ++++++++++++ 4 files changed, 80 insertions(+), 55 deletions(-) delete mode 100644 sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/events/Events.kt create mode 100644 sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/events/GameEvents.kt create mode 100644 sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/events/GameListEvents.kt (limited to 'sw-common-model') diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Lobby.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Lobby.kt index 59515057..2c7e2c5c 100644 --- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Lobby.kt +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Lobby.kt @@ -1,36 +1,11 @@ package org.luxons.sevenwonders.model.api -import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import org.luxons.sevenwonders.model.Settings import org.luxons.sevenwonders.model.wonders.PreGameWonder const val SEVEN_WONDERS_WS_ENDPOINT = "/seven-wonders-websocket" -// workaround for https://github.com/Kotlin/kotlinx.serialization/issues/1194 -@Serializable -data class GameListEventWrapper( - val event: GameListEvent -) - -fun GameListEvent.wrap(): GameListEventWrapper = GameListEventWrapper(this) - -@Serializable -sealed class GameListEvent { - - @SerialName("ReplaceList") - @Serializable - data class ReplaceList(val lobbies: List) : GameListEvent() - - @SerialName("CreateOrUpdate") - @Serializable - data class CreateOrUpdate(val lobby: LobbyDTO) : GameListEvent() - - @SerialName("Delete") - @Serializable - data class Delete(val lobbyId: Long) : GameListEvent() -} - enum class State { LOBBY, PLAYING, diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/events/Events.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/events/Events.kt deleted file mode 100644 index d8c05e91..00000000 --- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/events/Events.kt +++ /dev/null @@ -1,30 +0,0 @@ -package org.luxons.sevenwonders.model.api.events - -import kotlinx.serialization.Serializable -import org.luxons.sevenwonders.model.PlayerMove -import org.luxons.sevenwonders.model.PlayerTurnInfo -import org.luxons.sevenwonders.model.cards.PreparedCard - -// workaround for https://github.com/Kotlin/kotlinx.serialization/issues/1194 -@Serializable -data class GameEventWrapper( - val event: GameEvent -) - -fun GameEvent.wrap() = GameEventWrapper(this) - -@Serializable -sealed class GameEvent { - - @Serializable - data class NewTurnStarted(val turnInfo: PlayerTurnInfo) : GameEvent() - - @Serializable - data class MovePrepared(val move: PlayerMove) : GameEvent() - - @Serializable - data class CardPrepared(val preparedCard: PreparedCard) : GameEvent() - - @Serializable - data class PlayerIsReady(val username: String) : GameEvent() -} diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/events/GameEvents.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/events/GameEvents.kt new file mode 100644 index 00000000..c978fb96 --- /dev/null +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/events/GameEvents.kt @@ -0,0 +1,51 @@ +package org.luxons.sevenwonders.model.api.events + +import kotlinx.serialization.Serializable +import org.luxons.sevenwonders.model.PlayerMove +import org.luxons.sevenwonders.model.PlayerTurnInfo +import org.luxons.sevenwonders.model.TurnAction +import org.luxons.sevenwonders.model.api.ConnectedPlayer +import org.luxons.sevenwonders.model.api.LobbyDTO +import org.luxons.sevenwonders.model.cards.PreparedCard + +// workaround for https://github.com/Kotlin/kotlinx.serialization/issues/1194 +@Serializable +data class GameEventWrapper( + val event: GameEvent +) + +fun GameEvent.wrap() = GameEventWrapper(this) + +@Serializable +sealed class GameEvent { + + @Serializable + data class NameChosen(val player: ConnectedPlayer) : GameEvent() + + @Serializable + data class LobbyJoined(val lobby: LobbyDTO) : GameEvent() + + @Serializable + data class LobbyUpdated(val lobby: LobbyDTO) : GameEvent() + + @Serializable + object LobbyLeft : GameEvent() + + @Serializable + data class GameStarted(val turnInfo: PlayerTurnInfo) : GameEvent() + + @Serializable + data class NewTurnStarted(val turnInfo: PlayerTurnInfo<*>) : GameEvent() + + @Serializable + data class MovePrepared(val move: PlayerMove) : GameEvent() + + @Serializable + object MoveUnprepared : GameEvent() + + @Serializable + data class CardPrepared(val preparedCard: PreparedCard) : GameEvent() + + @Serializable + data class PlayerIsReady(val username: String) : GameEvent() +} diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/events/GameListEvents.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/events/GameListEvents.kt new file mode 100644 index 00000000..2dd8f551 --- /dev/null +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/events/GameListEvents.kt @@ -0,0 +1,29 @@ +package org.luxons.sevenwonders.model.api.events + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import org.luxons.sevenwonders.model.api.LobbyDTO + +// workaround for https://github.com/Kotlin/kotlinx.serialization/issues/1194 +@Serializable +data class GameListEventWrapper( + val event: GameListEvent +) + +fun GameListEvent.wrap(): GameListEventWrapper = GameListEventWrapper(this) + +@Serializable +sealed class GameListEvent { + + @SerialName("ReplaceList") + @Serializable + data class ReplaceList(val lobbies: List) : GameListEvent() + + @SerialName("CreateOrUpdate") + @Serializable + data class CreateOrUpdate(val lobby: LobbyDTO) : GameListEvent() + + @SerialName("Delete") + @Serializable + data class Delete(val lobbyId: Long) : GameListEvent() +} -- cgit