Skip to content

Commit

Permalink
revert: gameplay XML protocol changes
Browse files Browse the repository at this point in the history
  • Loading branch information
xeruf committed Mar 12, 2024
1 parent 2be0211 commit 4d3a95d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
5 changes: 2 additions & 3 deletions plugin/src/main/kotlin/sc/plugin2024/Move.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package sc.plugin2024

import com.thoughtworks.xstream.annotations.XStreamAlias
import com.thoughtworks.xstream.annotations.XStreamImplicit
import sc.api.plugins.IMove

@XStreamAlias("move")
Expand All @@ -13,11 +12,11 @@ import sc.api.plugins.IMove
* @property actions The list of actions in the move.
*/
data class Move(
@XStreamImplicit
//@XStreamImplicit
val actions: List<Action>,
): IMove, Comparable<Move> {

constructor(vararg actions: Action) : this(actions.asList())
constructor(vararg actions: Action) : this(ArrayList(actions.asList()))

/**
* Compares this Move instance with the specified Move for order.
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/kotlin/sc/plugin2024/Segment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ data class Segment(
@XStreamAsAttribute val direction: CubeDirection,
// could be omitted but helpful since ships also come with cubecoords @XStreamOmitField
val center: CubeCoordinates,
@XStreamImplicit(itemFieldName = "column") val fields: SegmentFields,
@XStreamImplicit/*(itemFieldName = "column")*/ val fields: SegmentFields,
): PublicCloneable<Segment> {

val tip: CubeCoordinates
Expand Down
20 changes: 10 additions & 10 deletions plugin/src/test/kotlin/sc/plugin2024/BoardTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,34 +167,34 @@ class BoardTest: FunSpec({
val serializedSegment = """
<segment direction="RIGHT">
<center q="0" r="0" s="0"/>
<column>
<field-array>
<water/>
<water/>
<water/>
<water/>
<water/>
</column>
<column>
</field-array>
<field-array>
<water/>
<water/>
<water/>
<water/>
<water/>
</column>
<column>
</field-array>
<field-array>
<water/>
<water/>
<water/>
<water/>
<water/>
</column>
<column>
</field-array>
<field-array>
<water/>
<water/>
<water/>
<water/>
<water/>
</column>
</field-array>
</segment>"""
val serialized = """
<board nextDirection="RIGHT">$serializedSegment
Expand Down Expand Up @@ -235,13 +235,13 @@ class BoardTest: FunSpec({
<board nextDirection="UP_LEFT">
<segment direction="UP_LEFT">
<center q="1" r="1" s="-2"/>
<column>
<field-array>
<water/>
<goal/>
<island/>
<sandbank/>
<passenger direction="RIGHT" passenger="1"/>
</column>
</field-array>
</segment>
</board>"""
}
Expand Down
6 changes: 4 additions & 2 deletions plugin/src/test/kotlin/sc/plugin2024/GameStateTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,10 @@ class GameStateTest: FunSpec({
<position q="-2" r="1" s="1"/>
</ship>
<lastMove>
<acceleration acc="1"/>
<advance distance="2"/>
<actions>
<acceleration acc="1"/>
<advance distance="2"/>
</actions>
</lastMove>
</state>"""
}
Expand Down
22 changes: 14 additions & 8 deletions plugin/src/test/kotlin/sc/plugin2024/MoveTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,32 @@ class MoveTest: FunSpec({
test("deserializes gracefully") {
testXStream.fromXML("""
<move>
<acceleration acc="1"/>
<advance distance="2"/>
<actions>
<acceleration acc="1"/>
<advance distance="2"/>
</actions>
</move>""".trimIndent()) shouldBe Move(Accelerate(1), Advance(2))
}
test("serializes well") {
Move(Accelerate(2), Advance(2), Turn(CubeDirection.UP_LEFT), Advance(1), Push(CubeDirection.LEFT)) shouldSerializeTo """
<move>
<acceleration acc="2"/>
<advance distance="2"/>
<turn direction="UP_LEFT"/>
<advance distance="1"/>
<push direction="LEFT"/>
<actions>
<acceleration acc="2"/>
<advance distance="2"/>
<turn direction="UP_LEFT"/>
<advance distance="1"/>
<push direction="LEFT"/>
</actions>
</move>
""".trimIndent()
}
test("in RoomPacket") {
RoomPacket("lol", Move(Advance(1))) shouldSerializeTo """
<room roomId="lol">
<data class="move">
<advance distance="1"/>
<actions>
<advance distance="1"/>
</actions>
</data>
</room>
""".trimIndent()
Expand Down

0 comments on commit 4d3a95d

Please sign in to comment.