Skip to content

Commit

Permalink
Added HexOrientation
Browse files Browse the repository at this point in the history
  • Loading branch information
smilefx committed Nov 26, 2024
1 parent 73c55db commit ebf4cb2
Show file tree
Hide file tree
Showing 35 changed files with 403 additions and 451 deletions.
2 changes: 2 additions & 0 deletions bgw-gui/src/commonMain/kotlin/PropData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ class DiceViewData : GameComponentViewData() {
@Serializable
class HexagonViewData : GameComponentViewData() {
var size: Int = 0
var orientation: String = ""
}
@Serializable
class TokenViewData : GameComponentViewData() { }
Expand All @@ -258,6 +259,7 @@ class HexagonGridData : GameComponentContainerData() {
var coordinateSystem: String = ""
var map : Map<String, HexagonViewData> = emptyMap()
var spacing : Int = 0
var orientation: String = ""
}
@Serializable
class LinearLayoutData: GameComponentContainerData() {
Expand Down
2 changes: 2 additions & 0 deletions bgw-gui/src/jsMain/kotlin/tools/aqua/bgw/ReactDND.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ external fun useDroppable(options: DroppableOptions): DroppableResult

external interface DraggableOptions {
var id: String
var disabled: Boolean
}

external interface DraggableResult {
Expand Down Expand Up @@ -92,6 +93,7 @@ external interface DragEndEventOver {

external interface DroppableOptions {
var id: String
var disabled: Boolean
}

external interface DroppableResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import tools.aqua.bgw.elements.Scene as ReactScene
object SceneBuilder {

fun build(scene: SceneData): ReactElement<*> {
return ReactScene.create { data = scene }
return ReactScene.create { data = scene }
}
}
13 changes: 9 additions & 4 deletions bgw-gui/src/jsMain/kotlin/tools/aqua/bgw/elements/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,15 @@ val App = FC<AppProps> { props ->
opacity = number(0.0)
backdropFilter = blur(0.px)
}
"bgw_hexagon_view" {

"bgw_hexagon_view[aria-details='hex-pointy_top']" {
clipPath = polygonPath("0% 25%, 0% 75%, 50% 100%, 100% 75%, 100% 25%, 50% 0%")
}

"bgw_hexagon_view[aria-details='hex-flat_top']" {
clipPath = polygonPath("25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%")
}

"bgw_menu_scene.scene--visible > bgw_scene" {
opacity = number(1.0)
backdropFilter = blur(DEFAULT_BLUR_RADIUS.em)
Expand Down Expand Up @@ -291,7 +296,7 @@ val App = FC<AppProps> { props ->
left = 4.em
width = 30.em
height = 18.em
backgroundColor = rgb(145,145,145)
backgroundColor = rgb(145, 145, 145)
transition = transition(300, "background-color")
borderRadius = 3.em
}
Expand All @@ -309,7 +314,7 @@ val App = FC<AppProps> { props ->
}

"bgw_togglebutton > input[type='checkbox']:checked + .toggle" {
backgroundColor = rgb(0,117,255)
backgroundColor = rgb(0, 117, 255)
}

"bgw_togglebutton > input[type='checkbox']:checked + .toggle::before" {
Expand Down Expand Up @@ -394,7 +399,6 @@ val App = FC<AppProps> { props ->
}

onDragEnd = { event ->
console.log(event.over)
if(event.over != null) {
JCEFEventDispatcher.dispatchEvent(event.toDragEventData())
}
Expand Down Expand Up @@ -469,6 +473,7 @@ val App = FC<AppProps> { props ->
}
}
}

inline val bgwScenes: IntrinsicType<HTMLAttributes<Element>>
get() = "bgw_scenes".unsafeCast<IntrinsicType<HTMLAttributes<Element>>>()
inline val bgwMenuScene: IntrinsicType<HTMLAttributes<Element>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,12 @@ fun PropertiesBuilder.cssBuilderIntern(componentViewData: AreaData) {
}

val Area = FC<AreaProps> { props ->
var droppable : DroppableResult? = null
val droppable = useDroppable(object : DroppableOptions {
override var id: String = props.data.id
override var disabled = !props.data.isDroppable
})

if(props.data.isDroppable) {
droppable = useDroppable(object : DroppableOptions {
override var id: String = props.data.id
})
}

val dropRef = useRef<Element>(null)
val elementRef = useRef<Element>(null)

bgwArea {
id = props.data.id
Expand All @@ -57,11 +54,9 @@ val Area = FC<AreaProps> { props ->
cssBuilderIntern(props.data)
}

if(props.data.isDroppable) {
ref = dropRef
useEffect {
dropRef.current?.let { droppable!!.setNodeRef(it) }
}
ref = elementRef
useEffect {
elementRef.current?.let { droppable.setNodeRef(it) }
}

bgwVisuals {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ fun PropertiesBuilder.cssBuilderIntern(componentViewData: CardStackData) {
}

val CardStack = FC<CardStackProps> { props ->
var droppable : DroppableResult? = null

if(props.data.isDroppable) {
droppable = useDroppable(object : DroppableOptions {
override var id: String = props.data.id
})
}
val droppable = useDroppable(object : DroppableOptions {
override var id: String = props.data.id
override var disabled = !props.data.isDroppable
})

val elementRef = useRef<Element>(null)

Expand All @@ -52,11 +49,9 @@ val CardStack = FC<CardStackProps> { props ->
cssBuilderIntern(props.data)
}

if(props.data.isDroppable) {
ref = elementRef
useEffect {
elementRef.current?.let { droppable!!.setNodeRef(it) }
}
ref = elementRef
useEffect {
elementRef.current?.let { droppable.setNodeRef(it) }
}

bgwVisuals {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,10 @@ fun PropertiesBuilder.cssBuilderIntern(componentViewData: HexagonGridData) {
}

val HexagonGrid = FC<HexagonGridProps> { props ->
var droppable : DroppableResult? = null

if(props.data.isDroppable) {
droppable = useDroppable(object : DroppableOptions {
override var id: String = props.data.id
})
}
val droppable = useDroppable(object : DroppableOptions {
override var id: String = props.data.id
override var disabled = !props.data.isDroppable
})

val elementRef = useRef<Element>(null)

Expand All @@ -63,11 +60,9 @@ val HexagonGrid = FC<HexagonGridProps> { props ->
cssBuilderIntern(props.data)
}

if(props.data.isDroppable) {
ref = elementRef
useEffect {
elementRef.current?.let { droppable!!.setNodeRef(it) }
}
ref = elementRef
useEffect {
elementRef.current?.let { droppable.setNodeRef(it) }
}

bgwVisuals {
Expand All @@ -84,69 +79,137 @@ val HexagonGrid = FC<HexagonGridProps> { props ->
var maxY = 0.0

props.data.map.forEach {
if(props.data.coordinateSystem == "offset") {
bgwHexagonContent {
val size = it.value.size
val w = (size * sqrt(3.0)).toString().substring(0, 3).toDouble()
val h = 2 * size
val q = it.key.split("/")[0].toInt()
val r = it.key.split("/")[1].toInt()

val x = if(r % 2 == 0)
w * q + props.data.spacing * (q - 1)
else
w * q + props.data.spacing * (q - 1) + w / 2

val y = h * 0.75 * r + props.data.spacing * (r - 1)

if(x < minX)
minX = x
if(x + w > maxX)
maxX = x + w
if(y < minY)
minY = y
if(y + h > maxY)
maxY = y + h

css {
position = Position.absolute
left = x.em
top = y.em
if(props.data.orientation == "pointy_top") {
if (props.data.coordinateSystem == "offset") {
bgwHexagonContent {
val size = it.value.size
val w = (size * sqrt(3.0)).toString().substring(0, 3).toDouble()
val h = 2 * size
val q = it.key.split("/")[0].toInt()
val r = it.key.split("/")[1].toInt()

val x = if (r % 2 == 0)
w * q + props.data.spacing * (q - 1)
else
w * q + props.data.spacing * (q - 1) + w / 2

val y = h * 0.75 * r + props.data.spacing * (r - 1)

if (x < minX)
minX = x
if (x + w > maxX)
maxX = x + w
if (y < minY)
minY = y
if (y + h > maxY)
maxY = y + h

css {
position = Position.absolute
left = x.em
top = y.em
}
+NodeBuilder.build(it.value)
}
} else {
bgwHexagonContent {
val size = it.value.size
val w = (size * sqrt(3.0)).toString().substring(0, 3).toDouble()
val h = 2 * size
var q = it.key.split("/")[0].toInt()
var r = it.key.split("/")[1].toInt()

q = q + (r - (r and 1)) / 2

val x = if (r % 2 == 0)
w * q + props.data.spacing * (q - 1)
else
w * q + props.data.spacing * (q - 1) + w / 2

val y = h * 0.75 * r + props.data.spacing * (r - 1)

if (x < minX)
minX = x
if (x + w > maxX)
maxX = x + w
if (y < minY)
minY = y
if (y + h > maxY)
maxY = y + h

css {
position = Position.absolute
left = x.em
top = y.em
}
+NodeBuilder.build(it.value)
}
+NodeBuilder.build(it.value)
}
} else {
bgwHexagonContent {
val size = it.value.size
val w = (size * sqrt(3.0)).toString().substring(0, 3).toDouble()
val h = 2 * size
var q = it.key.split("/")[0].toInt()
var r = it.key.split("/")[1].toInt()

q = q + (r - (r and 1)) / 2

val x = if(r % 2 == 0)
w * q + props.data.spacing * (q - 1)
else
w * q + props.data.spacing * (q - 1) + w / 2

val y = h * 0.75 * r + props.data.spacing * (r - 1)

if(x < minX)
minX = x
if(x + w > maxX)
maxX = x + w
if(y < minY)
minY = y
if(y + h > maxY)
maxY = y + h

css {
position = Position.absolute
left = x.em
top = y.em
if (props.data.coordinateSystem == "offset") {
bgwHexagonContent {
val size = it.value.size
val w = 2 * size
val h = (size * sqrt(3.0)).toString().substring(0, 3).toDouble()
val q = it.key.split("/")[0].toInt()
val r = it.key.split("/")[1].toInt()

val x = w * 0.75 * q + props.data.spacing * (q - 1)

val y = if (q % 2 == 0)
h * r + props.data.spacing * (r - 1)
else
h * r + props.data.spacing * (r - 1) + h / 2

if (x < minX)
minX = x.toDouble()
if (x + w > maxX)
maxX = (x + w).toDouble()
if (y < minY)
minY = y
if (y + h > maxY)
maxY = y + h

css {
position = Position.absolute
left = x.em
top = y.em
}
+NodeBuilder.build(it.value)
}
} else {
bgwHexagonContent {
val size = it.value.size
val w = 2 * size
val h = (size * sqrt(3.0)).toString().substring(0, 3).toDouble()
var q = it.key.split("/")[0].toInt()
var r = it.key.split("/")[1].toInt()

r = r + (q - (q and 1)) / 2

val x = w * 0.75 * q + props.data.spacing * (q - 1)

val y = if (q % 2 == 0)
h * r + props.data.spacing * (r - 1)
else
h * r + props.data.spacing * (r - 1) + h / 2

if (x < minX)
minX = x
if (x + w > maxX)
maxX = x + w
if (y < minY)
minY = y
if (y + h > maxY)
maxY = y + h

css {
position = Position.absolute
left = x.em
top = y.em
}
+NodeBuilder.build(it.value)
}
+NodeBuilder.build(it.value)
}
}
css {
Expand Down
Loading

0 comments on commit ebf4cb2

Please sign in to comment.