refactor: extracted SerializedEntityType enum
This commit is contained in:
parent
20f014209a
commit
23777bad33
@ -0,0 +1,29 @@
|
||||
package uulm.teamname.marvelous.gamelibrary.json.ingame;
|
||||
|
||||
import uulm.teamname.marvelous.gamelibrary.entities.EntityType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum SerializedEntityType {
|
||||
NPC,
|
||||
Character,
|
||||
InfinityStone,
|
||||
Rock;
|
||||
|
||||
private static Map<EntityType, SerializedEntityType> entityTypeToDeserialized;
|
||||
|
||||
static {
|
||||
entityTypeToDeserialized = new HashMap<>();
|
||||
|
||||
entityTypeToDeserialized.put(EntityType.NPC, NPC);
|
||||
entityTypeToDeserialized.put(EntityType.P1, Character);
|
||||
entityTypeToDeserialized.put(EntityType.P2, Character);
|
||||
entityTypeToDeserialized.put(EntityType.InfinityStones, InfinityStone);
|
||||
entityTypeToDeserialized.put(EntityType.Rocks, Rock);
|
||||
}
|
||||
|
||||
public static SerializedEntityType valueOf(EntityType entityType) {
|
||||
return entityTypeToDeserialized.get(entityType);
|
||||
}
|
||||
}
|
@ -1,27 +1,20 @@
|
||||
package uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.ObjectCodec;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
||||
import uulm.teamname.marvelous.gamelibrary.entities.*;
|
||||
import uulm.teamname.marvelous.gamelibrary.entities.Character;
|
||||
import uulm.teamname.marvelous.gamelibrary.json.config.CharacterConfig;
|
||||
import uulm.teamname.marvelous.gamelibrary.json.config.CharacterProperties;
|
||||
import uulm.teamname.marvelous.gamelibrary.json.ingame.SerializedEntityType;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class EntityDeserializer extends JsonDeserializer<Entity> {
|
||||
|
||||
|
||||
private enum DeserializedEntityType {
|
||||
Character,
|
||||
InfinityStone,
|
||||
Rock
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
var config = (CharacterConfig) ctxt
|
||||
@ -32,7 +25,7 @@ public class EntityDeserializer extends JsonDeserializer<Entity> {
|
||||
|
||||
Entity result = null;
|
||||
|
||||
DeserializedEntityType type = DeserializedEntityType.valueOf(node.get("entityType").asText());
|
||||
SerializedEntityType type = SerializedEntityType.valueOf(node.get("entityType").asText());
|
||||
|
||||
switch (type) {
|
||||
case Character -> {
|
||||
|
Loading…
Reference in New Issue
Block a user