67 lines
1.9 KiB
Java
67 lines
1.9 KiB
Java
package uulm.teamname.marvelous.gamelibrary.entities;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
|
import uulm.teamname.marvelous.gamelibrary.json.ingame.EntityIDDeserializer;
|
|
|
|
import java.util.Objects;
|
|
|
|
/** Represents a distinct identification for every {@link Entity} in a game. */
|
|
@JsonDeserialize(using = EntityIDDeserializer.class)
|
|
public class EntityID {
|
|
/** The index of the entity */
|
|
public final int id;
|
|
|
|
/** The type of the entity */
|
|
@JsonProperty("entityID")
|
|
public final EntityType type;
|
|
|
|
/**
|
|
* Constructs a new {@link Entity}-{@link EntityID} based on the given index and {@link EntityType}.
|
|
* @param type The type of the entity
|
|
* @param id The index of the entity
|
|
*/
|
|
public EntityID(EntityType type, int id) {
|
|
this.id = id;
|
|
this.type = type;
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
public boolean isSameType(EntityType other) {
|
|
return type == other;
|
|
}
|
|
|
|
/**
|
|
* Clones this entity id.
|
|
* @return The cloned {@link EntityID}
|
|
*/
|
|
public EntityID clone() {
|
|
return new EntityID(type, id);
|
|
}
|
|
|
|
/**
|
|
* Serializes the id for debugging.
|
|
* @return A debug string containing all the necessary information about the id
|
|
*/
|
|
public String toString() {
|
|
return "["+type.toString()+":"+id+"]";
|
|
}
|
|
|
|
@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);
|
|
}
|
|
}
|