feat: implemented proper CharacterConfig json stuff

This commit is contained in:
2021-06-02 16:10:35 +02:00
parent ea6a178c82
commit b13a7db67b
4 changed files with 549 additions and 3 deletions

View File

@ -2,9 +2,7 @@ package uulm.teamname.marvelous.gamelibrary.json.config;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
/**
* POJO describing the CharacterConfig as defined by the standard document.
@ -19,6 +17,7 @@ public class CharacterConfig {
* @return a unmodifiable {@link Map}<{@link String}, {@link CharacterProperties}> containing all properties.
* If not yet existent, initialize the Map
*/
@JsonIgnore
public Map<String, CharacterProperties> getMap() {
// lazy initialization
if (propertyMap == null) {
@ -31,4 +30,19 @@ public class CharacterConfig {
return unmodifiablePropertyMap;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CharacterConfig that = (CharacterConfig) o;
return Arrays.equals(characters, that.characters) && Objects.equals(propertyMap, that.propertyMap) && Objects.equals(unmodifiablePropertyMap, that.unmodifiablePropertyMap);
}
@Override
public int hashCode() {
int result = Objects.hash(propertyMap, unmodifiablePropertyMap);
result = 31 * result + Arrays.hashCode(characters);
return result;
}
}

View File

@ -1,11 +1,16 @@
package uulm.teamname.marvelous.gamelibrary.json.config;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import java.util.Objects;
@JsonPropertyOrder({"characterID", "name", "HP", "MP", "AP", "meleeDamage", "rangeCombatDamage", "rangeCombatReach"})
/**
* Represents properties of a character in the {@link CharacterConfig}.
*/
public class CharacterProperties {
public int characterID;
public String name;
public int HP;
public int MP;
@ -15,4 +20,17 @@ public class CharacterProperties {
public int rangedDamage;
@JsonProperty("rangeCombatReach")
public int attackRange;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CharacterProperties that = (CharacterProperties) o;
return characterID == that.characterID && HP == that.HP && MP == that.MP && AP == that.AP && meleeDamage == that.meleeDamage && rangedDamage == that.rangedDamage && attackRange == that.attackRange && Objects.equals(name, that.name);
}
@Override
public int hashCode() {
return Objects.hash(characterID, name, HP, MP, AP, meleeDamage, rangedDamage, attackRange);
}
}