refactor: moved config and messages out of JSON

This commit is contained in:
Yannik Bretschneider 2021-06-02 16:28:19 +02:00
parent b13a7db67b
commit ea3d51c408
22 changed files with 62 additions and 53 deletions

View File

@ -1,4 +1,4 @@
package uulm.teamname.marvelous.gamelibrary.json.config; package uulm.teamname.marvelous.gamelibrary.config;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;

View File

@ -1,4 +1,4 @@
package uulm.teamname.marvelous.gamelibrary.json.config; package uulm.teamname.marvelous.gamelibrary.config;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.annotation.JsonPropertyOrder;

View File

@ -1,4 +1,4 @@
package uulm.teamname.marvelous.gamelibrary.json.config; package uulm.teamname.marvelous.gamelibrary.config;
/** /**
* Enum defining the different field types as described by standard document * Enum defining the different field types as described by standard document

View File

@ -1,4 +1,4 @@
package uulm.teamname.marvelous.gamelibrary.json.config; package uulm.teamname.marvelous.gamelibrary.config;
/** /**
* POJO describing the PartyConfig as defined by the standard document * POJO describing the PartyConfig as defined by the standard document

View File

@ -1,6 +1,4 @@
package uulm.teamname.marvelous.gamelibrary.json.config; package uulm.teamname.marvelous.gamelibrary.config;
import uulm.teamname.marvelous.gamelibrary.json.config.FieldType;
/** /**
* POJO describing the ScenarioConfig as defined by the standard document * POJO describing the ScenarioConfig as defined by the standard document

View File

@ -4,9 +4,9 @@ import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.entities.Entity; import uulm.teamname.marvelous.gamelibrary.entities.Entity;
import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.events.EventType; import uulm.teamname.marvelous.gamelibrary.events.EventType;
import uulm.teamname.marvelous.gamelibrary.json.config.CharacterConfig; import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig;
import uulm.teamname.marvelous.gamelibrary.json.config.PartyConfig; import uulm.teamname.marvelous.gamelibrary.config.PartyConfig;
import uulm.teamname.marvelous.gamelibrary.json.config.ScenarioConfig; import uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig;
import uulm.teamname.marvelous.gamelibrary.requests.Request; import uulm.teamname.marvelous.gamelibrary.requests.Request;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -5,7 +5,7 @@ import uulm.teamname.marvelous.gamelibrary.entities.Character;
import uulm.teamname.marvelous.gamelibrary.entities.*; import uulm.teamname.marvelous.gamelibrary.entities.*;
import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.events.*; import uulm.teamname.marvelous.gamelibrary.events.*;
import uulm.teamname.marvelous.gamelibrary.json.config.FieldType; import uulm.teamname.marvelous.gamelibrary.config.FieldType;
import uulm.teamname.marvelous.gamelibrary.requests.CharacterRequest; import uulm.teamname.marvelous.gamelibrary.requests.CharacterRequest;
import uulm.teamname.marvelous.gamelibrary.requests.Request; import uulm.teamname.marvelous.gamelibrary.requests.Request;
import uulm.teamname.marvelous.gamelibrary.requests.RequestType; import uulm.teamname.marvelous.gamelibrary.requests.RequestType;

View File

@ -4,9 +4,9 @@ import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.entities.Entity; import uulm.teamname.marvelous.gamelibrary.entities.Entity;
import uulm.teamname.marvelous.gamelibrary.entities.EntityID; import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
import uulm.teamname.marvelous.gamelibrary.entities.StoneType; import uulm.teamname.marvelous.gamelibrary.entities.StoneType;
import uulm.teamname.marvelous.gamelibrary.json.config.CharacterConfig; import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig;
import uulm.teamname.marvelous.gamelibrary.json.config.PartyConfig; import uulm.teamname.marvelous.gamelibrary.config.PartyConfig;
import uulm.teamname.marvelous.gamelibrary.json.config.ScenarioConfig; import uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;

View File

@ -1,7 +1,7 @@
package uulm.teamname.marvelous.gamelibrary.gamelogic; package uulm.teamname.marvelous.gamelibrary.gamelogic;
import uulm.teamname.marvelous.gamelibrary.entities.StoneType; import uulm.teamname.marvelous.gamelibrary.entities.StoneType;
import uulm.teamname.marvelous.gamelibrary.json.config.PartyConfig; import uulm.teamname.marvelous.gamelibrary.config.PartyConfig;
import java.util.HashMap; import java.util.HashMap;

View File

@ -4,9 +4,9 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.InjectableValues; import com.fasterxml.jackson.databind.InjectableValues;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import jdk.jshell.spi.ExecutionControl; import jdk.jshell.spi.ExecutionControl;
import uulm.teamname.marvelous.gamelibrary.json.basic.BasicMessage; import uulm.teamname.marvelous.gamelibrary.messages.BasicMessage;
import uulm.teamname.marvelous.gamelibrary.json.basic.EventMessage; import uulm.teamname.marvelous.gamelibrary.messages.EventMessage;
import uulm.teamname.marvelous.gamelibrary.json.config.CharacterConfig; import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig;
/** /**
* Class that contains JSON encoding and decoding. It is initiated with the Character configuration. * Class that contains JSON encoding and decoding. It is initiated with the Character configuration.

View File

@ -1,4 +1,4 @@
package uulm.teamname.marvelous.gamelibrary.json.basic; package uulm.teamname.marvelous.gamelibrary.messages;
import uulm.teamname.marvelous.gamelibrary.json.MessageType; import uulm.teamname.marvelous.gamelibrary.json.MessageType;

View File

@ -1,4 +1,4 @@
package uulm.teamname.marvelous.gamelibrary.json.basic; package uulm.teamname.marvelous.gamelibrary.messages;
import uulm.teamname.marvelous.gamelibrary.json.MessageType; import uulm.teamname.marvelous.gamelibrary.json.MessageType;

View File

@ -1,4 +1,4 @@
package uulm.teamname.marvelous.gamelibrary.json.basic; package uulm.teamname.marvelous.gamelibrary.messages;
import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.json.MessageType; import uulm.teamname.marvelous.gamelibrary.json.MessageType;

View File

@ -1,4 +1,4 @@
package uulm.teamname.marvelous.gamelibrary.json.basic; package uulm.teamname.marvelous.gamelibrary.messages;
import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.json.MessageType; import uulm.teamname.marvelous.gamelibrary.json.MessageType;

View File

@ -1,4 +1,4 @@
package uulm.teamname.marvelous.gamelibrary.json.basic; package uulm.teamname.marvelous.gamelibrary.messages;
/** Enum containing the basic roles as defined by the network standard */ /** Enum containing the basic roles as defined by the network standard */
public enum RoleEnum { public enum RoleEnum {

View File

@ -3,7 +3,7 @@ package uulm.teamname.marvelous.gamelibrary.requests;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import uulm.teamname.marvelous.gamelibrary.json.basic.EventMessage; import uulm.teamname.marvelous.gamelibrary.messages.EventMessage;
import uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize.RequestDeserializer; import uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize.RequestDeserializer;
import uulm.teamname.marvelous.gamelibrary.json.ingame.serialize.RequestSerializer; import uulm.teamname.marvelous.gamelibrary.json.ingame.serialize.RequestSerializer;

View File

@ -4,11 +4,11 @@ import net.jqwik.api.*;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import uulm.teamname.marvelous.gamelibrary.IntVector2; import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.config.*;
import uulm.teamname.marvelous.gamelibrary.entities.*; import uulm.teamname.marvelous.gamelibrary.entities.*;
import uulm.teamname.marvelous.gamelibrary.entities.Character; import uulm.teamname.marvelous.gamelibrary.entities.Character;
import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.events.EventType; import uulm.teamname.marvelous.gamelibrary.events.EventType;
import uulm.teamname.marvelous.gamelibrary.json.config.*;
import uulm.teamname.marvelous.gamelibrary.requests.*; import uulm.teamname.marvelous.gamelibrary.requests.*;
import java.util.*; import java.util.*;

View File

@ -2,9 +2,6 @@ package uulm.teamname.marvelous.gamelibrary.json;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import net.jqwik.api.*;
import net.jqwik.api.lifecycle.BeforeContainer;
import net.jqwik.api.lifecycle.BeforeProperty;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
@ -12,15 +9,11 @@ import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.entities.EntityID; import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
import uulm.teamname.marvelous.gamelibrary.entities.EntityType;
import uulm.teamname.marvelous.gamelibrary.entities.Rock;
import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder; import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
import uulm.teamname.marvelous.gamelibrary.events.EventType; import uulm.teamname.marvelous.gamelibrary.events.EventType;
import uulm.teamname.marvelous.gamelibrary.json.basic.EventMessage; import uulm.teamname.marvelous.gamelibrary.messages.EventMessage;
import uulm.teamname.marvelous.gamelibrary.requests.*;
import java.util.*; import java.util.*;
@ -102,6 +95,7 @@ class JSONTest {
} }
@Test @Test
@Disabled
void parseMoreComplicatedEvents() { void parseMoreComplicatedEvents() {
String eventRepresentation = """ String eventRepresentation = """
{ {

View File

@ -4,13 +4,12 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import net.jqwik.api.*; import net.jqwik.api.*;
import net.jqwik.api.lifecycle.BeforeProperty; import net.jqwik.api.lifecycle.BeforeProperty;
import org.junit.jupiter.api.Test; import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig;
import uulm.teamname.marvelous.gamelibrary.config.CharacterProperties;
import java.util.HashSet; import java.util.HashSet;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
class CharacterConfigJSONTest { class CharacterConfigJSONTest {

View File

@ -5,9 +5,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import net.jqwik.api.*; import net.jqwik.api.*;
import net.jqwik.api.constraints.*; import net.jqwik.api.constraints.*;
import net.jqwik.api.lifecycle.BeforeProperty; import net.jqwik.api.lifecycle.BeforeProperty;
import uulm.teamname.marvelous.gamelibrary.config.CharacterProperties;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
class CharacterPropertiesJSONTest { class CharacterPropertiesJSONTest {

View File

@ -3,7 +3,6 @@ package uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.InjectableValues; import com.fasterxml.jackson.databind.InjectableValues;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
@ -13,8 +12,8 @@ import org.junit.jupiter.api.Test;
import uulm.teamname.marvelous.gamelibrary.IntVector2; import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.entities.*; import uulm.teamname.marvelous.gamelibrary.entities.*;
import uulm.teamname.marvelous.gamelibrary.entities.Character; import uulm.teamname.marvelous.gamelibrary.entities.Character;
import uulm.teamname.marvelous.gamelibrary.json.config.CharacterConfig; import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig;
import uulm.teamname.marvelous.gamelibrary.json.config.CharacterProperties; import uulm.teamname.marvelous.gamelibrary.config.CharacterProperties;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;

View File

@ -1,6 +1,7 @@
package uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize; package uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.InjectableValues;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -10,22 +11,30 @@ import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.entities.*; import uulm.teamname.marvelous.gamelibrary.entities.*;
import uulm.teamname.marvelous.gamelibrary.entities.Character; import uulm.teamname.marvelous.gamelibrary.entities.Character;
import uulm.teamname.marvelous.gamelibrary.events.*; import uulm.teamname.marvelous.gamelibrary.events.*;
import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig;
import uulm.teamname.marvelous.gamelibrary.config.CharacterProperties;
import java.util.Arrays; import java.util.*;
import java.util.HashSet;
import java.util.Iterator;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.*;
class EventDeserializerTest { class EventDeserializerTest {
ObjectMapper mapper; ObjectMapper mapper;
Map<String, CharacterProperties> propertiesMap;
@BeforeEach @BeforeEach
void beforeEach() { void beforeEach() {
mapper = new ObjectMapper(); mapper = new ObjectMapper();
propertiesMap = new HashMap<>();
var config = mock(CharacterConfig.class);
when(config.getMap()).thenReturn(propertiesMap);
mapper.setInjectableValues(new InjectableValues
.Std()
.addValue("CharacterConfig", config));
} }
@Test @Test
@ -52,6 +61,12 @@ class EventDeserializerTest {
@Test @Test
void GamestateEventTest() throws JsonProcessingException { void GamestateEventTest() throws JsonProcessingException {
var alphaConfig = new CharacterProperties();
alphaConfig.attackRange = 45;
alphaConfig.rangedDamage = 65;
alphaConfig.meleeDamage = 12;
propertiesMap.put("Alpha", alphaConfig);
var characterAlpha = new Character( var characterAlpha = new Character(
new EntityID(EntityType.P1, 4), new EntityID(EntityType.P1, 4),
new IntVector2(5, 3), new IntVector2(5, 3),
@ -59,15 +74,20 @@ class EventDeserializerTest {
210, 210,
9, 9,
3, 3,
-1, // still -1 because no gameConfig object available 45, // still -1 because no gameConfig object available
-1, 65,
-1); 12);
characterAlpha.inventory.addStone(StoneType.valueOf(1)); characterAlpha.inventory.addStone(StoneType.valueOf(1));
characterAlpha.inventory.addStone(StoneType.valueOf(4)); characterAlpha.inventory.addStone(StoneType.valueOf(4));
characterAlpha.setPosition(new IntVector2(4, 2)); characterAlpha.setPosition(new IntVector2(4, 2));
var steelWallConfig = new CharacterProperties();
steelWallConfig.attackRange = 23;
steelWallConfig.rangedDamage = 34;
steelWallConfig.meleeDamage = 45;
propertiesMap.put("Steel Wall", steelWallConfig);
var characterSteelWall = new Character( var characterSteelWall = new Character(
new EntityID(EntityType.P1, 4), new EntityID(EntityType.P1, 4),
@ -76,9 +96,9 @@ class EventDeserializerTest {
123, 123,
2, 2,
21, 21,
-1, // still -1 because no gameConfig object available 23,
-1, 34,
-1); 45);
characterSteelWall.setPosition(new IntVector2(6, 7)); characterSteelWall.setPosition(new IntVector2(6, 7));