Skip to content
This repository was archived by the owner on Sep 16, 2025. It is now read-only.

Commit fc35fa5

Browse files
committed
A number of changes and fixes
* Mill upgrade * Hexagon rotation is now odd row (to match legacy) * Legacy web storage now works after a fashion * Rotation is broken - it's unclear why at the moment * Added tests * Fixes CI
1 parent 2625582 commit fc35fa5

File tree

21 files changed

+549
-93
lines changed

21 files changed

+549
-93
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.11.0
1+
0.11.1

VirtualGloomhavenBoard/Indigo/vgb-common/src/vgb/common/BoardOverlayType.scala

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,27 @@ package vgb.common
33
import indigo.*
44

55
enum TreasureChestType:
6+
override def toString(): String = this match {
7+
case Goal => "goal"
8+
case Locked => "locked"
9+
case Normal(i) => i.toString()
10+
}
11+
612
case Normal(val number: Byte) extends TreasureChestType
713
case Goal, Locked
814

15+
object TreasureChestType:
16+
def fromString(str: String) =
17+
str.toLowerCase() match {
18+
case "goal" => Goal
19+
case "locked" => Locked
20+
case _ =>
21+
str.toByteOption match {
22+
case Some(b) => Normal(b)
23+
case None => Normal(0)
24+
}
25+
}
26+
927
trait BoardOverlayType:
1028
val baseGame: BaseGame
1129
val cells: Batch[Point]
@@ -16,7 +34,8 @@ trait BoardOverlayType:
1634
.toCharArray()
1735
.foldLeft("")((s, c) => if c >= '0' && c <= 'Z' then s + " " + c else s + c)
1836
.trim()
19-
val assetName: AssetName = AssetName(s"""${baseGame.shortName}-${name.toLowerCase().replace(" ", "-")}""")
37+
val codedName = name.toLowerCase().replace(" ", "-")
38+
val assetName: AssetName = AssetName(s"""${baseGame.shortName}-${codedName}""")
2039

2140
enum DifficultTerrain(
2241
val baseGame: BaseGame,
@@ -48,16 +67,18 @@ enum Hazard(val baseGame: BaseGame, val cells: Batch[Point]) extends BoardOverla
4867
case HotCoals extends Hazard(BaseGame.Gloomhaven, Batch(Point(0, 0)))
4968
case Thorns extends Hazard(BaseGame.Gloomhaven, Batch(Point(0, 0)))
5069

51-
enum Highlight(val baseGame: BaseGame, val colour: RGB) extends BoardOverlayType:
70+
final case class Highlight(val baseGame: BaseGame, val colour: RGB) extends BoardOverlayType:
5271
val cells: Batch[Point] = Batch(Point(0, 0))
5372
val flag: Flag = Flag.Highlight
5473
val verticalAssetName = None
55-
case Red extends Highlight(BaseGame.Gloomhaven, RGB.Red)
56-
case Orange extends Highlight(BaseGame.Gloomhaven, RGB.Orange)
57-
case Yellow extends Highlight(BaseGame.Gloomhaven, RGB.Yellow)
58-
case Green extends Highlight(BaseGame.Gloomhaven, RGB.Green)
59-
case Blue extends Highlight(BaseGame.Gloomhaven, RGB.Blue)
60-
case Indigo extends Highlight(BaseGame.Gloomhaven, RGB.Indigo)
74+
75+
object Highlight:
76+
val Red = Highlight(BaseGame.Gloomhaven, RGB.Red)
77+
val Orange = Highlight(BaseGame.Gloomhaven, RGB.Orange)
78+
val Yellow = Highlight(BaseGame.Gloomhaven, RGB.Yellow)
79+
val Green = Highlight(BaseGame.Gloomhaven, RGB.Green)
80+
val Blue = Highlight(BaseGame.Gloomhaven, RGB.Blue)
81+
val Indigo = Highlight(BaseGame.Gloomhaven, RGB.Indigo)
6182

6283
enum Obstacle(val baseGame: BaseGame, val cells: Batch[Point]) extends BoardOverlayType:
6384
val flag: Flag = Flag.Obstacle

VirtualGloomhavenBoard/Indigo/vgb-game/src/vgb/game/models/Hexagon.scala renamed to VirtualGloomhavenBoard/Indigo/vgb-common/src/vgb/common/Hexagon.scala

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package vgb.game.models
1+
package vgb.common
22

33
import indigo.shared.datatypes.Point
44
import indigo.shared.datatypes.Vector2
@@ -21,8 +21,8 @@ object Hexagon:
2121
)
2222
}
2323

