From a3349f46388f65fba4422b5d784ff453100d6ea3 Mon Sep 17 00:00:00 2001 From: Sven Koschnicke Date: Mon, 23 Sep 2019 11:10:04 +0200 Subject: [PATCH] fix(xml): Add miss move to xml classes --- plugin/src/shared/sc/plugin2020/Move.kt | 5 ++++- .../src/shared/sc/plugin2020/util/Configuration.kt | 2 +- plugin/src/test/sc/plugin2020/GamePlayTest.kt | 13 +++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/plugin/src/shared/sc/plugin2020/Move.kt b/plugin/src/shared/sc/plugin2020/Move.kt index 1880ba331..df651e317 100644 --- a/plugin/src/shared/sc/plugin2020/Move.kt +++ b/plugin/src/shared/sc/plugin2020/Move.kt @@ -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) @@ -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" } diff --git a/plugin/src/shared/sc/plugin2020/util/Configuration.kt b/plugin/src/shared/sc/plugin2020/util/Configuration.kt index 7a125cd20..624fa10e3 100644 --- a/plugin/src/shared/sc/plugin2020/util/Configuration.kt +++ b/plugin/src/shared/sc/plugin2020/util/Configuration.kt @@ -14,7 +14,7 @@ object Configuration { @JvmStatic val classesToRegister: List> 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) diff --git a/plugin/src/test/sc/plugin2020/GamePlayTest.kt b/plugin/src/test/sc/plugin2020/GamePlayTest.kt index 8446e7e83..afc3fdb6b 100644 --- a/plugin/src/test/sc/plugin2020/GamePlayTest.kt +++ b/plugin/src/test/sc/plugin2020/GamePlayTest.kt @@ -1093,6 +1093,19 @@ class GamePlayTest { assertEquals(expect, packet.data) } + @Test + fun xmlToMissMoveTest() { + val xstream = Configuration.xStream + val xml = """ + + + + """ + val packet = xstream.fromXML(xml) as RoomPacket + val expect = MissMove() + assertEquals(expect, packet.data) + } + @Test fun performMoveTest() { TestGameUtil.updateGamestateWithBoard(state, "" +