feat: created BasicAnswer, and cleaned up some code

This commit is contained in:
Yannik Bretschneider 2021-05-18 14:19:09 +02:00
parent 2d33f150a8
commit 37e84b6e15
3 changed files with 55 additions and 46 deletions

View File

@ -0,0 +1,10 @@
package uulm.teamname.marvelous.gamelibrary.json.basic;
import uulm.teamname.marvelous.gamelibrary.json.MessageType;
/** Basic answer to a message. It contains */
public class BasicAnswer {
String userID;
MessageType messageType;
boolean optionals;
}

View File

@ -1,6 +1,5 @@
package uulm.teamname.marvelous.gamelibrary.json.ingame;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.json.MessageType;

View File

@ -30,31 +30,31 @@ class JSONTest {
@BeforeEach
void setUp() {
messageStructureStart = """
{
"messages":[
""";
{
"messages":[
""";
messageStructureEnd = new String[] {
"""
],
"messageType": "REQUESTS",
"customContentType": "TestCustomContent",
"customContent": {
"customKey" = "customResult",
"customNumber" = 15,
"customProperty" = true
}
""",
"""
],
"messageType": "EVENTS",
"customContentType": "TestCustomContent",
"customContent": {
"customKey": "customResult",
"customNumber": 15,
"customProperty": true
}
}
""",
"""
],
"messageType": "REQUESTS",
"customContentType": "TestCustomContent",
"customContent": {
"customKey" = "customResult",
"customNumber" = 15,
"customProperty" = true
}
""",
"""
],
"messageType": "EVENTS",
"customContentType": "TestCustomContent",
"customContent": {
"customKey": "customResult",
"customNumber": 15,
"customProperty": true
}
}
""",
};
target = new MessageStructure();
target.customContentType = "TestCustomContent";
@ -76,9 +76,9 @@ class JSONTest {
};
String eventRepresentation = """
{"eventType": "Ack"},
{"eventType": "Nack"}
""";
{"eventType": "Ack"},
{"eventType": "Nack"}
""";
String completeMessageStructure = messageStructureStart + eventRepresentation + messageStructureEnd[1];
target.messageType = MessageType.EVENTS;
@ -91,19 +91,19 @@ class JSONTest {
@Test
void parseMoreComplicatedEvents() {
String eventRepresentation = """
{
"eventType": "GamestateEvent",
"activeCharacter": {"entityID": "P2", "ID": 4},
"turnOrder": [
{"entityID": "P2", "ID": 4},
{"entityID": "P2", "ID": 2},
{"entityID": "P1", "ID": 3},
{"entityID": "NPC", "ID": 1},
{"entityID": "InfinityStones", "ID": 5},
{"entityID": "Rocks", "ID": 0}
]
}
""";
{
"eventType": "GamestateEvent",
"activeCharacter": {"entityID": "P2", "ID": 4},
"turnOrder": [
{"entityID": "P2", "ID": 4},
{"entityID": "P2", "ID": 2},
{"entityID": "P1", "ID": 3},
{"entityID": "NPC", "ID": 1},
{"entityID": "InfinityStones", "ID": 5},
{"entityID": "Rocks", "ID": 0}
]
}
""";
String completeMessageStructure = messageStructureStart + eventRepresentation + messageStructureEnd[1];
System.out.println(JSON.parse(completeMessageStructure));
@ -113,11 +113,11 @@ class JSONTest {
@Disabled
void simpleInDevTest() throws JsonProcessingException {
String simpleEntity = """
{
"entityID": "P2",
"ID": 4
}
""";
{
"entityID": "P2",
"ID": 4
}
""";
System.out.println(new ObjectMapper().readValue(simpleEntity, EntityID.class));
}