24-
def screenPosToEvenRow(size: Int, pos: Point) =
25-
axialToEvenRow(screenPosToAxial(size, pos))
24+
def screenPosToOddRow(size: Int, pos: Point) =
25+
axialToOddRow(screenPosToAxial(size, pos))
2626

2727
def axialToScreenPos(size: Int, pos: Vector2) =
2828
val halfSize = size * 0.5;
@@ -31,26 +31,26 @@ object Hexagon:
3131
(halfSize * threeOver2 * pos.y).toInt
3232
)
3333

34-
def evenRowToScreenPos(size: Int, pos: Point) =
35-
axialToScreenPos(size, evenRowToAxial(Vector2.fromPoint(pos)))
34+
def oddRowToScreenPos(size: Int, pos: Point) =
35+
axialToScreenPos(size, oddRowToAxial(Vector2.fromPoint(pos)))
3636

37-
def axialToEvenRow(pos: Vector2) =
37+
def axialToOddRow(pos: Vector2) =
3838
Vector2(
39-
pos.x + (pos.y + (pos.y.toInt & 1)) * 0.5,
39+
pos.x + (pos.y - (pos.y.toInt & 1)) * 0.5,
4040
pos.y
4141
)
4242

43-
def evenRowToAxial(pos: Vector2) =
43+
def oddRowToAxial(pos: Vector2) =
4444
Vector2(
45-
pos.x - (pos.y + (pos.y.toInt & 1)) * 0.5,
45+
pos.x - (pos.y - (pos.y.toInt & 1)) * 0.5,
4646
pos.y
4747
)
4848

49-
def cubeToEvenRow(pos: Vector3) =
50-
Vector2(pos.x + (pos.y + (pos.y.toInt & 1)) * 0.5, pos.y)
49+
def cubeToOddRow(pos: Vector3) =
50+
Vector2(pos.x + (pos.y - (pos.y.toInt & 1)) * 0.5, pos.y)
5151

52-
def evenRowToCube(pos: Vector2) =
53-
val newX = pos.x - (pos.y + (pos.y.toInt & 1)) * 0.5
52+
def oddRowToCube(pos: Vector2) =
53+
val newX = pos.x - (pos.y - (pos.y.toInt & 1)) * 0.5
5454
Vector3(newX, pos.y, -newX - pos.y)
5555

5656
def cubeToAxial(pos: Vector3) =
@@ -74,22 +74,22 @@ object Hexagon:
7474
else Vector3(q, r, -q - r)
7575
}
7676

77-
def evenRowRotate(origin: Vector2, rotationPoint: Vector2, numTurns: Byte): Vector2 =
78-
val rotateResult = evenRowSingleRotate(origin, rotationPoint)
77+
def oddRowRotate(origin: Vector2, rotationPoint: Vector2, numTurns: Byte): Vector2 =
78+
val rotateResult = oddRowSingleRotate(origin, rotationPoint)
7979
numTurns match
8080
case 0 => origin
8181
case 1 => rotateResult
8282
case other if other < 0 =>
83-
evenRowRotate(rotateResult, rotationPoint, (other + 1).toByte)
83+
oddRowRotate(rotateResult, rotationPoint, (other + 1).toByte)
8484
case other =>
85-
evenRowRotate(rotateResult, rotationPoint, (other - 1).toByte)
85+
oddRowRotate(rotateResult, rotationPoint, (other - 1).toByte)
8686

