Skip to content

Commit

Permalink
fix(xml): Add miss move to xml classes
Browse files Browse the repository at this point in the history
  • Loading branch information
SKoschnicke committed Sep 23, 2019
1 parent ac65050 commit a3349f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 4 additions & 1 deletion plugin/src/shared/sc/plugin2020/Move.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.thoughtworks.xstream.annotations.XStreamAlias
import sc.api.plugins.IMove
import sc.plugin2020.util.CubeCoordinates

/* NOTE: Remember to add all these classes to classesToRegister in sc/plugin2020/util/Configuration.kt */

@XStreamAlias(value = "setmove")
data class SetMove(val piece: Piece, val destination: CubeCoordinates): IMove {
override fun toString() = String.format("Set %s %s to %s", this.piece.owner, this.piece.type, this.destination)
Expand All @@ -15,6 +17,7 @@ data class DragMove(val start: CubeCoordinates, val destination: CubeCoordinates
}

@XStreamAlias(value = "missmove")
data class MissMove(val type: String = "miss"): IMove {
data class MissMove(val _miss: String? = null): IMove {
/* parameter is only there because data classes need at least one constructor parameter */
override fun toString() = "Miss move"
}
2 changes: 1 addition & 1 deletion plugin/src/shared/sc/plugin2020/util/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object Configuration {
@JvmStatic
val classesToRegister: List<Class<*>>
get() = listOf(Game::class.java, Board::class.java,
GameState::class.java, SetMove::class.java, DragMove::class.java,
GameState::class.java, SetMove::class.java, DragMove::class.java, MissMove::class.java,
Direction::class.java, Field::class.java,
WelcomeMessage::class.java, Condition::class.java)

Expand Down
13 changes: 13 additions & 0 deletions plugin/src/test/sc/plugin2020/GamePlayTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,19 @@ class GamePlayTest {
assertEquals(expect, packet.data)
}

@Test
fun xmlToMissMoveTest() {
val xstream = Configuration.xStream
val xml = """
<room roomId="64a0482c-f368-4e33-9684-d5106228bb75">
<data class="missmove">
</data>
</room>"""
val packet = xstream.fromXML(xml) as RoomPacket
val expect = MissMove()
assertEquals(expect, packet.data)
}

@Test
fun performMoveTest() {
TestGameUtil.updateGamestateWithBoard(state, "" +
Expand Down

0 comments on commit a3349f4

Please sign in to comment.