Class AbstractView

java.lang.Object
gaiasky.scene.view.AbstractView
Direct Known Subclasses:
BaseView, PositionView

public abstract class AbstractView extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected com.badlogic.ashley.core.Entity
    A reference to the entity.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates an empty abstract view without entity.
    protected
    AbstractView(com.badlogic.ashley.core.Entity entity)
    Creates an abstract view with the given entity.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    check(com.badlogic.ashley.core.Entity entity, com.badlogic.ashley.core.ComponentMapper mapper, Class<? extends com.badlogic.ashley.core.Component> componentClass)
    Checks whether an entity has a component, and throws a RuntimeException if it does not.
    void
    Removes the entity (if any) of this view and sets all component references to null.
    protected abstract boolean
    componentsCheck(com.badlogic.ashley.core.Entity entity)
    Check whether the current components are the same as the components of the given entity.
    protected abstract void
    Contains actions to take after a new entity has been set.
    protected abstract void
    entityCheck(com.badlogic.ashley.core.Entity entity)
    Checks whether the given entity is suitable for this view.
    protected abstract void
    This method is called when the entity of this view is cleared.
    com.badlogic.ashley.core.Entity
    Returns the current entity under this view.
    boolean
    Checks whether an entity is set in this view.
    boolean
    Checks whether the entity is valid, i.e., it is not null and has at least one component.
    void
    setEntity(com.badlogic.ashley.core.Entity entity)
    Sets the entity behind this view.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • entity

      protected com.badlogic.ashley.core.Entity entity
      A reference to the entity.
  • Constructor Details

    • AbstractView

      protected AbstractView()
      Creates an empty abstract view without entity.
    • AbstractView

      protected AbstractView(com.badlogic.ashley.core.Entity entity)
      Creates an abstract view with the given entity.
      Parameters:
      entity - The entity.
  • Method Details

    • componentsCheck

      protected abstract boolean componentsCheck(com.badlogic.ashley.core.Entity entity)
      Check whether the current components are the same as the components of the given entity.
      Parameters:
      entity - The entity to check.
      Returns:
      True if the components are the same, false otherwise.
    • clearEntity

      public void clearEntity()
      Removes the entity (if any) of this view and sets all component references to null.
    • getEntity

      public com.badlogic.ashley.core.Entity getEntity()
      Returns the current entity under this view.
    • setEntity

      public void setEntity(com.badlogic.ashley.core.Entity entity)
      Sets the entity behind this view. This method can be used to reuse the AbstractView instance.
      Parameters:
      entity - The new entity.
    • isValid

      public boolean isValid()
      Checks whether the entity is valid, i.e., it is not null and has at least one component. Removed entities, for instance, have no components.
      Returns:
      Whether the entity is valid.
    • isEmpty

      public boolean isEmpty()
      Checks whether an entity is set in this view. Note that an entity may be set, but the entity may have been removed from the engine. In that case, the entity is no longer valid. Use isValid().
      Returns:
      True if an entity is not set. False otherwise.
    • check

      protected void check(com.badlogic.ashley.core.Entity entity, com.badlogic.ashley.core.ComponentMapper mapper, Class<? extends com.badlogic.ashley.core.Component> componentClass)
      Checks whether an entity has a component, and throws a RuntimeException if it does not.
      Parameters:
      entity - The entity.
      mapper - The component mapper.
      componentClass - The component class.
    • entityCheck

      protected abstract void entityCheck(com.badlogic.ashley.core.Entity entity)
      Checks whether the given entity is suitable for this view. This method should throw a RuntimeException if the entity is not suitable.
      Parameters:
      entity - The entity.
    • entityChanged

      protected abstract void entityChanged()
      Contains actions to take after a new entity has been set. This method is typically used to initialize the view components.
    • entityCleared

      protected abstract void entityCleared()
      This method is called when the entity of this view is cleared. It should set all component references to null.