From 445bde1105441879f34b05285f30b3c74a01f6a8 Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Thu, 3 Jun 2021 22:58:25 +0200 Subject: [PATCH] feat: added (mostly redundant) Json annotations to Events and Requests --- .../marvelous/gamelibrary/events/CharacterEvent.java | 6 ++++++ .../teamname/marvelous/gamelibrary/events/CustomEvent.java | 7 +++++++ .../teamname/marvelous/gamelibrary/events/EntityEvent.java | 6 ++++++ .../teamname/marvelous/gamelibrary/events/GameEvent.java | 6 ++++++ .../marvelous/gamelibrary/events/GamestateEvent.java | 6 ++++++ .../marvelous/gamelibrary/requests/CharacterRequest.java | 6 ++++++ .../marvelous/gamelibrary/requests/GameRequest.java | 7 +++++++ 7 files changed, 44 insertions(+) diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/CharacterEvent.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/CharacterEvent.java index 48dba8f..a2d8d44 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/CharacterEvent.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/CharacterEvent.java @@ -1,14 +1,20 @@ package uulm.teamname.marvelous.gamelibrary.events; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import uulm.teamname.marvelous.gamelibrary.IntVector2; import uulm.teamname.marvelous.gamelibrary.entities.EntityID; import uulm.teamname.marvelous.gamelibrary.entities.StoneType; +import uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize.EventDeserializer; +import uulm.teamname.marvelous.gamelibrary.json.ingame.serialize.EventSerializer; import java.util.Objects; /** * Represents a character event for: {@link EventType#MeleeAttackEvent}, {@link EventType#RangedAttackEvent}, {@link EventType#MoveEvent}, {@link EventType#ExchangeInfinityStoneEvent}, {@link EventType#UseInfinityStoneEvent}. */ +@JsonDeserialize(using = EventDeserializer.class) +@JsonSerialize(using = EventSerializer.class) public class CharacterEvent extends Event { public EntityID originEntity = null; public EntityID targetEntity = null; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/CustomEvent.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/CustomEvent.java index d79125a..f7f99c9 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/CustomEvent.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/CustomEvent.java @@ -1,9 +1,16 @@ package uulm.teamname.marvelous.gamelibrary.events; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize.EventDeserializer; +import uulm.teamname.marvelous.gamelibrary.json.ingame.serialize.EventSerializer; + import java.util.HashMap; import java.util.Objects; /** Represents a custom event ({@link EventType#CustomEvent}). */ +@JsonDeserialize(using = EventDeserializer.class) +@JsonSerialize(using = EventSerializer.class) public class CustomEvent extends Event { public String teamIdentifier; public HashMap customContent; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/EntityEvent.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/EntityEvent.java index da77417..f14e68e 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/EntityEvent.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/EntityEvent.java @@ -1,12 +1,18 @@ package uulm.teamname.marvelous.gamelibrary.events; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import uulm.teamname.marvelous.gamelibrary.IntVector2; import uulm.teamname.marvelous.gamelibrary.entities.Entity; import uulm.teamname.marvelous.gamelibrary.entities.EntityID; +import uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize.EventDeserializer; +import uulm.teamname.marvelous.gamelibrary.json.ingame.serialize.EventSerializer; import java.util.Objects; /** Represents an entity event for: {@link EventType#DestroyedEntityEvent}, {@link EventType#TakenDamageEvent}, {@link EventType#ConsumedAPEvent}, {@link EventType#ConsumedMPEvent}, {@link EventType#SpawnEntityEvent}, {@link EventType#HealedEvent}. */ +@JsonDeserialize(using = EventDeserializer.class) +@JsonSerialize(using = EventSerializer.class) public class EntityEvent extends Event { public EntityID targetEntity = null; public IntVector2 targetField = null; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/GameEvent.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/GameEvent.java index f149918..49ada71 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/GameEvent.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/GameEvent.java @@ -1,11 +1,17 @@ package uulm.teamname.marvelous.gamelibrary.events; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import uulm.teamname.marvelous.gamelibrary.entities.EntityID; +import uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize.EventDeserializer; +import uulm.teamname.marvelous.gamelibrary.json.ingame.serialize.EventSerializer; import java.util.Arrays; import java.util.Objects; /** Represents a game event for: {@link EventType#RoundSetupEvent}, {@link EventType#TurnEvent}, {@link EventType#WinEvent}, {@link EventType#TurnTimeoutEvent}, {@link EventType#TimeoutWarningEvent}, {@link EventType#TimeoutEvent}, {@link EventType#PauseStartEvent}, {@link EventType#PauseStopEvent}, {@link EventType#DisconnectEvent}. */ +@JsonDeserialize(using = EventDeserializer.class) +@JsonSerialize(using = EventSerializer.class) public class GameEvent extends Event { public Integer roundCount; public Integer turnCount; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/GamestateEvent.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/GamestateEvent.java index 8e7816d..6a31a9a 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/GamestateEvent.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/GamestateEvent.java @@ -1,13 +1,19 @@ package uulm.teamname.marvelous.gamelibrary.events; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import uulm.teamname.marvelous.gamelibrary.IntVector2; import uulm.teamname.marvelous.gamelibrary.entities.Entity; import uulm.teamname.marvelous.gamelibrary.entities.EntityID; +import uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize.EventDeserializer; +import uulm.teamname.marvelous.gamelibrary.json.ingame.serialize.EventSerializer; import java.util.Arrays; import java.util.Objects; /** Represents the game state event ({@link EventType#GamestateEvent}). */ +@JsonDeserialize(using = EventDeserializer.class) +@JsonSerialize(using = EventSerializer.class) public class GamestateEvent extends Event { public Entity[] entities; public EntityID[] turnOrder; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/CharacterRequest.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/CharacterRequest.java index 6edcfc2..28a9690 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/CharacterRequest.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/CharacterRequest.java @@ -1,14 +1,20 @@ package uulm.teamname.marvelous.gamelibrary.requests; import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import uulm.teamname.marvelous.gamelibrary.IntVector2; import uulm.teamname.marvelous.gamelibrary.entities.EntityID; import uulm.teamname.marvelous.gamelibrary.entities.StoneType; +import uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize.RequestDeserializer; +import uulm.teamname.marvelous.gamelibrary.json.ingame.serialize.RequestSerializer; import java.util.Objects; /** Represents a character event for: {@link RequestType#MeleeAttackRequest}, {@link RequestType#RangedAttackRequest}, {@link RequestType#MoveRequest}, {@link RequestType#ExchangeInfinityStoneRequest}, {@link RequestType#UseInfinityStoneRequest}. */ @JsonPropertyOrder({"requestType", "originEntity", "targetEntity", "originField", "targetField", "stoneType", "value"}) +@JsonDeserialize(using = RequestDeserializer.class) +@JsonSerialize(using = RequestSerializer.class) public class CharacterRequest extends Request { public EntityID originEntity = null; public EntityID targetEntity = null; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/GameRequest.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/GameRequest.java index b37e36b..699a6a4 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/GameRequest.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/GameRequest.java @@ -1,4 +1,11 @@ package uulm.teamname.marvelous.gamelibrary.requests; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize.RequestDeserializer; +import uulm.teamname.marvelous.gamelibrary.json.ingame.serialize.RequestSerializer; + /** Represents a game request for: {@link RequestType#DisconnectRequest}. */ +@JsonDeserialize(using = RequestDeserializer.class) +@JsonSerialize(using = RequestSerializer.class) public class GameRequest extends Request {}