fix: fixed several bugs in EventSerializer

This commit is contained in:
Yannik Bretschneider 2021-06-03 15:57:23 +02:00
parent 34dcc75400
commit fa8d8fcd00
2 changed files with 12 additions and 8 deletions

View File

@ -59,6 +59,7 @@ public class EventSerializer extends StdSerializer<Event> {
for (EntityID id : value.turnOrder) { for (EntityID id : value.turnOrder) {
gen.writeObject(id); gen.writeObject(id);
} }
gen.writeEndArray();
gen.writeObjectField("activeCharacter", value.activeCharacter); gen.writeObjectField("activeCharacter", value.activeCharacter);
@ -101,7 +102,7 @@ public class EventSerializer extends StdSerializer<Event> {
gen.writeObjectField("targetField", value.targetField); gen.writeObjectField("targetField", value.targetField);
if (value.type == EventType.UseInfinityStoneEvent || value.type == EventType.ExchangeInfinityStoneEvent) { 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<Event> {
case RoundSetupEvent -> { case RoundSetupEvent -> {
gen.writeNumberField("roundCount", value.roundCount); gen.writeNumberField("roundCount", value.roundCount);
gen.writeFieldName("characterOrder"); gen.writeFieldName("characterOrder");
gen.writeStartArray();
for (EntityID id : value.characterOrder) { for (EntityID id : value.characterOrder) {
gen.writeObject(id); gen.writeObject(id);
} }

View File

@ -147,9 +147,9 @@ public class EventSerializerTest {
CharacterEvent ce = new CharacterEvent(); CharacterEvent ce = new CharacterEvent();
ce.type = EventType.MeleeAttackEvent; 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.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); ce.targetField = new IntVector2(2,2);
var jsonRepresentingEE = """ var jsonRepresentingEE = """
@ -157,7 +157,7 @@ public class EventSerializerTest {
"eventType":"MeleeAttackEvent", "eventType":"MeleeAttackEvent",
"originEntity":{"entityID":"P2","ID":7}, "originEntity":{"entityID":"P2","ID":7},
"targetEntity":{"entityID":"P1","ID":5}, "targetEntity":{"entityID":"P1","ID":5},
"originField":null,"targetField":[2,2] "originField":[1,2],"targetField":[2,2]
}""".replace("\n", ""); }""".replace("\n", "");
// System.out.println(mapper.writeValueAsString(ce)); // System.out.println(mapper.writeValueAsString(ce));
@ -166,9 +166,9 @@ public class EventSerializerTest {
CharacterEvent ce2 = new CharacterEvent(); CharacterEvent ce2 = new CharacterEvent();
ce2.type = EventType.UseInfinityStoneEvent; 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.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.targetField = new IntVector2(2,2);
ce2.stoneType = StoneType.MindStone; ce2.stoneType = StoneType.MindStone;
@ -177,7 +177,9 @@ public class EventSerializerTest {
"eventType":"UseInfinityStoneEvent", "eventType":"UseInfinityStoneEvent",
"originEntity":{"entityID":"P2","ID":7}, "originEntity":{"entityID":"P2","ID":7},
"targetEntity":{"entityID":"P1","ID":5}, "targetEntity":{"entityID":"P1","ID":5},
"originField":null,"targetField":[2,2] "originField":[1,1],
"targetField":[2,2],
"stoneType":{"entityID":"InfinityStones","ID":1}
}""".replace("\n", ""); }""".replace("\n", "");
System.out.println(mapper.writeValueAsString(ce2)); System.out.println(mapper.writeValueAsString(ce2));
@ -211,7 +213,7 @@ public class EventSerializerTest {
"originField":null,"targetField":[2,2] "originField":null,"targetField":[2,2]
}""".replace("\n", ""); }""".replace("\n", "");
System.out.println(mapper.writeValueAsString(ge)); // System.out.println(mapper.writeValueAsString(ge));
// ERROR !!! "Current context not Array but Object" bei characterorder // ERROR !!! "Current context not Array but Object" bei characterorder