2021-04-29 14:45:18 +00:00
|
|
|
package uulm.teamname.marvelous.gamelibrary.entities;
|
2021-04-29 14:40:23 +00:00
|
|
|
|
2021-05-11 04:14:43 +00:00
|
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
|
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.json.ingame.EntityIDDeserializer;
|
|
|
|
|
2021-05-01 22:03:09 +00:00
|
|
|
import java.util.Objects;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** Represents a distinct identification for every {@link Entity} in a game. */
|
2021-05-11 04:14:43 +00:00
|
|
|
@JsonDeserialize(using = EntityIDDeserializer.class)
|
2021-04-29 14:40:23 +00:00
|
|
|
public class EntityID {
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The index of the entity */
|
2021-04-29 14:40:23 +00:00
|
|
|
public final int id;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The type of the entity */
|
2021-05-11 04:14:43 +00:00
|
|
|
@JsonProperty("entityID")
|
2021-04-29 14:40:23 +00:00
|
|
|
public final EntityType type;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/**
|
|
|
|
* Constructs a new {@link Entity}-{@link EntityID} based on the given index and {@link EntityType}.
|
|
|
|
* @param type The type of the entity
|
2021-05-01 20:24:27 +00:00
|
|
|
* @param id The index of the entity
|
2021-04-29 14:40:23 +00:00
|
|
|
*/
|
2021-05-01 20:24:27 +00:00
|
|
|
public EntityID(EntityType type, int id) {
|
2021-04-29 14:40:23 +00:00
|
|
|
this.id = id;
|
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/**
|
|
|
|
* Checks if the id has the same {@link EntityType} as the given one.
|
|
|
|
* @param other The type to compare to
|
|
|
|
* @return Whether or not the id has the same type
|
2021-04-29 14:40:23 +00:00
|
|
|
*/
|
|
|
|
public boolean isSameType(EntityType other) {
|
|
|
|
return type == other;
|
|
|
|
}
|
|
|
|
|
2021-04-30 19:48:28 +00:00
|
|
|
/**
|
|
|
|
* Clones this entity id.
|
|
|
|
* @return The cloned {@link EntityID}
|
|
|
|
*/
|
|
|
|
public EntityID clone() {
|
2021-05-01 20:24:27 +00:00
|
|
|
return new EntityID(type, id);
|
2021-04-30 19:48:28 +00:00
|
|
|
}
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/**
|
|
|
|
* Serializes the id for debugging.
|
|
|
|
* @return A debug string containing all the necessary information about the id
|
2021-04-29 14:40:23 +00:00
|
|
|
*/
|
|
|
|
public String toString() {
|
|
|
|
return "["+type.toString()+":"+id+"]";
|
|
|
|
}
|
2021-05-01 22:03:09 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (this == o) return true;
|
|
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
|
|
EntityID entityID = (EntityID) o;
|
|
|
|
return id == entityID.id && type == entityID.type;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return Objects.hash(id, type);
|
|
|
|
}
|
2021-04-29 14:40:23 +00:00
|
|
|
}
|