From fa8d8fcd005542d88a93ed4d456b86e5aed820a2 Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Thu, 3 Jun 2021 15:57:23 +0200 Subject: [PATCH] fix: fixed several bugs in EventSerializer --- .../json/ingame/serialize/EventSerializer.java | 4 +++- .../ingame/serialize/EventSerializerTest.java | 16 +++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EventSerializer.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EventSerializer.java index cf84c94..3654102 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EventSerializer.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EventSerializer.java @@ -59,6 +59,7 @@ public class EventSerializer extends StdSerializer { for (EntityID id : value.turnOrder) { gen.writeObject(id); } + gen.writeEndArray(); gen.writeObjectField("activeCharacter", value.activeCharacter); @@ -101,7 +102,7 @@ public class EventSerializer extends StdSerializer { gen.writeObjectField("targetField", value.targetField); if (value.type == EventType.UseInfinityStoneEvent || value.type == EventType.ExchangeInfinityStoneEvent) { - gen.writeObject(new EntityID(EntityType.InfinityStones, value.stoneType.getID())); + gen.writeObjectField("stoneType", new EntityID(EntityType.InfinityStones, value.stoneType.getID())); } } @@ -114,6 +115,7 @@ public class EventSerializer extends StdSerializer { case RoundSetupEvent -> { gen.writeNumberField("roundCount", value.roundCount); gen.writeFieldName("characterOrder"); + gen.writeStartArray(); for (EntityID id : value.characterOrder) { gen.writeObject(id); } diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EventSerializerTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EventSerializerTest.java index c541660..bf94564 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EventSerializerTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EventSerializerTest.java @@ -147,9 +147,9 @@ public class EventSerializerTest { CharacterEvent ce = new CharacterEvent(); ce.type = EventType.MeleeAttackEvent; - ce.targetEntity = new EntityID(EntityType.P1,5); - ce.targetField = new IntVector2(1,1); ce.originEntity = new EntityID(EntityType.P2,7); + ce.targetEntity = new EntityID(EntityType.P1,5); + ce.originField = new IntVector2(1,2); ce.targetField = new IntVector2(2,2); var jsonRepresentingEE = """ @@ -157,7 +157,7 @@ public class EventSerializerTest { "eventType":"MeleeAttackEvent", "originEntity":{"entityID":"P2","ID":7}, "targetEntity":{"entityID":"P1","ID":5}, - "originField":null,"targetField":[2,2] + "originField":[1,2],"targetField":[2,2] }""".replace("\n", ""); // System.out.println(mapper.writeValueAsString(ce)); @@ -166,9 +166,9 @@ public class EventSerializerTest { CharacterEvent ce2 = new CharacterEvent(); ce2.type = EventType.UseInfinityStoneEvent; - ce2.targetEntity = new EntityID(EntityType.P1,5); - ce2.targetField = new IntVector2(1,1); ce2.originEntity = new EntityID(EntityType.P2,7); + ce2.targetEntity = new EntityID(EntityType.P1,5); + ce2.originField = new IntVector2(1,1); ce2.targetField = new IntVector2(2,2); ce2.stoneType = StoneType.MindStone; @@ -177,7 +177,9 @@ public class EventSerializerTest { "eventType":"UseInfinityStoneEvent", "originEntity":{"entityID":"P2","ID":7}, "targetEntity":{"entityID":"P1","ID":5}, - "originField":null,"targetField":[2,2] + "originField":[1,1], + "targetField":[2,2], + "stoneType":{"entityID":"InfinityStones","ID":1} }""".replace("\n", ""); System.out.println(mapper.writeValueAsString(ce2)); @@ -211,7 +213,7 @@ public class EventSerializerTest { "originField":null,"targetField":[2,2] }""".replace("\n", ""); - System.out.println(mapper.writeValueAsString(ge)); + // System.out.println(mapper.writeValueAsString(ge)); // ERROR !!! "Current context not Array but Object" bei characterorder