Skip to content

Commit

Permalink
Correctly documented GameComponentViews
Browse files Browse the repository at this point in the history
  • Loading branch information
smilefx committed Jan 7, 2025
1 parent 87bad1e commit 5ab77bd
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import tools.aqua.bgw.builder.ReactConverters.toMouseReleasedEventData
import web.dom.Element

internal fun HTMLAttributes<Element>.applyCommonEventHandlers(props: ComponentViewData) {
onContextMenu = {
/*onContextMenu = {
it.preventDefault()
JCEFEventDispatcher.dispatchEvent(it.toMouseEventData(props.id))
}
}*/
onClick = { JCEFEventDispatcher.dispatchEvent(it.toMouseEventData(props.id)) }
onMouseDown = { JCEFEventDispatcher.dispatchEvent(it.toMousePressedEventData(props.id)) }
onMouseUp = { JCEFEventDispatcher.dispatchEvent(it.toMouseReleasedEventData(props.id)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ import kotlinx.html.*
import kotlinx.serialization.encodeToString
import tools.aqua.bgw.application.JCEFApplication
import tools.aqua.bgw.core.Frontend
import java.io.ByteArrayOutputStream
import java.util.Base64
import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream
import kotlin.text.Charsets.UTF_8

internal val componentChannel: Channel =
Channel("/ws").apply {
Expand Down Expand Up @@ -108,6 +113,17 @@ internal fun CoroutineScope.launchPeriodicAsync(repeatMillis: Long, action: (sus
}
}



internal fun gzip(content: String): String {
val bos = ByteArrayOutputStream()
GZIPOutputStream(bos).bufferedWriter(UTF_8).use { it.write(content) }
return Base64.getEncoder().encodeToString(bos.toByteArray())
}

internal fun ungzip(content: ByteArray): String =
GZIPInputStream(content.inputStream()).bufferedReader(UTF_8).use { it.readText() }

internal var uiJob =
CoroutineScope(Dispatchers.IO).launchPeriodicAsync(10) {
if ((Frontend.applicationEngine as JCEFApplication).getTitle() !==
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ private typealias AxialCoordinate = Pair<Int, Int>
* @param orientation The orientation of the hexagons in the grid. Default is
* [HexOrientation.POINTY_TOP].
*
* @see CoordinateSystem
* @see HexOrientation
* @see HexagonView
*
* @since 0.8
*/
class HexagonGrid<T : HexagonView>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package tools.aqua.bgw.components.gamecomponentviews

import tools.aqua.bgw.components.gamecomponentviews.CardView.CardSide
import tools.aqua.bgw.components.gamecomponentviews.CardView.CardSide.BACK
import tools.aqua.bgw.components.gamecomponentviews.CardView.CardSide.FRONT
import tools.aqua.bgw.core.DEFAULT_CARD_HEIGHT
Expand All @@ -44,6 +45,10 @@ import tools.aqua.bgw.visual.Visual
* @param height Height for this [CardView]. Default: [DEFAULT_CARD_HEIGHT].
* @param front Visual to represent the front side of the card.
* @param back Visual to represent the back side of the card. Default: same [Visual] as front.
*
* @see CardSide
*
* @since 0.1
*/
open class CardView(
posX: Number = 0,
Expand All @@ -60,6 +65,7 @@ open class CardView(
*
* @see showFront
* @see showBack
* @see flip
*/
var currentSide: CardSide = FRONT
set(value) {
Expand All @@ -70,7 +76,7 @@ open class CardView(
}
}

/** Front [Visual] for this [CardView]. */
/** Front [Visual] for this [CardView] to be displayed for [CardSide.FRONT]. */
var frontVisual: Visual = Visual.EMPTY
/** Sets front [Visual] for this [CardView] as a copy of given [value]. */
set(value) {
Expand All @@ -79,7 +85,7 @@ open class CardView(
if (currentSide == FRONT) super.visual = field
}

/** Back [Visual] for this [CardView]. */
/** Back [Visual] for this [CardView] to be displayed for [CardSide.BACK]. */
var backVisual: Visual = Visual.EMPTY
/** Sets back [Visual] for this [CardView] as a copy of given [value]. */
set(value) {
Expand Down Expand Up @@ -117,7 +123,11 @@ open class CardView(
currentSide = side
}

/** Flips the [CardView] by seting the [currentSide] to the other value. */
/**
* Flips the [CardView] by seting the [currentSide] to the other value.
*
* @since 0.7.1
*/
fun flip() {
currentSide = if (currentSide == BACK) FRONT else BACK
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import tools.aqua.bgw.observable.lists.ObservableArrayList
import tools.aqua.bgw.visual.Visual

/**
* A [DiceView] may be used to visualize a dice.
* A [DiceView] may be used to visualize a die.
*
* Visualization:
*
Expand All @@ -38,6 +38,8 @@ import tools.aqua.bgw.visual.Visual
* @param width Width for this [DiceView]. Default: [DEFAULT_DICE_WIDTH].
* @param height Height for this [DiceView]. Default: [DEFAULT_DICE_HEIGHT].
* @param visuals List of visuals to represent the sides of the die.
*
* @since 0.1
*/
open class DiceView(
posX: Number = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ sealed class GameComponentView(
) :
DynamicComponentView(
posX = posX, posY = posY, width = width, height = height, visual = visual) {

/** @throws UnsupportedOperationException [GameComponentView] does not support children. */
override fun removeChild(component: ComponentView) {
throw UnsupportedOperationException("This $this component has no children.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,25 @@ import tools.aqua.bgw.visual.Visual
* Default: [DEFAULT_HEXAGON_SIZE].
* @param visual Visual for this [HexagonView].
* @param orientation Orientation of the [HexagonView]. Default: [HexOrientation.POINTY_TOP].
*
* @see HexOrientation
* @see HexagonView
*
* @since 0.8
*/
open class HexagonView(
posX: Number = 0,
posY: Number = 0,
val size: Number = DEFAULT_HEXAGON_SIZE,
visual: Visual,

/**
* Orientation of the [HexagonView].
*
* @see HexOrientation
*
* @since 1.0
*/
var orientation: HexOrientation = HexOrientation.POINTY_TOP
) :
GameComponentView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import tools.aqua.bgw.visual.Visual
* @param width Width for this TokenView. Default: [DEFAULT_TOKEN_WIDTH].
* @param height Height for this TokenView. Default: [DEFAULT_TOKEN_HEIGHT].
* @param visual Visual for this TokenView.
*
* @since 0.1
*/
open class TokenView(
posX: Number = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ import tools.aqua.bgw.observable.properties.StringProperty
* @property offsetX Left bound of sub-image. Default: 0.
* @property offsetY Top bound of sub-image. Default: 0.
*
* @throws IllegalArgumentException If [path] is not a valid path or empty.
* @exception IllegalArgumentException If [path] was not found in resources.
* @throws IllegalArgumentException If [path] is not a valid path or empty or if [path] was not
* found in resources.
*
* @since 1.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,15 @@ publishing {
}
}

spotless {
kotlin {
target("src/*/kotlin/**/*.kt")
defaultFormat(rootProject)
}
}
//spotless {
// kotlin {
// target(rootProject.fileTree("bgw-gui/src") {
// include("**/*.kt")
// exclude("**/Config.kt")
// })
// defaultFormat(rootProject)
// }
//}

// Ignore yarn.lock mismatches
rootProject.plugins.withType(org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin::class.java) {
Expand Down

0 comments on commit 5ab77bd

Please sign in to comment.