From 41aad62e8f63a676d36da9ddf46f1ed7c8fd3765 Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Sun, 5 Nov 2023 16:10:12 +0100 Subject: [PATCH] Add json import/export handling of mmFloor and mmBar --- .../kotlin/org/jeudego/pairgoth/model/Pairing.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairing.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairing.kt index b6ebdc2..08e5208 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairing.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairing.kt @@ -307,12 +307,15 @@ fun Pairing.Companion.fromJson(json: Json.Object): Pairing { val placementParams = json.getArray("placement")?.let { PlacementParams.fromJson(it) } ?: defaultParams.placementParams return when (type) { SWISS -> Swiss(pairingParams, placementParams) - MAC_MAHON -> MacMahon(pairingParams, placementParams) + MAC_MAHON -> MacMahon(pairingParams, placementParams).also { mm -> + mm.mmFloor = json.getInt("mmFloor") ?: -20 + mm.mmBar = json.getInt("mmBar") ?: 0 + } ROUND_ROBIN -> RoundRobin(pairingParams, placementParams) } } -fun Pairing.toJson() = Json.Object( +fun Pairing.toJson(): Json.Object = Json.MutableObject( "type" to type.name, "base" to pairingParams.base.toJson(), "main" to pairingParams.main.toJson(), @@ -320,4 +323,9 @@ fun Pairing.toJson() = Json.Object( "geo" to pairingParams.geo.toJson(), "handicap" to pairingParams.handicap.toJson(), "placement" to placementParams.toJson() -) +).also { ret -> + if (this is MacMahon) { + ret["mmFloor"] = mmFloor + ret["mmBar"] = mmBar + } +}