refactor: changed GameStateEvent to GamestateEvent

This commit is contained in:
Yannik Bretschneider 2021-05-11 05:06:00 +02:00
parent e31cc1644d
commit 6e9efa1a59
5 changed files with 16 additions and 16 deletions

View File

@ -253,19 +253,19 @@ public class EventBuilder {
} }
/** /**
* Builds a generic {@link GameStateEvent} from the values given to the builder. * Builds a generic {@link GamestateEvent} from the values given to the builder.
* <ul> * <ul>
* <li>type is the {@link EventType} of the {@link GameStateEvent}</li> * <li>type is the {@link EventType} of the {@link GamestateEvent}</li>
* <li>entities is an array of {@link Entity Entities}</li> * <li>entities is an array of {@link Entity Entities}</li>
* <li>turnOrder describes the order in which characters take turns</li> * <li>turnOrder describes the order in which characters take turns</li>
* <li>activeCharacter describes the currently active character</li> * <li>activeCharacter describes the currently active character</li>
* <li>describes whether the win condition is in effect</li> * <li>describes whether the win condition is in effect</li>
* </ul> * </ul>
* *
* @return a {@link GameStateEvent} based on the builder * @return a {@link GamestateEvent} based on the builder
*/ */
public GameStateEvent buildGameStateEvent() throws IllegalStateException { public GamestateEvent buildGameStateEvent() throws IllegalStateException {
var gameStateEvent = new GameStateEvent(); var gameStateEvent = new GamestateEvent();
gameStateEvent.type = this.type; gameStateEvent.type = this.type;
gameStateEvent.entities = this.entities; gameStateEvent.entities = this.entities;
gameStateEvent.turnOrder = this.turnOrder; gameStateEvent.turnOrder = this.turnOrder;

View File

@ -5,7 +5,7 @@ public enum EventType {
// GameStateEvents // GameStateEvents
Ack, Ack,
Nack, Nack,
GameStateEvent, GamestateEvent,
// CustomEvents // CustomEvents
CustomEvent, CustomEvent,

View File

@ -7,8 +7,8 @@ import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
/** Represents the game state event ({@link EventType#GameStateEvent}). */ /** Represents the game state event ({@link EventType#GamestateEvent}). */
public class GameStateEvent extends Event { public class GamestateEvent extends Event {
public Entity[] entities; public Entity[] entities;
public EntityID[] turnOrder; public EntityID[] turnOrder;
public IntVector2 mapSize; public IntVector2 mapSize;
@ -24,7 +24,7 @@ public class GameStateEvent extends Event {
switch(type) { switch(type) {
// GameState needs very specific properties // GameState needs very specific properties
case GameStateEvent: case GamestateEvent:
if (this.entities == null || if (this.entities == null ||
this.turnOrder == null || this.turnOrder == null ||
this.mapSize == null || this.mapSize == null ||
@ -44,7 +44,7 @@ public class GameStateEvent extends Event {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false; if (!super.equals(o)) return false;
GameStateEvent that = (GameStateEvent) o; GamestateEvent that = (GamestateEvent) o;
return Arrays.equals(entities, that.entities) && Arrays.equals(turnOrder, that.turnOrder) && Objects.equals(mapSize, that.mapSize) && Objects.equals(activeCharacter, that.activeCharacter) && Arrays.equals(stoneCooldowns, that.stoneCooldowns) && Objects.equals(winCondition, that.winCondition); return Arrays.equals(entities, that.entities) && Arrays.equals(turnOrder, that.turnOrder) && Objects.equals(mapSize, that.mapSize) && Objects.equals(activeCharacter, that.activeCharacter) && Arrays.equals(stoneCooldowns, that.stoneCooldowns) && Objects.equals(winCondition, that.winCondition);
} }

View File

@ -157,7 +157,7 @@ class GameLogic {
} }
} }
case Req -> { case Req -> {
result.add(new EventBuilder(EventType.GameStateEvent) result.add(new EventBuilder(EventType.GamestateEvent)
.withEntities(state.entities.export()) .withEntities(state.entities.export())
.withTurnOrder((EntityID[])state.turnOrder.toArray()) .withTurnOrder((EntityID[])state.turnOrder.toArray())
.withMapSize(state.mapSize) .withMapSize(state.mapSize)
@ -296,7 +296,7 @@ class GameLogic {
} }
} }
case TimeStone -> { case TimeStone -> {
// "👍 i approve" - the server // "👍 i approve" - the server
} }
case SoulStone -> { case SoulStone -> {
Character target = getCharacter(state, data.targetField, data.targetEntity); Character target = getCharacter(state, data.targetField, data.targetEntity);

View File

@ -205,7 +205,7 @@ class EventBuilderTest {
.isTrue() .isTrue()
.withFailMessage("GameStateEvent failed check"); .withFailMessage("GameStateEvent failed check");
var baseline = new GameStateEvent(); var baseline = new GamestateEvent();
baseline.type = EventType.ConsumedAPEvent; baseline.type = EventType.ConsumedAPEvent;
baseline.entities = entities; baseline.entities = entities;
baseline.turnOrder = turns; baseline.turnOrder = turns;
@ -248,15 +248,15 @@ class EventBuilderTest {
assertThat(new EventBuilder(EventType.Nack).buildGameStateEvent().check()).isTrue(); assertThat(new EventBuilder(EventType.Nack).buildGameStateEvent().check()).isTrue();
assertThat(new EventBuilder(EventType.Req).buildGameStateEvent().check()).isTrue(); // assertThat(new EventBuilder(EventType.Req).buildGameStateEvent().check()).isTrue();
assertThat(new EventBuilder(EventType.GameStateEvent) // if properties missing throw exception assertThat(new EventBuilder(EventType.GamestateEvent) // if properties missing throw exception
.withTurnOrder(turns) .withTurnOrder(turns)
.withActiveCharacter(turn) .withActiveCharacter(turn)
.buildGameStateEvent() .buildGameStateEvent()
.check()).isFalse(); .check()).isFalse();
assertThat(new EventBuilder(EventType.GameStateEvent) // no exception if all properties present assertThat(new EventBuilder(EventType.GamestateEvent) // no exception if all properties present
.withEntities(entities) .withEntities(entities)
.withTurnOrder(turns) .withTurnOrder(turns)
.withMapSize(new IntVector2(42, 24)) .withMapSize(new IntVector2(42, 24))