87-
def evenRowSingleRotate(origin: Vector2, rotationPoint: Vector2): Vector2 =
88-
val (originX, originY, originZ) = evenRowToCube(origin) match
87+
def oddRowSingleRotate(origin: Vector2, rotationPoint: Vector2): Vector2 =
88+
val (originX, originY, originZ) = oddRowToCube(origin) match
8989
case v => (v.x, v.y, v.z)
90-
val (rotateX, rotateY, rotateZ) = evenRowToCube(rotationPoint) match
90+
val (rotateX, rotateY, rotateZ) = oddRowToCube(rotationPoint) match
9191
case v => (v.x, v.y, v.z)
9292
val (rX, rY, rZ) =
9393
(-(originY - rotateY), -(originZ - rotateZ), -(originX - rotateX))
9494

95-
cubeToEvenRow(Vector3(rX + rotateX, rY + rotateY, rZ + rotateZ))
95+
cubeToOddRow(Vector3(rX + rotateX, rY + rotateY, rZ + rotateZ))

VirtualGloomhavenBoard/Indigo/vgb-common/src/vgb/common/MonsterLevel.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@ package vgb.common
22

33
enum MonsterLevel:
44
case None, Normal, Elite
5+
6+
object MonsterLevel:
7+
def fromString(str: String) =
8+
MonsterLevel.values
9+
.find(l => l.toString().toLowerCase() == str)
10+
.getOrElse(None)

VirtualGloomhavenBoard/Indigo/vgb-common/src/vgb/common/RoomType.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ enum RoomType(val baseGame: BaseGame, val mapRef: String, val offset: Point, val
1111
"a1a",
1212
Point(-13, -34),
1313
Batch(
14-
Point(0, 0),
15-
Point(1, 0),
16-
Point(2, 0),
17-
Point(3, 0),
1814
Point(0, 1),
1915
Point(1, 1),
2016
Point(2, 1),
2117
Point(3, 1),
22-
Point(4, 1)
18+
Point(0, 2),
19+
Point(1, 2),
20+
Point(2, 2),
21+
Point(3, 2),
22+
Point(4, 2)
2323
),
2424
Size(432, 244)
2525
)
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package vgb.common
2+
3+
import indigo.shared.datatypes.Vector2
4+
5+
class HexagonTests extends munit.FunSuite {
6+
7+
test("should rotate (0, 2) 0 turn around 0, 0") {
8+
assertEquals(
9+
Vector2(0, 2),
10+
Hexagon.oddRowRotate(Vector2(0, 2), Vector2(0, 0), 0)
11+
)
12+
}
13+
14+
test("should rotate (0, 2) 1 turn around 0, 0") {
15+
assertEquals(
16+
Vector2(-2, 1),
17+
Hexagon.oddRowRotate(Vector2(0, 2), Vector2(0, 0), 1)
18+
)
19+
}
20+
21+
test("should rotate (-1, 0) 1 turns around 0, 0") {
22+
assertEquals(
23+
Vector2(-1, -1),
24+
Hexagon.oddRowRotate(Vector2(-1, 0), Vector2(0, 0), 1)
25+
)
26+
}
27+
28+
test("should rotate (0, 1) 6 turns around 0, 0") {
29+
assertEquals(
30+
Vector2(0, 1),
31+
Hexagon.oddRowRotate(Vector2(0, 1), Vector2(0, 0), 6)
32+
)
33+
}
34+
35+
test("should rotate (0, 1) 5 turns around 0, 0") {
36+
assertEquals(
37+
Vector2(1, 0),
38+
Hexagon.oddRowRotate(Vector2(0, 1), Vector2(0, 0), 5)
39+
)
40+
}
41+
42+
test("should rotate (0, 1) 4 turns around 0, 0") {
43+
assertEquals(
44+
Vector2(0, -1),
45+
Hexagon.oddRowRotate(Vector2(0, 1), Vector2(0, 0), 4)
46+
)
47+
}
48+
49+
test("should rotate (0, 1) 3 turns around 0, 0") {
50+
assertEquals(
51+
Vector2(-1, -1),
52+
Hexagon.oddRowRotate(Vector2(0, 1), Vector2(0, 0), 3)
53+
)
54+
}
55+
56+
test("should rotate (0, 1) 2 turns around 0, 0") {
57+
assertEquals(
58+
Vector2(-1, 0),
59+
Hexagon.oddRowRotate(Vector2(0, 1), Vector2(0, 0), 2)
60+
)
61+
}
62+
63+
test("should rotate (0, 1) 1 turn around 0, 0") {
64+
assertEquals(
65+
Vector2(-1, 1),
66+
Hexagon.oddRowRotate(Vector2(0, 1), Vector2(0, 0), 1)
67+
)
68+
}
69+
70+
test("should rotate (0, 2) 1 turn around 0, 3") {
71+
assertEquals(
72+
Vector2(1, 2),
73+
Hexagon.oddRowRotate(Vector2(0, 2), Vector2(0, 3), 1)
74+
)
75+
}
76+
77+
test("should rotate (0, 2) 3 turns around 0, 3") {
78+
assertEquals(
79+
Vector2(1, 4),
80+
Hexagon.oddRowRotate(Vector2(0, 2), Vector2(0, 3), 3)
81+
)
82+
}
83+
84+
test("should rotate (-1, 6) 1 turn around 0, 6") {
85+
assertEquals(
86+
Vector2(-1, 5),
87+
Hexagon.oddRowRotate(Vector2(-1, 6), Vector2(0, 6), 1)
88+
)
89+
90+
}
91+
}

