diff options
Diffstat (limited to 'sw-ui/src/main')
38 files changed, 294 insertions, 133 deletions
diff --git a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpButtons.kt b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpButtons.kt index 8b6ce30a..7438e0ba 100644 --- a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpButtons.kt +++ b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpButtons.kt @@ -1,4 +1,5 @@ @file:JsModule("@blueprintjs/core") + package com.palantir.blueprintjs import org.w3c.dom.HTMLElement @@ -14,10 +15,13 @@ import react.ReactElement external interface IActionProps : IIntentProps, IProps { /** Whether this action is non-interactive. */ var disabled: Boolean? + /** Name of a Blueprint UI icon (or an icon element) to render before the text. */ var icon: IconName? + /** Click event handler. */ var onClick: ((event: MouseEvent) -> Unit)? + /** Action text. Can be any single React renderable. */ var text: String? } @@ -25,12 +29,14 @@ external interface IActionProps : IIntentProps, IProps { external interface IButtonProps : IActionProps { // artificially added to allow title on button (should probably be on more general props) var title: String? + /** * If set to `true`, the button will display in an active state. * This is equivalent to setting `className={Classes.ACTIVE}`. * @default false */ var active: Boolean? + /** * Text alignment within button. By default, icons and text will be centered * within the button. Passing `"left"` or `"right"` will align the button @@ -39,26 +45,35 @@ external interface IButtonProps : IActionProps { * @default Alignment.CENTER */ var alignText: Alignment? + /** A ref handler that receives the native HTML element backing this component. */ var elementRef: ((ref: HTMLElement?) -> Any)? + /** Whether this button should expand to fill its container. */ var fill: Boolean? + /** Whether this button should use large styles. */ var large: Boolean? + /** * If set to `true`, the button will display a centered loading spinner instead of its contents. * The width of the button is not affected by the value of this prop. * @default false */ var loading: Boolean? + /** Whether this button should use minimal styles. */ var minimal: Boolean? + /** Whether this button should use outlined styles. */ var outlined: Boolean? + /** Name of a Blueprint UI icon (or an icon element) to render after the text. */ var rightIcon: IconName? + /** Whether this button should use small styles. */ var small: Boolean? + /** * HTML `type` attribute of button. Accepted values are `"button"`, `"submit"`, and `"reset"`. * Note that this prop has no effect on `AnchorButton`; it only affects `Button`. @@ -76,6 +91,7 @@ abstract external class AbstractButton : PureComponent<IButtonProps, IButtonStat external class Button : AbstractButton { override fun render(): ReactElement } + external class AnchorButton : AbstractButton { override fun render(): ReactElement } diff --git a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpCallout.kt b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpCallout.kt index a812d6e4..15d8a3f9 100644 --- a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpCallout.kt +++ b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpCallout.kt @@ -1,4 +1,5 @@ @file:JsModule("@blueprintjs/core") + package com.palantir.blueprintjs import react.PureComponent diff --git a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpCard.kt b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpCard.kt index dc8961f1..be9977ec 100644 --- a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpCard.kt +++ b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpCard.kt @@ -1,4 +1,5 @@ @file:JsModule("@blueprintjs/core") + package com.palantir.blueprintjs import org.w3c.dom.events.MouseEvent diff --git a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpDivider.kt b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpDivider.kt index 8ccef232..84f5ae31 100644 --- a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpDivider.kt +++ b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpDivider.kt @@ -1,4 +1,5 @@ @file:JsModule("@blueprintjs/core") + package com.palantir.blueprintjs import react.PureComponent diff --git a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpHtmlTable.kt b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpHtmlTable.kt index 1a602882..a8d45145 100644 --- a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpHtmlTable.kt +++ b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpHtmlTable.kt @@ -1,4 +1,5 @@ @file:JsModule("@blueprintjs/core") + package com.palantir.blueprintjs import react.PureComponent diff --git a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpIcon.kt b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpIcon.kt index ab277617..54d6bde8 100644 --- a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpIcon.kt +++ b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpIcon.kt @@ -1,4 +1,5 @@ @file:JsModule("@blueprintjs/core") + package com.palantir.blueprintjs import react.PureComponent @@ -13,11 +14,13 @@ external interface IIconProps : IIntentProps, IProps { * surrounding text. */ var color: String? + /** * String for the `title` attribute on the rendered element, which will appear * on hover as a native browser tooltip. */ var htmlTitle: String? + /** * Name of a Blueprint UI icon, or an icon element, to render. This prop is * required because it determines the content of the component, but it can @@ -35,6 +38,7 @@ external interface IIconProps : IIntentProps, IProps { * `<Element />` instead. */ var icon: IconName + /** * Size of the icon, in pixels. Blueprint contains 16px and 20px SVG icon * images, and chooses the appropriate resolution based on this prop. @@ -48,6 +52,7 @@ external interface IIconProps : IIntentProps, IProps { * @default "span" */ var tagName: String? // keyof JSX.IntrinsicElements + /** * Description string. This string does not appear in normal browsers, but * it increases accessibility. For instance, screen readers will use it for diff --git a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpInputs.kt b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpInputs.kt index 4eaadb78..90178a9b 100644 --- a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpInputs.kt +++ b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpInputs.kt @@ -1,4 +1,5 @@ @file:JsModule("@blueprintjs/core") + package com.palantir.blueprintjs import org.w3c.dom.HTMLInputElement @@ -13,30 +14,39 @@ external interface IInputGroupProps : IControlledProps, IIntentProps, IProps { * @default false */ var disabled: Boolean? + /** * Whether the component should take up the full width of its container. */ var fill: Boolean? + /** Ref handler that receives HTML `<input>` element backing this component. */ var inputRef: ((ref: HTMLInputElement?) -> Any)? + /** * Name of a Blueprint UI icon (or an icon element) to render on the left side of the input group, * before the user's cursor. */ var leftIcon: IconName? + /** Whether this input should use large styles. */ var large: Boolean? + /** Whether this input should use small styles. */ var small: Boolean? + /** Placeholder text in the absence of any value. */ var placeholder: String? + /** * Element to render on right side of input. * For best results, use a minimal button, tag, or small spinner. */ var rightElement: ReactElement? + /** Whether the input (and any buttons) should appear with rounded caps. */ var round: Boolean? + /** * HTML `input` type attribute. * @default "text" diff --git a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpNonIdealState.kt b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpNonIdealState.kt index f6ca7aec..7bc4fa0d 100644 --- a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpNonIdealState.kt +++ b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpNonIdealState.kt @@ -1,4 +1,5 @@ @file:JsModule("@blueprintjs/core") + package com.palantir.blueprintjs import react.PureComponent diff --git a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpOverlay.kt b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpOverlay.kt index 254b5bb3..7c2f3c43 100644 --- a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpOverlay.kt +++ b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpOverlay.kt @@ -1,4 +1,5 @@ @file:JsModule("@blueprintjs/core") + package com.palantir.blueprintjs import org.w3c.dom.HTMLElement @@ -14,11 +15,13 @@ external interface IOverlayableProps : IOverlayLifecycleProps { * @default true */ var autoFocus: Boolean? + /** * Whether pressing the `esc` key should invoke `onClose`. * @default true */ var canEscapeKeyClose: Boolean? + /** * Whether the overlay should prevent focus from leaving itself. That is, if the user attempts * to focus an element outside the overlay and this prop is enabled, then the overlay will @@ -27,6 +30,7 @@ external interface IOverlayableProps : IOverlayLifecycleProps { * @default true */ var enforceFocus: Boolean? + /** * If `true` and `usePortal={true}`, the `Portal` containing the children is created and attached * to the DOM when the overlay is opened for the first time; otherwise this happens when the @@ -35,6 +39,7 @@ external interface IOverlayableProps : IOverlayLifecycleProps { * @default true */ var lazy: Boolean? + /** * Indicates how long (in milliseconds) the overlay's enter/leave transition takes. * This is used by React `CSSTransition` to know when a transition completes and must match @@ -43,6 +48,7 @@ external interface IOverlayableProps : IOverlayLifecycleProps { * @default 300 */ var transitionDuration: Int? + /** * Whether the overlay should be wrapped in a `Portal`, which renders its contents in a new * element attached to `portalContainer` prop. @@ -56,17 +62,20 @@ external interface IOverlayableProps : IOverlayLifecycleProps { * @default true */ var usePortal: Boolean? + /** * Space-delimited string of class names applied to the `Portal` element if * `usePortal={true}`. */ var portalClassName: String? + /** * The container element into which the overlay renders its contents, when `usePortal` is `true`. * This prop is ignored if `usePortal` is `false`. * @default document.body */ var portalContainer: HTMLElement? + /** * A callback that is invoked when user interaction causes the overlay to close, such as * clicking on the overlay or pressing the `esc` key (if enabled). @@ -77,53 +86,63 @@ external interface IOverlayableProps : IOverlayLifecycleProps { */ var onClose: ((Event) -> Unit)? } + external interface IOverlayLifecycleProps { /** * Lifecycle method invoked just before the CSS _close_ transition begins on * a child. Receives the DOM element of the child being closed. */ var onClosing: ((node: HTMLElement) -> Unit)? + /** * Lifecycle method invoked just after the CSS _close_ transition ends but * before the child has been removed from the DOM. Receives the DOM element * of the child being closed. */ var onClosed: ((node: HTMLElement) -> Unit)? + /** * Lifecycle method invoked just after mounting the child in the DOM but * just before the CSS _open_ transition begins. Receives the DOM element of * the child being opened. */ var onOpening: ((node: HTMLElement) -> Unit)? + /** * Lifecycle method invoked just after the CSS _open_ transition ends. * Receives the DOM element of the child being opened. */ var onOpened: ((node: HTMLElement) -> Unit)? } + external interface IBackdropProps { /** CSS class names to apply to backdrop element. */ var backdropClassName: String? + /** HTML props for the backdrop element. */ var backdropProps: RProps? // React.HTMLProps<HTMLDivElement>? + /** * Whether clicking outside the overlay element (either on backdrop when present or on document) * should invoke `onClose`. * @default true */ var canOutsideClickClose: Boolean? + /** * Whether a container-spanning backdrop element should be rendered behind the contents. * @default true */ var hasBackdrop: Boolean? } + external interface IOverlayProps : IOverlayableProps, IBackdropProps, IProps { /** * Toggles the visibility of the overlay and its children. * This prop is required because the component is controlled. */ var isOpen: Boolean + /** * Name of the transition for internal `CSSTransition`. * Providing your own name here will require defining new CSS transition properties. @@ -131,9 +150,11 @@ external interface IOverlayProps : IOverlayableProps, IBackdropProps, IProps { */ var transitionName: String? } + external interface IOverlayState : RState { var hasEverOpened: Boolean? } + external class Overlay : PureComponent<IOverlayProps, IOverlayState> { override fun render(): ReactElement } diff --git a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpPopover.kt b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpPopover.kt index 1c610579..57093a25 100644 --- a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpPopover.kt +++ b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpPopover.kt @@ -1,4 +1,5 @@ @file:JsModule("@blueprintjs/core") + package com.palantir.blueprintjs import org.w3c.dom.HTMLDivElement diff --git a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpTag.kt b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpTag.kt index 7a2a04f2..a3727af9 100644 --- a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpTag.kt +++ b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpTag.kt @@ -1,4 +1,5 @@ @file:JsModule("@blueprintjs/core") + package com.palantir.blueprintjs import org.w3c.dom.events.MouseEvent @@ -12,13 +13,16 @@ external interface ITagProps : IProps, IIntentProps { * @default false */ var active: Boolean? + /** * Whether the tag should take up the full width of its container. * @default false */ var fill: Boolean? + /** Name of a Blueprint UI icon (or an icon element) to render before the children. */ var icon: IconName? + /** * Whether the tag should visually respond to user interactions. If set * to `true`, hovering over the tag will change its color and mouse cursor. @@ -28,16 +32,19 @@ external interface ITagProps : IProps, IIntentProps { * @default false */ var interactive: Boolean? + /** * Whether this tag should use large styles. * @default false */ var large: Boolean? + /** * Whether this tag should use minimal styles. * @default false */ var minimal: Boolean? + /** * Whether tag content should be allowed to occupy multiple lines. * If false, a single line of text will be truncated with an ellipsis if @@ -46,18 +53,22 @@ external interface ITagProps : IProps, IIntentProps { * @default false */ var multiline: Boolean? + /** * Callback invoked when the tag is clicked. * Recommended when `interactive` is `true`. */ var onClick: ((e: MouseEvent) -> Unit)? + /** * Click handler for remove button. * The remove button will only be rendered if this prop is defined. */ var onRemove: ((e: MouseEvent, tagProps: ITagProps) -> Unit)? + /** Name of a Blueprint UI icon (or an icon element) to render after the children. */ var rightIcon: IconName? + /** * Whether this tag should have rounded ends. * @default false diff --git a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/blueprintjs.kt b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/blueprintjs.kt index 7da41fc9..8063f98e 100644 --- a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/blueprintjs.kt +++ b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/blueprintjs.kt @@ -1,4 +1,5 @@ @file:JsModule("@blueprintjs/core") + package com.palantir.blueprintjs import org.w3c.dom.events.Event @@ -59,26 +60,33 @@ external interface IProps : RProps { /** A space-delimited list of class names to pass along to a child element. */ var className: String? } + external interface IIntentProps { /** Visual intent color to apply to element. */ var intent: Intent? } + /** Interface for a link, with support for customizing target window. */ external interface ILinkProps { /** Link URL. */ var href: String? + /** Link target attribute. Use `"_blank"` to open in a new window. */ var target: String? } + /** Interface for a controlled input. */ external interface IControlledProps { /** Initial value of the input, for uncontrolled usage. */ var defaultValue: String? + /** Change event handler. Use `event.target.value` for new value. */ var onChange: ((Event) -> Unit)? + /** Form value of the input, for controlled usage. */ var value: String? } + /** * An interface for an option in a list, such as in a `<select>` or `RadioGroup`. * These props can be spread directly to an `<option>` or `<Radio>` element. @@ -86,8 +94,10 @@ external interface IControlledProps { external interface IOptionProps : IProps { /** Whether this option is non-interactive. */ var disabled: Boolean? + /** Label text for this option. If omitted, `value` is used as the label. */ var label: String? + /** Value of this option. */ var value: Any? // String | Number } diff --git a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/blueprintjsHelpers.kt b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/blueprintjsHelpers.kt index 9132de58..5ad0cc7c 100644 --- a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/blueprintjsHelpers.kt +++ b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/blueprintjsHelpers.kt @@ -17,7 +17,7 @@ fun RBuilder.bpIcon( title: String? = null, alt: String? = null, className: String? = null, - block: RHandler<IIconProps> = {} + block: RHandler<IIconProps> = {}, ): ReactElement = child(Icon::class) { attrs { this.icon = name @@ -40,7 +40,7 @@ fun RBuilder.bpButton( rightIcon: IconName? = null, intent: Intent = Intent.NONE, onClick: ((event: MouseEvent) -> Unit)? = {}, - block: RHandler<IButtonProps> = {} + block: RHandler<IButtonProps> = {}, ): ReactElement = child(Button::class) { attrs { this.title = title @@ -59,7 +59,7 @@ fun RBuilder.bpButton( fun RBuilder.bpButtonGroup( large: Boolean = false, minimal: Boolean = false, - block: RHandler<IButtonGroupProps> = {} + block: RHandler<IButtonGroupProps> = {}, ): ReactElement = child(ButtonGroup::class) { attrs { this.large = large @@ -72,7 +72,7 @@ fun RBuilder.bpInputGroup( large: Boolean = false, placeholder: String = "", rightElement: ReactElement? = null, - onChange: (Event) -> Unit + onChange: (Event) -> Unit, ): ReactElement = child(InputGroup::class) { attrs { this.large = large @@ -90,7 +90,7 @@ fun RBuilder.bpTag( fill: Boolean? = null, active: Boolean? = null, icon: String? = null, - block: RHandler<ITagProps> = {} + block: RHandler<ITagProps> = {}, ): ReactElement = child(Tag::class) { attrs { this.intent = intent @@ -110,7 +110,7 @@ fun RBuilder.bpNonIdealState( description: ReactElement? = null, action: ReactElement? = null, children: ReactElement? = null, - block: RHandler<INonIdealStateProps> = {} + block: RHandler<INonIdealStateProps> = {}, ): ReactElement = child(NonIdealState::class) { attrs { this.icon = icon @@ -128,7 +128,7 @@ fun RBuilder.bpNonIdealState( description: ReactElement? = null, action: ReactElement? = null, children: ReactElement? = null, - block: RHandler<INonIdealStateProps> = {} + block: RHandler<INonIdealStateProps> = {}, ): ReactElement = bpNonIdealState(icon, buildElement { h2 { +title } }, description, action, children, block) fun RBuilder.bpOverlay( @@ -140,7 +140,7 @@ fun RBuilder.bpOverlay( canEscapeKeyClose: Boolean = true, canOutsideClickClose: Boolean = true, onClose: () -> Unit = {}, - block: RHandler<IOverlayProps> = {} + block: RHandler<IOverlayProps> = {}, ): ReactElement = child(Overlay::class) { attrs { this.isOpen = isOpen @@ -167,7 +167,7 @@ fun RBuilder.bpPopover( popoverClassName: String? = null, portalClassName: String? = null, onClose: () -> Unit = {}, - block: RHandler<IPopoverProps> = {} + block: RHandler<IPopoverProps> = {}, ): ReactElement = child(Popover::class) { attrs { this.interactionKind = interactionKind @@ -189,7 +189,7 @@ fun RBuilder.bpCallout( intent: Intent? = Intent.NONE, icon: IconName? = null, title: String? = null, - block: RHandler<ICalloutProps> = {} + block: RHandler<ICalloutProps> = {}, ): ReactElement = child(Callout::class) { attrs { if (icon != null) { @@ -206,7 +206,7 @@ fun RBuilder.bpCard( interactive: Boolean = false, className: String? = null, onClick: () -> Unit = {}, - block: RHandler<ICardProps> = {} + block: RHandler<ICardProps> = {}, ): ReactElement = child(Card::class) { attrs { this.elevation = elevation @@ -222,7 +222,7 @@ fun RBuilder.bpHtmlTable( interactive: Boolean = false, condensed: Boolean = false, striped: Boolean = false, - block: RHandler<IHTMLTableProps> = {} + block: RHandler<IHTMLTableProps> = {}, ): ReactElement = child(HTMLTable::class) { attrs { this.bordered = bordered @@ -235,7 +235,7 @@ fun RBuilder.bpHtmlTable( fun RBuilder.bpDivider( tagName: String? = null, - block: RHandler<IDividerProps> = {} + block: RHandler<IDividerProps> = {}, ): ReactElement = child(Divider::class) { attrs { if (tagName != null) { 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 diff --git a/sw-ui/src/main/resources/index.html b/sw-ui/src/main/resources/index.html index d4fba7e6..304be751 100644 --- a/sw-ui/src/main/resources/index.html +++ b/sw-ui/src/main/resources/index.html @@ -7,10 +7,10 @@ <title>Seven Wonders</title> <link href='https://fonts.googleapis.com/css2?family=Acme&display=swap' rel='stylesheet'> <!-- Style dependencies --> - <link href="https://unpkg.com/normalize.css@^7.0.0" rel="stylesheet" /> + <link href="https://unpkg.com/normalize.css@^7.0.0" rel="stylesheet"/> <!-- Blueprint stylesheets --> - <link href="https://unpkg.com/@blueprintjs/icons@^3.4.0/lib/css/blueprint-icons.css" rel="stylesheet" /> - <link href="https://unpkg.com/@blueprintjs/core@^3.10.0/lib/css/blueprint.css" rel="stylesheet" /> + <link href="https://unpkg.com/@blueprintjs/icons@^3.4.0/lib/css/blueprint-icons.css" rel="stylesheet"/> + <link href="https://unpkg.com/@blueprintjs/core@^3.10.0/lib/css/blueprint.css" rel="stylesheet"/> </head> <body> <div id="root"></div> |