Class TileContent

java.lang.Object
tech.underoaks.coldcase.state.tileContent.TileContent
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
Door, Door_Trigger, GoalObject, Hole, InvisibleWall, ItemObject, MovableBlock, Player, PortalObject, TestContent, TranscendentTestBlock, UIContentTileContent, Wall

public abstract class TileContent extends Object implements Cloneable
The TileContent class represents the content that can be placed on a Tile. This content can be an item, a static object like a wall, or any other entity that occupies a tile on the game board.

Each instance of TileContent can represent a unique object or type of content. Subclasses or specific instances may be used to specify different types of content.

This class provides a way to abstractly define what exists on a tile without needing to specify the specific type directly within the Tile class.

See Also:
  • Field Details

    • tileContent

      public TileContent tileContent
      Reference to the next TileContent in the stack
    • visibilityState

      protected VisibilityStates visibilityState
      The visibility state of this TileContent
  • Constructor Details

    • TileContent

      public TileContent(com.badlogic.gdx.graphics.Texture texture, boolean isPlayerPassable, boolean isObjectPassable)
      Constructs a new TileContent with the specified texture and passability properties.

      If a texture is provided, a new Sprite is created and its origin is set to the center. The content's visibility is set to VisibilityStates.PLAYER_ONE_ONLY by default.

      Parameters:
      texture - the Texture used for rendering the TileContent; may be null
      isPlayerPassable - true if the content can be passed by the player, false otherwise
      isObjectPassable - true if the content can be passed by objects, false otherwise
  • Method Details

    • render

      public void render(com.badlogic.gdx.graphics.g2d.Batch batch, float x, float y)
      Renders the tileContent at the specified coordinates using the given SpriteBatch. If the tile has no texture, this method renders nothing.

      If the tileContent has a TileContent, the render method of the content is called.

      Parameters:
      batch - the SpriteBatch used to render the tileContent
      x - the x-coordinate for rendering the tile
      y - the y-coordinate for rendering the tile
    • handleAction

      public TileContent handleAction(InteractionChain chain, Interaction interaction) throws GameStateUpdateException
      FIXME JavaDoc Tries to perform the action associated with this TileContent when interacted with.

      handleAction(...) is a recursive function that traverses a stack of TileContents in post order. This means that the top most content gets the first chance to handle a triggered action. If a content handles the action no more contents will be able to accept it.

      Parameters:
      chain - InteractionChain managing the snapshot.
      interaction - The interaction to trigger.
      Returns:
      True if the action has been taken care of; False otherwise
      Throws:
      GameStateUpdateException - If a GameStateUpdate has failed
    • action

      public abstract boolean action(InteractionChain chain, Interaction interaction) throws GameStateUpdateException
      Performs the action associated with this TileContent when interacted with.
      Parameters:
      chain - InteractionChain managing the snapshot.
      interaction - The interaction to trigger.
      Returns:
      True if the action has been taken care of; False otherwise
      Throws:
      GameStateUpdateException - If a GameStateUpdate has failed
    • handleUpdate

      public List<TileContent> handleUpdate(InteractionChain chain, com.badlogic.gdx.math.Vector2 tilePosition, Interaction interaction, TileContent handler) throws GameStateUpdateException, UpdateTileContentException
      FIXME JavaDoc Tries to perform an update associated with this TileContent when triggered.

      handleUpdate(...) is a recursive function that traverses a stack of TileContents in post order. This means that the top most content gets the first chance to handle a triggered update.

      Parameters:
      chain - InteractionChain managing the snapshot.
      tilePosition - The position of the currently selected tile.
      interaction - The interaction that needs to be handled.
      handler - The TileContent that has been handling the interaction so far.
      Returns:
      True if an update as been performed; False otherwise
      Throws:
      GameStateUpdateException - If a GameStateUpdate has failed
      UpdateTileContentException - If a TileContent couldn't be updated (due to a failing validation)
      See Also:
    • update

      public abstract boolean update(InteractionChain chain, com.badlogic.gdx.math.Vector2 tilePosition, Interaction interaction, TileContent handler) throws GameStateUpdateException, UpdateTileContentException
      Updates the state of this TileContent based on interactions.
      Parameters:
      chain - InteractionChain managing the snapshot.
      tilePosition - The position of the currently selected tile.
      interaction - The interaction that is currently being handled.
      handler - The TileContent that has been handling the interaction so far.
      Returns:
      True if an update has been performed; False otherwise
      Throws:
      GameStateUpdateException - If a GameStateUpdate has failed
      UpdateTileContentException - If the TileContent couldn't be updated (due to a failing validation)
      "Implementation Note:"
      Ensure this method returns true only for meaningful changes to avoid unnecessary processing. It should not always return true to prevent infinite loops in calling methods like updateUntilStable. Avoid cyclic updates that could trigger endless interactions.
    • setNextContent

      public void setNextContent(TileContent tileContent)
      Sets the next TileContent in the stack.
      Parameters:
      tileContent - the TileContent to set as the next content in the stack
    • getNextContent

      public TileContent getNextContent()
      Returns the next TileContent in the stack.
      Returns:
      the next TileContent, or null if there is none
    • pushContent

      public void pushContent(TileContent tileContent)
      Adds a new content layer on top of the current stack of contents.
      Parameters:
      tileContent - The TileContent that is being injected into the Map
    • popContent

      public TileContent popContent()
      Removes the topmost content layer from the stack and returns it.
      Returns:
      The topmost TileContent
    • topContent

      public TileContent topContent()
      Retrieves the topmost TileContent in the stack.

      If there are nested contents, this method returns the topmost element. Otherwise, it returns this.

      Returns:
      the topmost TileContent in the stack
    • getVisibilityState

      public VisibilityStates getVisibilityState()
      Returns the current visibility state of this TileContent.
      Returns:
      the VisibilityStates representing the visibility of this content
    • setVisibilityState

      public void setVisibilityState(VisibilityStates visibilityState)
      Sets the visibility state for this TileContent.
      Parameters:
      visibilityState - the new VisibilityStates to apply
    • isObjectPassable

      public boolean isObjectPassable()
      Indicates whether this TileContent is passable by objects.
      Returns:
      true if objects can pass through this content, false otherwise
    • setObjectPassable

      public void setObjectPassable(boolean objectPassable)
      Sets whether this TileContent is passable by objects.
      Parameters:
      objectPassable - true if objects should be able to pass through this content, false otherwise
    • isPlayerPassable

      public boolean isPlayerPassable()
      Indicates whether this TileContent is passable by the player.
      Returns:
      true if the player can pass through this content, false otherwise
    • setPlayerPassable

      public void setPlayerPassable(boolean playerPassable)
      Sets whether this TileContent is passable by the player.
      Parameters:
      playerPassable - true if the player should be able to pass through this content, false otherwise
    • dispose

      public void dispose()
      Disposes of the resources used by this TileContent.

      Releases the underlying texture and disposes any nested TileContent if present.

    • clone

      public TileContent clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • getChildIndex

      public int getChildIndex(TileContent tileContent)
      Returns the index of the specified TileContent in the content stack.

      The current TileContent is considered to have index 0. If the specified content is not found, -1 is returned.

      Parameters:
      tileContent - the TileContent whose index is to be determined
      Returns:
      the index of the specified TileContent, or -1 if not found
    • getTileContentByIndex

      public TileContent getTileContentByIndex(int i)
      Retrieves a TileContent from the content stack by its index.

      An index of 0 returns this TileContent. For higher indices, the method traverses the nested content. If the specified index is not found, an IllegalArgumentException is thrown.

      Parameters:
      i - the index of the desired TileContent (0 for this, 1 for the next, etc.)
      Returns:
      the TileContent at the specified index
      Throws:
      IllegalArgumentException - if no TileContent exists at the given index
    • getTexture

      public com.badlogic.gdx.graphics.Texture getTexture()
      Returns the Texture associated with this TileContent.
      Returns:
      the texture used for rendering, or null if none is set
    • setTexture

      public void setTexture(com.badlogic.gdx.graphics.Texture texture)
      Sets the texture for this TileContent and updates its sprite.
      Parameters:
      texture - the new Texture to be used for rendering
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object