Skip to content

Commit a3349f4

Browse files
committed
fix(xml): Add miss move to xml classes
1 parent ac65050 commit a3349f4

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

plugin/src/shared/sc/plugin2020/Move.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import com.thoughtworks.xstream.annotations.XStreamAlias
44
import sc.api.plugins.IMove
55
import sc.plugin2020.util.CubeCoordinates
66

7+
/* NOTE: Remember to add all these classes to classesToRegister in sc/plugin2020/util/Configuration.kt */
8+
79
@XStreamAlias(value = "setmove")
810
data class SetMove(val piece: Piece, val destination: CubeCoordinates): IMove {
911
override fun toString() = String.format("Set %s %s to %s", this.piece.owner, this.piece.type, this.destination)
@@ -15,6 +17,7 @@ data class DragMove(val start: CubeCoordinates, val destination: CubeCoordinates
1517
}
1618

1719
@XStreamAlias(value = "missmove")
18-
data class MissMove(val type: String = "miss"): IMove {
20+
data class MissMove(val _miss: String? = null): IMove {
21+
/* parameter is only there because data classes need at least one constructor parameter */
1922
override fun toString() = "Miss move"
2023
}

plugin/src/shared/sc/plugin2020/util/Configuration.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object Configuration {
1414
@JvmStatic
1515
val classesToRegister: List<Class<*>>
1616
get() = listOf(Game::class.java, Board::class.java,
17-
GameState::class.java, SetMove::class.java, DragMove::class.java,
17+
GameState::class.java, SetMove::class.java, DragMove::class.java, MissMove::class.java,
1818
Direction::class.java, Field::class.java,
1919
WelcomeMessage::class.java, Condition::class.java)
2020

plugin/src/test/sc/plugin2020/GamePlayTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,19 @@ class GamePlayTest {
10931093
assertEquals(expect, packet.data)
10941094
}
10951095

1096+
@Test
1097+
fun xmlToMissMoveTest() {
1098+
val xstream = Configuration.xStream
1099+
val xml = """
1100+
<room roomId="64a0482c-f368-4e33-9684-d5106228bb75">
1101+
<data class="missmove">
1102+
</data>
1103+
</room>"""
1104+
val packet = xstream.fromXML(xml) as RoomPacket
1105+
val expect = MissMove()
1106+
assertEquals(expect, packet.data)
1107+
}
1108+
10961109
@Test
10971110
fun performMoveTest() {
10981111
TestGameUtil.updateGamestateWithBoard(state, "" +

0 commit comments

Comments
 (0)