Skip to content

Commit

Permalink
fix(plugin24): ship deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
xeruf committed Aug 8, 2023
1 parent 8ffcf89 commit f2bf189
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
16 changes: 8 additions & 8 deletions plugin/src/main/kotlin/sc/plugin2024/Ship.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ data class Ship(
@XStreamAsAttribute var speed: Int = 1,
@XStreamAsAttribute var coal: Int = START_COAL,
@XStreamAsAttribute var passengers: Int = 0,
@XStreamOmitField var movement: Int = 1,
@XStreamOmitField var freeTurns: Int = 1,
@XStreamAsAttribute var freeTurns: Int = 1,
@XStreamOmitField var movement: Int = speed,
@XStreamOmitField var freeAcc: Int = 1,
): PublicCloneable<Ship> {
override fun clone(): Ship {
return this.copy(
position = this.position.copy(),
team = this.team,
direction = this.direction
)
override fun clone(): Ship =
this.copy()
fun readResolve(): Ship {
freeAcc = 1
movement = speed
return this
}
}
2 changes: 1 addition & 1 deletion plugin/src/main/kotlin/sc/plugin2024/actions/Push.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ data class Push(
}

else -> {
nudgedShip.freeTurns += 1
nudgedShip.position = pushResult.shiftTo
nudgedShip.freeTurns++
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions plugin/src/test/kotlin/sc/plugin2024/ShipTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.*
import sc.api.plugins.CubeCoordinates
import sc.api.plugins.Team
import sc.helpers.shouldSerializeTo

class ShipTest: FunSpec({
val shipOne = Ship(CubeCoordinates(-1, -1), Team.ONE)
test("hashcode differs upon change") {
val shipOneMoved = shipOne.copy(CubeCoordinates.ORIGIN)
shipOne shouldNotBe shipOneMoved
shipOne.hashCode() shouldNotBe shipOneMoved.hashCode()
}
test("serializes nicely") {
val xStream = XStream().apply {
processAnnotations(Ship::class.java)
XStream.setupDefaultSecurity(this)
allowTypesByWildcard(arrayOf("sc.plugin2024.actions.*"))
}

val serialized = xStream.toXML(Ship(CubeCoordinates.ORIGIN, Team.ONE))

serialized shouldBe """<ship team="ONE" points="0" direction="RIGHT" speed="1" coal="6" passengers="0">
<position q="0" r="0" s="0"/>
</ship>"""
shipOne shouldSerializeTo """
<ship team="ONE" points="0" direction="RIGHT" speed="1" coal="6" passengers="0" freeTurns="1">
<position q="-1" r="-1" s="2"/>
</ship>"""
}
})

0 comments on commit f2bf189

Please sign in to comment.