From 371424e6c32de5c10b1b9260d6d113cc1607ca4e Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Thu, 24 Jun 2021 15:37:30 +0200 Subject: [PATCH] feat: added PortalEvent to EventBuilder --- .../gamelibrary/entities/EntityType.java | 2 ++ .../gamelibrary/events/EventBuilder.java | 34 +++++++++++++++++++ .../gamelibrary/events/EventBuilderTest.java | 22 ++++++++++++ 3 files changed, 58 insertions(+) diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityType.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityType.java index acbc9f4..4097c65 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityType.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityType.java @@ -12,6 +12,8 @@ public enum EntityType { Rocks, /** Represents an InfinityStone entity */ InfinityStones, + /** Represents a Portal */ + Portals, /** Represents nothing */ None } diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilder.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilder.java index 12f0ff3..e8cf250 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilder.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilder.java @@ -46,6 +46,10 @@ public class EventBuilder { private Integer[] stoneCooldowns; private Boolean winCondition; + // Keys used in TeleportedEvents (plus origin/targetFields) + public EntityID teleportedEntity; + public EntityID originPortal, targetPortal; + // Keys used in CustomEvents private String teamIdentifier; private HashMap customContent; @@ -167,6 +171,21 @@ public class EventBuilder { return this; } + public EventBuilder withTeleportedEntity(EntityID teleportedEntity) { + this.teleportedEntity = teleportedEntity; + return this; + } + + public EventBuilder withOriginPortal(EntityID originPortal) { + this.originPortal = originPortal; + return this; + } + + public EventBuilder withTargetPortal(EntityID targetPortal) { + this.targetPortal = targetPortal; + return this; + } + public EventBuilder withTeamIdentifier(String teamIdentifier) { this.teamIdentifier = teamIdentifier; return this; @@ -293,6 +312,21 @@ public class EventBuilder { return customEvent; } + /** + * Builds a {@link TeleportedEvent}, used for describing teleporting Players into Portals. + * @return the built {@link TeleportedEvent} + */ + public TeleportedEvent buildTeleportedEvent() { + var teleportedEvent = new TeleportedEvent(); + teleportedEvent.type = this.type; + teleportedEvent.originField = this.originField; + teleportedEvent.targetField = this.targetField; + teleportedEvent.teleportedEntity = this.teleportedEntity; + teleportedEvent.originPortal = this.originPortal; + teleportedEvent.targetPortal = this.targetPortal; + return teleportedEvent; + } + @Override public String toString() { StringJoiner joiner = new StringJoiner("\n"); diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilderTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilderTest.java index a5d3974..4283e60 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilderTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilderTest.java @@ -394,4 +394,26 @@ class EventBuilderTest { } + + @Test + void buildPortalEvents() { + var built = new EventBuilder(EventType.TeleportedEvent) + .withTeleportedEntity(new EntityID(EntityType.P1, 3)) + .withOriginField(new IntVector2(6, 2)) + .withTargetField(new IntVector2(11, 14)) + .withOriginPortal(new EntityID(EntityType.Portals, 0)) + .withTargetPortal(new EntityID(EntityType.Portals, 2)) + .buildTeleportedEvent(); + + var actual = new TeleportedEvent(); + actual.type = EventType.TeleportedEvent; + actual.originField = new IntVector2(6, 2); + actual.targetField = new IntVector2(11, 14); + actual.teleportedEntity = new EntityID(EntityType.P1, 3); + actual.originPortal = new EntityID(EntityType.Portals, 0); + actual.targetPortal = new EntityID(EntityType.Portals, 2); + + assertThat(built).isEqualTo(actual); + + } }