From c3fc62e7117b2e970eea4eb84137b6624063fb6d Mon Sep 17 00:00:00 2001 From: Joffrey BION Date: Fri, 31 May 2019 20:19:34 +0200 Subject: Create multiplatform SevenWondersClient based on Krossbow --- .../org/luxons/sevenwonders/model/api/Api.kt | 23 ++++++++ .../sevenwonders/model/api/actions/Actions.kt | 65 ++++++++++++++++++++++ .../luxons/sevenwonders/model/api/errors/Errors.kt | 18 ++++++ .../org/luxons/sevenwonders/model/cards/Cards.kt | 6 ++ 4 files changed, 112 insertions(+) create mode 100644 sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Api.kt create mode 100644 sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/actions/Actions.kt create mode 100644 sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/errors/Errors.kt (limited to 'sw-common-model/src/commonMain/kotlin/org') diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Api.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Api.kt new file mode 100644 index 00000000..04c7ef2f --- /dev/null +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Api.kt @@ -0,0 +1,23 @@ +package org.luxons.sevenwonders.model.api + +const val SEVEN_WONDERS_WS_ENDPOINT = "/seven-wonders-websocket" + +enum class State { + LOBBY, PLAYING +} + +data class LobbyDTO( + val id: Long, + val name: String, + val owner: String, + val players: List, + val state: State +) + +data class PlayerDTO( + val username: String, + val displayName: String, + val index: Int, + val isGameOwner: Boolean, + val isUser: Boolean +) diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/actions/Actions.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/actions/Actions.kt new file mode 100644 index 00000000..59bc2e5b --- /dev/null +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/actions/Actions.kt @@ -0,0 +1,65 @@ +package org.luxons.sevenwonders.model.api.actions + +import org.luxons.sevenwonders.model.CustomizableSettings +import org.luxons.sevenwonders.model.PlayerMove + +/** + * The action to choose the player's name. This is the first action that should be called. + */ +class ChooseNameAction( + /** + * The display name of the player. May contain spaces and special characters. + */ + val playerName: String +) + +/** + * The action to create a game. + */ +class CreateGameAction( + /** + * The name of the game to create. + */ + val gameName: String +) + +/** + * The action to join a game. + */ +class JoinGameAction( + /** + * The ID of the game to join. + */ + val gameId: Long +) + +/** + * The action to prepare the next move during a game. + */ +class PrepareMoveAction( + /** + * The move to prepare. + */ + val move: PlayerMove +) + +/** + * The action to update the order of the players around the table. Can only be called in the lobby by the owner of the + * game. + */ +class ReorderPlayersAction( + /** + * The list of usernames of the players, in the new order. + */ + val orderedPlayers: List +) + +/** + * The action to update the settings of the game. Can only be called in the lobby by the owner of the game. + */ +class UpdateSettingsAction( + /** + * The new values for the settings. + */ + val settings: CustomizableSettings +) diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/errors/Errors.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/errors/Errors.kt new file mode 100644 index 00000000..f668f020 --- /dev/null +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/errors/Errors.kt @@ -0,0 +1,18 @@ +package org.luxons.sevenwonders.model.api.errors + +enum class ErrorType { + VALIDATION, CLIENT, SERVER +} + +data class ErrorDTO( + val code: String, + val message: String, + val type: ErrorType, + val details: List = emptyList() +) + +data class ValidationErrorDTO( + val path: String, + val message: String, + val rejectedValue: Any? = null +) diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt index 57cf3a00..11a3e8d8 100644 --- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt @@ -1,5 +1,6 @@ package org.luxons.sevenwonders.model.cards +import org.luxons.sevenwonders.model.api.PlayerDTO import org.luxons.sevenwonders.model.boards.Requirements import org.luxons.sevenwonders.model.resources.ResourceTransactions @@ -29,6 +30,11 @@ data class HandCard( val playability: CardPlayability ) +class PreparedCard( + val player: PlayerDTO, + val cardBack: CardBack +) + data class CardBack(val image: String) enum class PlayabilityLevel { -- cgit