VirtualGloomhavenBoard/Indigo/vgb-game/src/vgb/game/models/BoardOverlay.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package vgb.game.models
22

33
import indigo.*
44
import vgb.common.BoardOverlayType
5+
import vgb.common.Hexagon
56
import vgb.common.RoomType
67

78
final case class BoardOverlay(
@@ -17,7 +18,7 @@ final case class BoardOverlay(
1718

1819
def rotate() =
1920
val rotatedOrigin =
20-
Hexagon.evenRowRotate(Vector2.fromPoint(origin), Vector2.fromPoint(rotationPoint), 1)
21+
Hexagon.oddRowRotate(Vector2.fromPoint(origin), Vector2.fromPoint(rotationPoint), 1)
2122

2223
this.copy(
2324
origin = rotatedOrigin.toPoint,

VirtualGloomhavenBoard/Indigo/vgb-game/src/vgb/game/models/Placeable.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package vgb.game.models
22

33
import indigo.*
4+
import vgb.common.Hexagon
45

56
trait Placeable:
67
val rotation: TileRotation
@@ -14,7 +15,7 @@ trait Placeable:
1415

1516
def localToWorld(localPoint: Point) =
1617
val rotatedPoint = Hexagon
17-
.evenRowRotate(
18+
.oddRowRotate(
1819
Vector2.fromPoint(localPoint),
1920
Vector2.fromPoint(minPoint),
2021
rotation.toByte()

VirtualGloomhavenBoard/Indigo/vgb-game/src/vgb/game/models/Room.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package vgb.game.models
22

33
import indigo.*
4+
import vgb.common.Hexagon
45
import vgb.common.RoomType
56

67
final case class Room(
@@ -14,7 +15,7 @@ final case class Room(
1415

1516
def rotate() =
1617
val rotatedOrigin =
17-
Hexagon.evenRowRotate(Vector2.fromPoint(origin), Vector2.fromPoint(rotationPoint), 1)
18+
Hexagon.oddRowRotate(Vector2.fromPoint(origin), Vector2.fromPoint(rotationPoint), 1)
1819
this.copy(
1920
origin = rotatedOrigin.toPoint,
2021
rotation = rotation.nextRotation(false)

VirtualGloomhavenBoard/Indigo/vgb-game/src/vgb/game/models/TileRotation.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,10 @@ object TileRotation:
5252
case "diagonal-right-reverse" => DiagonalRightReverse
5353
case _ => Default
5454
}
55+
56+
def fromByte(i: Byte) =
57+
TileRotation.values
58+
// We can't discern vertical just from the byte, so don't try
59+
.filter(t => t != Vertical && t != VerticalReverse)
60+
.find(t => t.toByte() == i)
61+
.getOrElse(Default)

0 commit comments

Comments
 (0)