Class StructureService

java.lang.Object
com.deco2800.game.entities.EntityService
com.deco2800.game.entities.StructureService

public class StructureService extends EntityService
Provides a global access point for entities to register themselves. This allows for iterating over entities to perform updates each loop. All game entities should be registered here. Avoid adding additional state here! Global access is often the easy but incorrect answer to sharing data.
  • Constructor Details

    • StructureService

      public StructureService()
  • Method Details

    • register

      public void register(Entity entity)
      Register a new entity with the entity service. The entity will be created and start updating.
      Overrides:
      register in class EntityService
      Parameters:
      entity - new entity.
    • registerNamed

      public void registerNamed(String name, Entity entity)
      Registers an entity with a name, so it can be found later
      Overrides:
      registerNamed in class EntityService
      Parameters:
      name - the name to register it as (must be unique or will overwrite)
      entity - the entity to register
    • getNamedEntity

      public Entity getNamedEntity(String name)
      Returns a registered named entity
      Overrides:
      getNamedEntity in class EntityService
      Parameters:
      name - the name the entity was registered as
      Returns:
      the registered entity or null
    • getLastEntity

      public Entity getLastEntity()
      Returns the last registered entity
      Overrides:
      getLastEntity in class EntityService
      Returns:
      the last registered entity or null
    • getAllNamedEntities

      public Map<String,Entity> getAllNamedEntities()
      Returns all registered entities
      Overrides:
      getAllNamedEntities in class EntityService
      Returns:
      all registered entities or null
    • unregister

      public void unregister(Entity entity)
      Unregister an entity with the entity service. The entity will be removed and stop updating.
      Overrides:
      unregister in class EntityService
      Parameters:
      entity - entity to be removed.
    • update

      public void update()
      Update all registered entities. Should only be called from the main game loop.
      Overrides:
      update in class EntityService
    • dispose

      public void dispose()
      Dispose all entities.
      Overrides:
      dispose in class EntityService
    • buildStructure

      public static Boolean buildStructure(String structureName, com.badlogic.gdx.math.GridPoint2 gridPos)
      Builds a structure at specific location, gridPos. the type of structure built is determined by the specific structure name, structureName.
      Parameters:
      structureName - name of the structure to build (also type of structure)
      gridPos - location of where the structure is to be built
      Returns:
      true if building was build successfully, false otherwise
    • getTempBuildState

      public static Boolean getTempBuildState()
      gets the building temp entity state
      Returns:
      True if building a building from the inventory or False if not building a building from the inventory
    • getTempEntityName

      public static String getTempEntityName()
      gets the temp building name
      Returns:
      name of the temp entity
    • setTempBuildState

      public void setTempBuildState(Boolean state)
      Set the building temp entity state
      Parameters:
      state - state to set the buildingTempEntity state to.
    • buildTempStructure

      public static void buildTempStructure(String name)
      Builds a structure and locks it to the mouse as the user decides where to build it
      Parameters:
      name - of the tempStructureEntity
    • drawVisualFeedback

      public static void drawVisualFeedback(com.badlogic.gdx.math.GridPoint2 centerCoord, String entityType)
      Draw the coloured tiles around a structure to show the player where they can build a structure
      Parameters:
      centerCoord - location of the structure in gridPoint2
      entityType - type of entity being checked
    • clearVisualTiles

      public static void clearVisualTiles()
      Clear the coloured visual tiles by disposing of them
    • rotateTempStructure

      public static void rotateTempStructure()
      Rotate the current temp structure
    • getStructureOrientation

      public static int getStructureOrientation()
      get the orientation of the structure being built (facing forward or facing right)
      Returns:
    • toggleStructureOrientation

      public static void toggleStructureOrientation()
      toggle the structure orientation from 0 to 1 or from 1 to 0
    • setUiPopUp

      public static void setUiPopUp(int screenX, int screenY)
    • SellBuilding

      public String SellBuilding(String buildingName, com.badlogic.gdx.math.GridPoint2 entityCords)