Class Entity

  • All Implemented Interfaces:
    IEntity

    public class Entity
    extends AbstractLogger
    implements IEntity
    An entity is something that exists in your game world. Again, an entity is little more than a list of components. Because they are so simple, most implementations won't define an entity as a concrete piece of data. Instead, an entity is a unique ID, and all components that make up an entity will be tagged with that ID.
    Author:
    kong
    See Also:
    IEntity
    • Constructor Detail

      • Entity

        public Entity()
    • Method Detail

      • setId

        public void setId​(java.lang.String id)
        Description copied from interface: IEntity
        Set new id
        Specified by:
        setId in interface IEntity
        Parameters:
        id - the desired id
      • getId

        public java.lang.String getId()
        Description copied from interface: IEntity
        Retrieves the entity's id
        Specified by:
        getId in interface IEntity
        Returns:
        entity's id
      • setComponentPools

        public void setComponentPools​(IElementPool<IComponent>[] componentPools)
        Description copied from interface: IEntity
        Set list of component pools, each component pool manages specific component type
        Specified by:
        setComponentPools in interface IEntity
        Parameters:
        componentPools - an array of ComponentPool
      • setComponent

        public void setComponent​(int index,
                                 IComponent component)
        Description copied from interface: IEntity
        Set new component
        Specified by:
        setComponent in interface IEntity
        Parameters:
        index - the component index
        component - the component object
      • removeComponent

        public void removeComponent​(int index)
        Description copied from interface: IEntity
        Remove component by index
        Specified by:
        removeComponent in interface IEntity
        Parameters:
        index - the component index
      • replaceComponent

        public void replaceComponent​(int index,
                                     IComponent component)
        Description copied from interface: IEntity
        Replace old component by new component by index
        Specified by:
        replaceComponent in interface IEntity
        Parameters:
        index - the component index
        component - the component object
      • getComponent

        public IComponent getComponent​(int index)
        Description copied from interface: IEntity
        Retrieves the component by index
        Specified by:
        getComponent in interface IEntity
        Parameters:
        index - the component index
        Returns:
        the corresponding component
      • getComponents

        public IComponent[] getComponents()
        Description copied from interface: IEntity
        Retrieves a list of the current entity
        Specified by:
        getComponents in interface IEntity
        Returns:
        list of components
      • hasComponent

        public boolean hasComponent​(int index)
        Description copied from interface: IEntity
        Check if the component is existed or not
        Specified by:
        hasComponent in interface IEntity
        Parameters:
        index - component index
        Returns:
        true if the component is existed, false otherwise
      • hasComponents

        public boolean hasComponents​(int... indices)
        Description copied from interface: IEntity
        Check if all the components in list are existed or not
        Specified by:
        hasComponents in interface IEntity
        Parameters:
        indices - list of component indices
        Returns:
        true if the all components are existed, false otherwise
      • hasAnyComponent

        public boolean hasAnyComponent​(int... indices)
        Description copied from interface: IEntity
        Check if one of components in list are existed or not
        Specified by:
        hasAnyComponent in interface IEntity
        Parameters:
        indices - list of component indices
        Returns:
        true if the one of components in list is existed, false otherwise
      • removeAllComponents

        public void removeAllComponents()
        Description copied from interface: IEntity
        Remove all components
        Specified by:
        removeAllComponents in interface IEntity
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • reset

        public void reset()
        Description copied from interface: IEntity
        Reset entity
        Specified by:
        reset in interface IEntity