diff options
Diffstat (limited to 'sw-ui/src/main/kotlin/org')
24 files changed, 199 insertions, 117 deletions
diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Board.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Board.kt index 419aa71b..9cc72c31 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Board.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Board.kt @@ -74,7 +74,7 @@ private fun RBuilder.tableCard(card: TableCard, indexInColumn: Int, block: Style transform { translate( tx = (indexInColumn * xOffset).pct, - ty = (indexInColumn * yOffset).pct + ty = (indexInColumn * yOffset).pct, ) } maxWidth = 100.pct @@ -153,7 +153,7 @@ private fun RBuilder.boardToken(tokenName: String, count: Int, block: StyledDOMB tokenName = tokenName, count = count, countPosition = TokenCountPosition.RIGHT, - brightText = true + brightText = true, ) { css { filter = "drop-shadow(0.2rem 0.2rem 0.5rem black)" diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/BoardSummary.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/BoardSummary.kt index 05a043bf..4f1459de 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/BoardSummary.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/BoardSummary.kt @@ -11,12 +11,16 @@ import org.luxons.sevenwonders.ui.components.gameBrowser.playerInfo import react.RBuilder import react.ReactElement import react.buildElement -import styled.* +import styled.StyledDOMBuilder +import styled.css +import styled.getClassName +import styled.styledDiv +import styled.styledHr enum class BoardSummarySide( val tokenCountPosition: TokenCountPosition, val alignment: Align, - val popoverPosition: PopoverPosition + val popoverPosition: PopoverPosition, ) { LEFT(TokenCountPosition.RIGHT, Align.flexStart, PopoverPosition.RIGHT), TOP(TokenCountPosition.OVER, Align.flexStart, PopoverPosition.BOTTOM), @@ -27,13 +31,13 @@ fun RBuilder.boardSummaryWithPopover( player: PlayerDTO, board: Board, boardSummarySide: BoardSummarySide, - block: StyledDOMBuilder<DIV>.() -> Unit = {} + block: StyledDOMBuilder<DIV>.() -> Unit = {}, ) { val popoverClass = GameStyles.getClassName { it::fullBoardPreviewPopover } bpPopover( content = createFullBoardPreview(board), position = boardSummarySide.popoverPosition, - popoverClassName = popoverClass + popoverClassName = popoverClass, ) { boardSummary(player, board, boardSummarySide, block) } @@ -50,14 +54,14 @@ private fun createFullBoardPreview(board: Board): ReactElement = buildElement { private fun RBuilder.boardSummary( player: PlayerDTO, board: Board, - boardSummarySide: BoardSummarySide, - block: StyledDOMBuilder<DIV>.() -> Unit = {} + side: BoardSummarySide, + block: StyledDOMBuilder<DIV>.() -> Unit = {}, ) { styledDiv { css { display = Display.flex flexDirection = FlexDirection.column - alignItems = boardSummarySide.alignment + alignItems = side.alignment padding(all = 0.5.rem) backgroundColor = Color.paleGoldenrod.withAlpha(0.5) zIndex = 50 // above table cards @@ -77,13 +81,13 @@ private fun RBuilder.boardSummary( styledDiv { css { display = Display.flex - flexDirection = if (boardSummarySide == BoardSummarySide.TOP) FlexDirection.row else FlexDirection.column - alignItems = boardSummarySide.alignment + flexDirection = if (side == BoardSummarySide.TOP) FlexDirection.row else FlexDirection.column + alignItems = side.alignment } val tokenSize = 2.rem - generalCounts(board, tokenSize, boardSummarySide.tokenCountPosition) + generalCounts(board, tokenSize, side.tokenCountPosition) bpDivider() - scienceTokens(board, tokenSize, boardSummarySide.tokenCountPosition) + scienceTokens(board, tokenSize, side.tokenCountPosition) } block() } @@ -92,7 +96,7 @@ private fun RBuilder.boardSummary( private fun StyledDOMBuilder<DIV>.generalCounts( board: Board, tokenSize: LinearDimension, - countPosition: TokenCountPosition + countPosition: TokenCountPosition, ) { goldIndicator(amount = board.gold, imgSize = tokenSize, amountPosition = countPosition) tokenWithCount( @@ -100,41 +104,41 @@ private fun StyledDOMBuilder<DIV>.generalCounts( count = board.bluePoints, imgSize = tokenSize, countPosition = countPosition, - brightText = countPosition == TokenCountPosition.OVER + brightText = countPosition == TokenCountPosition.OVER, ) tokenWithCount( tokenName = "military/shield", count = board.military.nbShields, imgSize = tokenSize, countPosition = countPosition, - brightText = countPosition == TokenCountPosition.OVER + brightText = countPosition == TokenCountPosition.OVER, ) } private fun RBuilder.scienceTokens( board: Board, tokenSize: LinearDimension, - sciencePosition: TokenCountPosition + sciencePosition: TokenCountPosition, ) { tokenWithCount( tokenName = "science/compass", count = board.science.nbCompasses, imgSize = tokenSize, countPosition = sciencePosition, - brightText = sciencePosition == TokenCountPosition.OVER + brightText = sciencePosition == TokenCountPosition.OVER, ) tokenWithCount( tokenName = "science/cog", count = board.science.nbWheels, imgSize = tokenSize, countPosition = sciencePosition, - brightText = sciencePosition == TokenCountPosition.OVER + brightText = sciencePosition == TokenCountPosition.OVER, ) tokenWithCount( tokenName = "science/tablet", count = board.science.nbTablets, imgSize = tokenSize, countPosition = sciencePosition, - brightText = sciencePosition == TokenCountPosition.OVER + brightText = sciencePosition == TokenCountPosition.OVER, ) } diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/CardImage.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/CardImage.kt index a2d0b8f2..79836f70 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/CardImage.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/CardImage.kt @@ -15,7 +15,7 @@ fun RBuilder.cardImage( card: Card, faceDown: Boolean = false, highlightColor: Color? = null, - block: StyledDOMBuilder<IMG>.() -> Unit = {} + block: StyledDOMBuilder<IMG>.() -> Unit = {}, ) { if (faceDown) { cardBackImage(card.back, highlightColor, block) @@ -36,7 +36,7 @@ fun RBuilder.cardImage( fun RBuilder.cardBackImage( cardBack: CardBack, highlightColor: Color? = null, - block: StyledDOMBuilder<IMG>.() -> Unit = {} + block: StyledDOMBuilder<IMG>.() -> Unit = {}, ) { styledImg(src = "/images/cards/back/${cardBack.image}") { css { @@ -75,7 +75,7 @@ private fun CSSBuilder.highlightStyle(highlightColor: Color?) { offsetY = 0.px, blurRadius = 1.rem, spreadRadius = 0.1.rem, - color = highlightColor + color = highlightColor, ) } } diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt index 3545113b..fbd6d8c5 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt @@ -1,17 +1,38 @@ package org.luxons.sevenwonders.ui.components.game -import com.palantir.blueprintjs.* +import com.palantir.blueprintjs.Elevation +import com.palantir.blueprintjs.Intent +import com.palantir.blueprintjs.bpButton +import com.palantir.blueprintjs.bpButtonGroup +import com.palantir.blueprintjs.bpCallout +import com.palantir.blueprintjs.bpCard +import com.palantir.blueprintjs.bpNonIdealState +import com.palantir.blueprintjs.bpOverlay import kotlinx.css.* import kotlinx.css.properties.* import kotlinx.html.DIV -import org.luxons.sevenwonders.model.* +import org.luxons.sevenwonders.model.Action +import org.luxons.sevenwonders.model.PlayerMove +import org.luxons.sevenwonders.model.PlayerTurnInfo import org.luxons.sevenwonders.model.api.PlayerDTO import org.luxons.sevenwonders.model.boards.Board import org.luxons.sevenwonders.model.boards.RelativeBoardPosition import org.luxons.sevenwonders.model.cards.HandCard +import org.luxons.sevenwonders.model.getBoard +import org.luxons.sevenwonders.model.getOwnBoard import org.luxons.sevenwonders.ui.components.GlobalStyles -import org.luxons.sevenwonders.ui.redux.* -import react.* +import org.luxons.sevenwonders.ui.redux.GameState +import org.luxons.sevenwonders.ui.redux.RequestLeaveGame +import org.luxons.sevenwonders.ui.redux.RequestPrepareMove +import org.luxons.sevenwonders.ui.redux.RequestSayReady +import org.luxons.sevenwonders.ui.redux.RequestUnprepareMove +import org.luxons.sevenwonders.ui.redux.connectStateAndDispatch +import react.RBuilder +import react.RClass +import react.RComponent +import react.RProps +import react.RState +import react.ReactElement import styled.StyledDOMBuilder import styled.css import styled.getClassName @@ -193,17 +214,12 @@ private class GameScene(props: GameSceneProps) : RComponent<GameSceneProps, RSta disabled = isReady, intent = intent, icon = if (isReady) "tick-circle" else "play", - onClick = { props.sayReady() } + onClick = { props.sayReady() }, ) { +"READY" } // not really a button, but nice for style - bpButton( - large = true, - icon = "people", - disabled = isReady, - intent = intent - ) { + bpButton(large = true, icon = "people", disabled = isReady, intent = intent) { +"${props.players.count { it.isReady }}/${props.players.size}" } } @@ -228,5 +244,5 @@ private val gameScene: RClass<GameSceneProps> = gameState = state.gameState preparedMove = state.gameState?.currentPreparedMove preparedCard = state.gameState?.currentPreparedCard - } + }, ) diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt index 315e25e8..c8fb8d61 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt @@ -1,14 +1,28 @@ package org.luxons.sevenwonders.ui.components.game -import com.palantir.blueprintjs.* +import com.palantir.blueprintjs.IButtonGroupProps +import com.palantir.blueprintjs.IButtonProps +import com.palantir.blueprintjs.IconName +import com.palantir.blueprintjs.Intent +import com.palantir.blueprintjs.bpButton +import com.palantir.blueprintjs.bpButtonGroup +import com.palantir.blueprintjs.bpIcon import kotlinx.css.* import kotlinx.css.properties.* import kotlinx.html.DIV -import org.luxons.sevenwonders.model.* +import org.luxons.sevenwonders.model.Action +import org.luxons.sevenwonders.model.MoveType +import org.luxons.sevenwonders.model.PlayerMove +import org.luxons.sevenwonders.model.PlayerTurnInfo import org.luxons.sevenwonders.model.cards.CardPlayability import org.luxons.sevenwonders.model.cards.HandCard +import org.luxons.sevenwonders.model.getOwnBoard import org.luxons.sevenwonders.model.wonders.WonderBuildability -import react.* +import react.RBuilder +import react.RComponent +import react.RElementBuilder +import react.RProps +import react.RState import styled.StyledDOMBuilder import styled.css import styled.styledDiv @@ -17,7 +31,7 @@ import kotlin.math.absoluteValue private enum class HandAction( val buttonTitle: String, val moveType: MoveType, - val icon: IconName + val icon: IconName, ) { PLAY("PLAY", MoveType.PLAY, "play"), PLAY_FREE("Play as this age's free card", MoveType.PLAY_FREE, "star"), @@ -58,7 +72,7 @@ class HandComponent(props: HandProps) : RComponent<HandProps, RState>(props) { private fun RBuilder.handCard( card: HandCard, - block: StyledDOMBuilder<DIV>.() -> Unit + block: StyledDOMBuilder<DIV>.() -> Unit, ) { styledDiv { css { @@ -120,7 +134,7 @@ class HandComponent(props: HandProps) : RComponent<HandProps, RState>(props) { onClick = { val transactions = card.playability.cheapestTransactions.first() props.prepareMove(PlayerMove(handAction.moveType, card.name, transactions)) - } + }, ) { bpIcon(handAction.icon) if (card.playability.isPlayable && !card.playability.isFree) { @@ -139,7 +153,7 @@ class HandComponent(props: HandProps) : RComponent<HandProps, RState>(props) { onClick = { val transactions = wonderBuildability.cheapestTransactions.first() props.prepareMove(PlayerMove(MoveType.UPGRADE_WONDER, card.name, transactions)) - } + }, ) { bpIcon("key-shift") if (wonderBuildability.isBuildable && !wonderBuildability.isFree) { @@ -154,7 +168,7 @@ class HandComponent(props: HandProps) : RComponent<HandProps, RState>(props) { large = true, intent = Intent.DANGER, icon = "cross", - onClick = { props.prepareMove(PlayerMove(MoveType.DISCARD, card.name)) } + onClick = { props.prepareMove(PlayerMove(MoveType.DISCARD, card.name)) }, ) } } @@ -189,7 +203,7 @@ private fun RElementBuilder<IButtonProps>.priceInfo(amount: Int) { customCountStyle = { fontFamily = "sans-serif" fontSize = size * 0.8 - } + }, ) { css { position = Position.absolute @@ -251,7 +265,7 @@ private fun CSSBuilder.handCardImgStyle(isPlayable: Boolean) { fun RBuilder.handCards( turnInfo: PlayerTurnInfo, preparedMove: PlayerMove?, - prepareMove: (PlayerMove) -> Unit + prepareMove: (PlayerMove) -> Unit, ) { child(HandComponent::class) { attrs { diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/PreparedMove.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/PreparedMove.kt index 083338a8..3cb230e0 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/PreparedMove.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/PreparedMove.kt @@ -19,7 +19,7 @@ fun RBuilder.preparedMove( card: HandCard, move: PlayerMove, unprepareMove: () -> Unit, - block: StyledDOMBuilder<DIV>.() -> Unit + block: StyledDOMBuilder<DIV>.() -> Unit, ) { styledDiv { block() @@ -45,7 +45,7 @@ fun RBuilder.preparedMove( title = "Cancel prepared move", small = true, intent = Intent.DANGER, - onClick = { unprepareMove() } + onClick = { unprepareMove() }, ) } } diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/ScoreTable.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/ScoreTable.kt index 28003cef..16c83c78 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/ScoreTable.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/ScoreTable.kt @@ -1,6 +1,12 @@ package org.luxons.sevenwonders.ui.components.game -import com.palantir.blueprintjs.* +import com.palantir.blueprintjs.Intent +import com.palantir.blueprintjs.bpButton +import com.palantir.blueprintjs.bpCard +import com.palantir.blueprintjs.bpHtmlTable +import com.palantir.blueprintjs.bpIcon +import com.palantir.blueprintjs.bpOverlay +import com.palantir.blueprintjs.bpTag import kotlinx.css.* import kotlinx.html.TD import kotlinx.html.TH @@ -10,7 +16,12 @@ import org.luxons.sevenwonders.model.score.ScoreCategory import org.luxons.sevenwonders.ui.components.GlobalStyles import react.RBuilder import react.dom.* -import styled.* +import styled.css +import styled.getClassName +import styled.inlineStyles +import styled.styledDiv +import styled.styledH1 +import styled.styledTd fun RBuilder.scoreTableOverlay(scoreBoard: ScoreBoard, players: List<PlayerDTO>, leaveGame: () -> Unit) { bpOverlay(isOpen = true) { diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Tokens.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Tokens.kt index efdc3ba8..74dc232e 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Tokens.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Tokens.kt @@ -6,10 +6,16 @@ import kotlinx.html.IMG import kotlinx.html.title import org.luxons.sevenwonders.ui.components.GlobalStyles import react.RBuilder -import styled.* +import styled.StyledDOMBuilder +import styled.css +import styled.styledDiv +import styled.styledImg +import styled.styledSpan enum class TokenCountPosition { - LEFT, RIGHT, OVER + LEFT, + RIGHT, + OVER, } fun RBuilder.goldIndicator( @@ -17,7 +23,7 @@ fun RBuilder.goldIndicator( amountPosition: TokenCountPosition = TokenCountPosition.OVER, imgSize: LinearDimension = 3.rem, customCountStyle: CSSBuilder.() -> Unit = {}, - block: StyledDOMBuilder<DIV>.() -> Unit = {} + block: StyledDOMBuilder<DIV>.() -> Unit = {}, ) { tokenWithCount( tokenName = "coin", @@ -26,7 +32,7 @@ fun RBuilder.goldIndicator( count = amount, countPosition = amountPosition, customCountStyle = customCountStyle, - block = block + block = block, ) } @@ -38,7 +44,7 @@ fun RBuilder.tokenWithCount( countPosition: TokenCountPosition = TokenCountPosition.RIGHT, brightText: Boolean = false, customCountStyle: CSSBuilder.() -> Unit = {}, - block: StyledDOMBuilder<DIV>.() -> Unit = {} + block: StyledDOMBuilder<DIV>.() -> Unit = {}, ) { styledDiv { block() @@ -85,7 +91,7 @@ fun RBuilder.tokenImage( tokenName: String, title: String = tokenName, size: LinearDimension?, - block: StyledDOMBuilder<IMG>.() -> Unit = {} + block: StyledDOMBuilder<IMG>.() -> Unit = {}, ) { styledImg(src = getTokenImagePath(tokenName)) { css { @@ -108,7 +114,7 @@ private fun getTokenImagePath(tokenName: String) = "/images/tokens/$tokenName.pn private fun CSSBuilder.tokenCountStyle( size: LinearDimension, brightText: Boolean, - customStyle: CSSBuilder.() -> Unit = {} + customStyle: CSSBuilder.() -> Unit = {}, ) { fontFamily = "Acme" fontSize = size diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/gameBrowser/CreateGameForm.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/gameBrowser/CreateGameForm.kt index a33c0507..e060af9c 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/gameBrowser/CreateGameForm.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/gameBrowser/CreateGameForm.kt @@ -9,7 +9,12 @@ import org.luxons.sevenwonders.ui.redux.RequestCreateGame import org.luxons.sevenwonders.ui.redux.connectDispatch import org.w3c.dom.HTMLInputElement import org.w3c.dom.events.Event -import react.* +import react.RBuilder +import react.RClass +import react.RComponent +import react.RProps +import react.RState +import react.buildElement import react.dom.* import styled.css import styled.styledDiv @@ -44,7 +49,7 @@ private class CreateGameForm(props: CreateGameFormProps) : RComponent<CreateGame val input = e.currentTarget as HTMLInputElement setState(transformState = { CreateGameFormState(input.value) }) }, - rightElement = createGameButton() + rightElement = createGameButton(), ) } currentPlayerInfo() diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/gameBrowser/GameList.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/gameBrowser/GameList.kt index 4d23974f..1e74070a 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/gameBrowser/GameList.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/gameBrowser/GameList.kt @@ -1,6 +1,10 @@ package org.luxons.sevenwonders.ui.components.gameBrowser -import com.palantir.blueprintjs.* +import com.palantir.blueprintjs.Intent +import com.palantir.blueprintjs.bpButton +import com.palantir.blueprintjs.bpHtmlTable +import com.palantir.blueprintjs.bpIcon +import com.palantir.blueprintjs.bpTag import kotlinx.css.* import kotlinx.html.title import org.luxons.sevenwonders.model.api.ConnectedPlayer @@ -99,7 +103,7 @@ class GameListPresenter(props: GameListProps) : RComponent<GameListProps, RState title = joinability.tooltip, icon = "arrow-right", disabled = !joinability.canDo, - onClick = { props.joinGame(lobby.id) } + onClick = { props.joinGame(lobby.id) }, ) } } @@ -114,5 +118,5 @@ private val gameList = connectStateAndDispatch<GameListStateProps, GameListDispa }, mapDispatchToProps = { dispatch, _ -> joinGame = { gameId -> dispatch(RequestJoinGame(gameId = gameId)) } - } + }, ) diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/gameBrowser/PlayerInfo.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/gameBrowser/PlayerInfo.kt index a6289649..40581ff4 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/gameBrowser/PlayerInfo.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/gameBrowser/PlayerInfo.kt @@ -76,7 +76,7 @@ class PlayerInfoPresenter(props: PlayerInfoProps) : RComponent<PlayerInfoProps, fun RBuilder.playerInfo( playerDTO: PlayerDTO, showUsername: Boolean = false, - iconSize: Int = 30 + iconSize: Int = 30, ) = child(PlayerInfoPresenter::class) { attrs { this.player = playerDTO @@ -92,5 +92,5 @@ private val playerInfo = connectState( mapStateToProps = { state, _ -> player = state.connectedPlayer showUsername = true - } + }, ) diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/home/ChooseNameForm.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/home/ChooseNameForm.kt index c4d424fa..a63fef08 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/home/ChooseNameForm.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/home/ChooseNameForm.kt @@ -8,7 +8,13 @@ import org.luxons.sevenwonders.ui.redux.RequestChooseName import org.luxons.sevenwonders.ui.redux.connectDispatch import org.w3c.dom.HTMLInputElement import org.w3c.dom.events.Event -import react.* +import react.RBuilder +import react.RClass +import react.RComponent +import react.RProps +import react.RState +import react.ReactElement +import react.buildElement import react.dom.* private interface ChooseNameFormProps : RProps { @@ -33,7 +39,7 @@ private class ChooseNameForm(props: ChooseNameFormProps) : RComponent<ChooseName onChange = { e -> val input = e.currentTarget as HTMLInputElement setState(transformState = { ChooseNameFormState(input.value) }) - } + }, ) } } @@ -43,7 +49,7 @@ private class ChooseNameForm(props: ChooseNameFormProps) : RComponent<ChooseName minimal = true, icon = "arrow-right", intent = Intent.PRIMARY, - onClick = { e -> chooseUsername(e) } + onClick = { e -> chooseUsername(e) }, ) } diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/Lobby.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/Lobby.kt index d304880f..3fa85b0a 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/Lobby.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/Lobby.kt @@ -99,7 +99,7 @@ class LobbyPresenter(props: LobbyProps) : RComponent<LobbyProps, RState>(props) icon = "play", title = startability.tooltip, disabled = !startability.canDo, - onClick = { props.startGame() } + onClick = { props.startGame() }, ) { +"START" } @@ -141,7 +141,7 @@ class LobbyPresenter(props: LobbyProps) : RComponent<LobbyProps, RState>(props) rightIcon = "desktop", title = if (currentGame.maxPlayersReached) "Max players reached" else "Add a bot to this game", disabled = currentGame.maxPlayersReached, - onClick = { addBot(currentGame) } + onClick = { addBot(currentGame) }, ) } @@ -157,7 +157,7 @@ class LobbyPresenter(props: LobbyProps) : RComponent<LobbyProps, RState>(props) icon = "random", rightIcon = "people", title = "Re-order players randomly", - onClick = { reorderPlayers(currentGame) } + onClick = { reorderPlayers(currentGame) }, ) { +"Reorder players" } @@ -171,7 +171,7 @@ class LobbyPresenter(props: LobbyProps) : RComponent<LobbyProps, RState>(props) bpButton( icon = "random", title = "Re-assign wonders to players randomly", - onClick = { randomizeWonders(currentGame) } + onClick = { randomizeWonders(currentGame) }, ) { +"Randomize wonders" } @@ -185,17 +185,17 @@ class LobbyPresenter(props: LobbyProps) : RComponent<LobbyProps, RState>(props) bpButton( icon = "random", title = "Re-roll wonder sides randomly", - onClick = { randomizeWonderSides(currentGame) } + onClick = { randomizeWonderSides(currentGame) }, ) bpButton( title = "Choose side A for everyone", - onClick = { setWonderSides(currentGame, WonderSide.A) } + onClick = { setWonderSides(currentGame, WonderSide.A) }, ) { +"A" } bpButton( title = "Choose side B for everyone", - onClick = { setWonderSides(currentGame, WonderSide.B) } + onClick = { setWonderSides(currentGame, WonderSide.B) }, ) { +"B" } @@ -220,7 +220,7 @@ class LobbyPresenter(props: LobbyProps) : RComponent<LobbyProps, RState>(props) intent = Intent.DANGER, icon = "arrow-left", title = "Leave the lobby and go back to the game browser", - onClick = { props.leaveLobby() } + onClick = { props.leaveLobby() }, ) { +"LEAVE" } @@ -241,5 +241,5 @@ private val lobby = connectStateAndDispatch<LobbyStateProps, LobbyDispatchProps, leaveLobby = { dispatch(RequestLeaveLobby()) } reorderPlayers = { orderedPlayers -> dispatch(RequestReorderPlayers(orderedPlayers)) } reassignWonders = { wonders -> dispatch(RequestReassignWonders(wonders)) } - } + }, ) diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/RadialList.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/RadialList.kt index e27e1cd8..97320b76 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/RadialList.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/RadialList.kt @@ -7,7 +7,11 @@ import org.luxons.sevenwonders.ui.components.GlobalStyles import react.RBuilder import react.ReactElement import react.dom.* -import styled.* +import styled.StyledDOMBuilder +import styled.css +import styled.styledDiv +import styled.styledLi +import styled.styledUl fun <T> RBuilder.radialList( items: List<T>, @@ -17,7 +21,7 @@ fun <T> RBuilder.radialList( itemWidth: Int, itemHeight: Int, options: RadialConfig = RadialConfig(), - block: StyledDOMBuilder<DIV>.() -> Unit = {} + block: StyledDOMBuilder<DIV>.() -> Unit = {}, ): ReactElement { val containerWidth = options.diameter + itemWidth val containerHeight = options.diameter + itemHeight @@ -39,7 +43,7 @@ private fun <T> RBuilder.radialListItems( items: List<T>, renderItem: (T) -> ReactElement, getKey: (T) -> String, - radialConfig: RadialConfig + radialConfig: RadialConfig, ): ReactElement { val offsets = offsetsFromCenter(items.size, radialConfig) return styledUl { diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/RadialMath.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/RadialMath.kt index d668ab9b..4b5eb509 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/RadialMath.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/RadialMath.kt @@ -7,12 +7,12 @@ import kotlin.math.sin data class CartesianCoords( val x: Int, - val y: Int + val y: Int, ) data class PolarCoords( val radius: Int, - val angleDeg: Int + val angleDeg: Int, ) private fun Int.toRadians() = (this * PI / 180.0) @@ -22,7 +22,7 @@ private fun Double.yProjection(angleRad: Double) = project(angleRad, ::sin) private fun PolarCoords.toCartesian() = CartesianCoords( x = radius.toDouble().xProjection(angleDeg.toRadians()), - y = radius.toDouble().yProjection(angleDeg.toRadians()) + y = radius.toDouble().yProjection(angleDeg.toRadians()), ) // Y-axis is pointing down in the browser, so the directions need to be reversed @@ -38,7 +38,7 @@ data class RadialConfig( val radius: Int = 120, val spreadArcDegrees: Int = 360, // full circle val firstItemAngleDegrees: Int = 0, // 12 o'clock - val direction: Direction = Direction.CLOCKWISE + val direction: Direction = Direction.CLOCKWISE, ) { val diameter: Int = radius * 2 } diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/RadialPlayerList.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/RadialPlayerList.kt index ef1ee612..56d25cb2 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/RadialPlayerList.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/RadialPlayerList.kt @@ -14,7 +14,7 @@ import styled.styledDiv import styled.styledH4 fun RBuilder.radialPlayerList(players: List<PlayerDTO>, currentPlayer: PlayerDTO): ReactElement { - val playerItems = players + val playerItems = players // .map { PlayerItem.Player(it, it.username == currentPlayer.username) } .growWithPlaceholders(targetSize = 3) .withUserFirst(currentPlayer) @@ -31,8 +31,8 @@ fun RBuilder.radialPlayerList(players: List<PlayerDTO>, currentPlayer: PlayerDTO options = RadialConfig( radius = 175, firstItemAngleDegrees = 180, // self at the bottom - direction = Direction.COUNTERCLOCKWISE // new players sit to the right of last player - ) + direction = Direction.COUNTERCLOCKWISE, // new players sit to the right of last player + ), ) } @@ -73,7 +73,7 @@ private sealed class PlayerItem { player.isGameOwner -> Icon("badge") else -> Icon("user") }, - title = if (player.isGameOwner) "Game owner" else null + title = if (player.isGameOwner) "Game owner" else null, ) } } @@ -87,19 +87,18 @@ private sealed class PlayerItem { userIcon( isMe = false, icon = Icon("user"), - title = "Waiting for player..." + title = "Waiting for player...", ) } } } -private fun RBuilder.userIcon(isMe: Boolean, icon: Icon, title: String?): ReactElement = - bpIcon( - name = icon.name, - intent = if (isMe) Intent.WARNING else Intent.NONE, - size = 50, - title = title - ) +private fun RBuilder.userIcon(isMe: Boolean, icon: Icon, title: String?): ReactElement = bpIcon( + name = icon.name, + intent = if (isMe) Intent.WARNING else Intent.NONE, + size = 50, + title = title, +) private fun RBuilder.playerElement(playerItem: PlayerItem) { styledDiv { diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt index 7eca24b8..97d00ab7 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt @@ -15,7 +15,7 @@ data class SwState( // they must be by ID to support updates to a sublist val gamesById: Map<Long, LobbyDTO> = emptyMap(), val currentLobby: LobbyDTO? = null, - val gameState: GameState? = null + val gameState: GameState? = null, ) { val currentPlayer: PlayerDTO? = (gameState?.players ?: currentLobby?.players)?.first { it.username == connectedPlayer?.username @@ -28,7 +28,7 @@ data class GameState( val players: List<PlayerDTO>, val turnInfo: PlayerTurnInfo?, val preparedCardsByUsername: Map<String, CardBack?> = emptyMap(), - val currentPreparedMove: PlayerMove? = null + val currentPreparedMove: PlayerMove? = null, ) { val currentPreparedCard: HandCard? get() = turnInfo?.hand?.firstOrNull { it.name == currentPreparedMove?.cardName } @@ -38,7 +38,7 @@ fun rootReducer(state: SwState, action: RAction): SwState = state.copy( gamesById = gamesReducer(state.gamesById, action), connectedPlayer = currentPlayerReducer(state.connectedPlayer, action), currentLobby = currentLobbyReducer(state.currentLobby, action), - gameState = gameStateReducer(state.gameState, action) + gameState = gameStateReducer(state.gameState, action), ) private fun gamesReducer(games: Map<Long, LobbyDTO>, action: RAction): Map<Long, LobbyDTO> = when (action) { @@ -64,20 +64,22 @@ private fun gameStateReducer(gameState: GameState?, action: RAction): GameState? is EnterGameAction -> GameState( id = action.lobby.id, players = action.lobby.players, - turnInfo = action.turnInfo + turnInfo = action.turnInfo, ) is PreparedMoveEvent -> gameState?.copy(currentPreparedMove = action.move) is RequestUnprepareMove -> gameState?.copy(currentPreparedMove = null) is PreparedCardEvent -> gameState?.copy( - preparedCardsByUsername = gameState.preparedCardsByUsername + (action.card.username to action.card.cardBack) + preparedCardsByUsername = gameState.preparedCardsByUsername + (action.card.username to action.card.cardBack), ) is PlayerReadyEvent -> gameState?.copy( - players = gameState.players.map { p -> if (p.username == action.username) p.copy(isReady = true) else p } + players = gameState.players.map { p -> + if (p.username == action.username) p.copy(isReady = true) else p + }, ) is TurnInfoEvent -> gameState?.copy( players = gameState.players.map { p -> p.copy(isReady = false) }, turnInfo = action.turnInfo, - currentPreparedMove = null + currentPreparedMove = null, ) else -> gameState } diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Store.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Store.kt index 9011f389..71c5eec0 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Store.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Store.kt @@ -22,7 +22,7 @@ private fun <A, T1, R> composeWithDevTools(function1: (T1) -> R, function2: (A) fun configureStore( sagaManager: SagaManager<SwState, RAction, WrapperAction>, - initialState: SwState = INITIAL_STATE + initialState: SwState = INITIAL_STATE, ): Store<SwState, RAction, WrapperAction> { val sagaEnhancer = applyMiddleware(sagaManager.createMiddleware()) return createStore(::rootReducer, initialState, composeWithDevTools(sagaEnhancer, rEnhancer())) diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Utils.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Utils.kt index 67ac5304..b748c3a5 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Utils.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Utils.kt @@ -12,7 +12,7 @@ import kotlin.reflect.KClass inline fun <reified DP : RProps> connectDispatch( clazz: KClass<out RComponent<DP, out RState>>, - noinline mapDispatchToProps: DP.((RAction) -> WrapperAction, RProps) -> Unit + noinline mapDispatchToProps: DP.((RAction) -> WrapperAction, RProps) -> Unit, ): RClass<RProps> { val connect = rConnect(mapDispatchToProps = mapDispatchToProps) return connect.invoke(clazz.js.unsafeCast<RClass<DP>>()) @@ -20,7 +20,7 @@ inline fun <reified DP : RProps> connectDispatch( inline fun <reified SP : RProps> connectState( clazz: KClass<out RComponent<SP, out RState>>, - noinline mapStateToProps: SP.(SwState, RProps) -> Unit + noinline mapStateToProps: SP.(SwState, RProps) -> Unit, ): RClass<RProps> { val connect = rConnect(mapStateToProps = mapStateToProps) return connect.invoke(clazz.js.unsafeCast<RClass<SP>>()) @@ -29,11 +29,11 @@ inline fun <reified SP : RProps> connectState( inline fun <reified SP : RProps, reified DP : RProps, reified P : RProps> connectStateAndDispatch( clazz: KClass<out RComponent<P, out RState>>, noinline mapStateToProps: SP.(SwState, RProps) -> Unit, - noinline mapDispatchToProps: DP.((RAction) -> WrapperAction, RProps) -> Unit + noinline mapDispatchToProps: DP.((RAction) -> WrapperAction, RProps) -> Unit, ): RClass<RProps> { val connect = rConnect<SwState, RAction, WrapperAction, RProps, SP, DP, P>( mapStateToProps = mapStateToProps, - mapDispatchToProps = mapDispatchToProps + mapDispatchToProps = mapDispatchToProps, ) return connect.invoke(clazz.js.unsafeCast<RClass<P>>()) } diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameBrowserSagas.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameBrowserSagas.kt index aa81ae55..b6f3662a 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameBrowserSagas.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameBrowserSagas.kt @@ -20,7 +20,7 @@ suspend fun SwSagaContext.gameBrowserSaga(session: SevenWondersSession) { private class GameBrowserSaga( private val session: SevenWondersSession, - private val sagaContext: SwSagaContext + private val sagaContext: SwSagaContext, ) { suspend fun run() { coroutineScope { diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt index b9f456e5..fb9bdfe2 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt @@ -4,7 +4,14 @@ import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import org.luxons.sevenwonders.client.SevenWondersSession -import org.luxons.sevenwonders.ui.redux.* +import org.luxons.sevenwonders.ui.redux.PlayerReadyEvent +import org.luxons.sevenwonders.ui.redux.PreparedCardEvent +import org.luxons.sevenwonders.ui.redux.PreparedMoveEvent +import org.luxons.sevenwonders.ui.redux.RequestLeaveGame +import org.luxons.sevenwonders.ui.redux.RequestPrepareMove +import org.luxons.sevenwonders.ui.redux.RequestSayReady +import org.luxons.sevenwonders.ui.redux.RequestUnprepareMove +import org.luxons.sevenwonders.ui.redux.TurnInfoEvent import org.luxons.sevenwonders.ui.router.Navigate import org.luxons.sevenwonders.ui.router.Route diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt index 044f8e78..37872017 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt @@ -4,7 +4,13 @@ import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import org.luxons.sevenwonders.client.SevenWondersSession -import org.luxons.sevenwonders.ui.redux.* +import org.luxons.sevenwonders.ui.redux.EnterGameAction +import org.luxons.sevenwonders.ui.redux.RequestAddBot +import org.luxons.sevenwonders.ui.redux.RequestLeaveLobby +import org.luxons.sevenwonders.ui.redux.RequestReassignWonders +import org.luxons.sevenwonders.ui.redux.RequestReorderPlayers +import org.luxons.sevenwonders.ui.redux.RequestStartGame +import org.luxons.sevenwonders.ui.redux.UpdateLobbyAction import org.luxons.sevenwonders.ui.router.Navigate import org.luxons.sevenwonders.ui.router.Route import org.luxons.sevenwonders.ui.utils.awaitFirst @@ -12,9 +18,7 @@ import org.luxons.sevenwonders.ui.utils.awaitFirst suspend fun SwSagaContext.lobbySaga(session: SevenWondersSession) { val lobby = getState().currentLobby ?: error("Lobby saga run without a current lobby") coroutineScope { - val lobbyUpdatesSubscription = session.watchLobbyUpdates() - .map { UpdateLobbyAction(it) } - .dispatchAllIn(this) + val lobbyUpdatesSubscription = session.watchLobbyUpdates().map { UpdateLobbyAction(it) }.dispatchAllIn(this) launch { onEach<RequestAddBot> { session.addBot(it.botDisplayName) } @@ -39,7 +43,7 @@ suspend fun SwSagaContext.lobbySaga(session: SevenWondersSession) { lobbyUpdatesSubscription.cancel() startGameJob.cancel() dispatch(Navigate(Route.GAME)) - } + }, ) } } diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/SagasFramework.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/SagasFramework.kt index df00f43f..3acf68e8 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/SagasFramework.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/SagasFramework.kt @@ -15,7 +15,7 @@ import redux.RAction @OptIn(ExperimentalCoroutinesApi::class) class SagaManager<S, A : RAction, R>( - private val monitor: ((A) -> Unit)? = null + private val monitor: ((A) -> Unit)? = null, ) { private lateinit var context: SagaContext<S, A, R> @@ -65,7 +65,7 @@ class SagaManager<S, A : RAction, R>( @OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class) class SagaContext<S, A : RAction, R>( private val reduxApi: MiddlewareApi<S, A, R>, - private val actions: BroadcastChannel<A> + private val actions: BroadcastChannel<A>, ) { /** * Gets the current redux state. @@ -112,7 +112,7 @@ class SagaContext<S, A : RAction, R>( * cancelled. */ suspend inline fun <reified T : A> onEach( - crossinline handle: suspend SagaContext<S, A, R>.(T) -> Unit + crossinline handle: suspend SagaContext<S, A, R>.(T) -> Unit, ) = onEach { if (it is T) { handle(it) diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt index 3a22b1ed..b5dcb978 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt @@ -18,7 +18,7 @@ data class Navigate(val route: Route) : RAction suspend fun SwSagaContext.routerSaga( startRoute: Route, - runRouteSaga: suspend SwSagaContext.(Route) -> Unit + runRouteSaga: suspend SwSagaContext.(Route) -> Unit, ) { coroutineScope { window.location.hash = startRoute.path |