Class TileContent
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
Door,Door_Trigger,GoalObject,Hole,InvisibleWall,ItemObject,MovableBlock,Player,PortalObject,TestContent,TranscendentTestBlock,UIContentTileContent,Wall
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 Summary
FieldsModifier and TypeFieldDescriptionReference to the next TileContent in the stackprotected VisibilityStatesThe visibility state of this TileContent -
Constructor Summary
ConstructorsConstructorDescriptionTileContent(com.badlogic.gdx.graphics.Texture texture, boolean isPlayerPassable, boolean isObjectPassable) Constructs a newTileContentwith the specified texture and passability properties. -
Method Summary
Modifier and TypeMethodDescriptionabstract booleanaction(InteractionChain chain, Interaction interaction) Performs the action associated with this TileContent when interacted with.clone()voiddispose()Disposes of the resources used by this TileContent.booleanintgetChildIndex(TileContent tileContent) Returns the index of the specifiedTileContentin the content stack.Returns the nextTileContentin the stack.com.badlogic.gdx.graphics.TextureReturns theTextureassociated with thisTileContent.getTileContentByIndex(int i) Retrieves aTileContentfrom the content stack by its index.Returns the current visibility state of thisTileContent.handleAction(InteractionChain chain, Interaction interaction) FIXME JavaDoc Tries to perform the action associated with this TileContent when interacted with.handleUpdate(InteractionChain chain, com.badlogic.gdx.math.Vector2 tilePosition, Interaction interaction, TileContent handler) FIXME JavaDoc Tries to perform an update associated with this TileContent when triggered.booleanIndicates whether thisTileContentis passable by objects.booleanIndicates whether thisTileContentis passable by the player.Removes the topmost content layer from the stack and returns it.voidpushContent(TileContent tileContent) Adds a new content layer on top of the current stack of contents.voidrender(com.badlogic.gdx.graphics.g2d.Batch batch, float x, float y) Renders the tileContent at the specified coordinates using the givenSpriteBatch.voidsetNextContent(TileContent tileContent) Sets the nextTileContentin the stack.voidsetObjectPassable(boolean objectPassable) Sets whether thisTileContentis passable by objects.voidsetPlayerPassable(boolean playerPassable) Sets whether thisTileContentis passable by the player.voidsetTexture(com.badlogic.gdx.graphics.Texture texture) Sets the texture for thisTileContentand updates its sprite.voidsetVisibilityState(VisibilityStates visibilityState) Sets the visibility state for thisTileContent.Retrieves the topmostTileContentin the stack.abstract booleanupdate(InteractionChain chain, com.badlogic.gdx.math.Vector2 tilePosition, Interaction interaction, TileContent handler) Updates the state of this TileContent based on interactions.
-
Field Details
-
tileContent
Reference to the next TileContent in the stack -
visibilityState
The visibility state of this TileContent
-
-
Constructor Details
-
TileContent
public TileContent(com.badlogic.gdx.graphics.Texture texture, boolean isPlayerPassable, boolean isObjectPassable) Constructs a newTileContentwith the specified texture and passability properties.If a texture is provided, a new
Spriteis created and its origin is set to the center. The content's visibility is set toVisibilityStates.PLAYER_ONE_ONLYby default.- Parameters:
texture- theTextureused for rendering the TileContent; may benullisPlayerPassable-trueif the content can be passed by the player,falseotherwiseisObjectPassable-trueif the content can be passed by objects,falseotherwise
-
-
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 givenSpriteBatch. 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- theSpriteBatchused to render the tileContentx- the x-coordinate for rendering the tiley- 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 ofTileContents 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 ofTileContents 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 failedUpdateTileContentException- 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 failedUpdateTileContentException- If the TileContent couldn't be updated (due to a failing validation)- "Implementation Note:"
- Ensure this method returns
trueonly for meaningful changes to avoid unnecessary processing. It should not always returntrueto prevent infinite loops in calling methods likeupdateUntilStable. Avoid cyclic updates that could trigger endless interactions.
-
setNextContent
Sets the nextTileContentin the stack.- Parameters:
tileContent- theTileContentto set as the next content in the stack
-
getNextContent
Returns the nextTileContentin the stack.- Returns:
- the next
TileContent, ornullif there is none
-
pushContent
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
Removes the topmost content layer from the stack and returns it.- Returns:
- The topmost
TileContent
-
topContent
Retrieves the topmostTileContentin the stack.If there are nested contents, this method returns the topmost element. Otherwise, it returns this.
- Returns:
- the topmost
TileContentin the stack
-
getVisibilityState
Returns the current visibility state of thisTileContent.- Returns:
- the
VisibilityStatesrepresenting the visibility of this content
-
setVisibilityState
Sets the visibility state for thisTileContent.- Parameters:
visibilityState- the newVisibilityStatesto apply
-
isObjectPassable
public boolean isObjectPassable()Indicates whether thisTileContentis passable by objects.- Returns:
trueif objects can pass through this content,falseotherwise
-
setObjectPassable
public void setObjectPassable(boolean objectPassable) Sets whether thisTileContentis passable by objects.- Parameters:
objectPassable-trueif objects should be able to pass through this content,falseotherwise
-
isPlayerPassable
public boolean isPlayerPassable()Indicates whether thisTileContentis passable by the player.- Returns:
trueif the player can pass through this content,falseotherwise
-
setPlayerPassable
public void setPlayerPassable(boolean playerPassable) Sets whether thisTileContentis passable by the player.- Parameters:
playerPassable-trueif the player should be able to pass through this content,falseotherwise
-
dispose
public void dispose()Disposes of the resources used by this TileContent.Releases the underlying texture and disposes any nested
TileContentif present. -
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
getChildIndex
Returns the index of the specifiedTileContentin the content stack.The current
TileContentis considered to have index 0. If the specified content is not found,-1is returned.- Parameters:
tileContent- theTileContentwhose index is to be determined- Returns:
- the index of the specified
TileContent, or-1if not found
-
getTileContentByIndex
Retrieves aTileContentfrom 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, anIllegalArgumentExceptionis thrown.- Parameters:
i- the index of the desiredTileContent(0 for this, 1 for the next, etc.)- Returns:
- the
TileContentat the specified index - Throws:
IllegalArgumentException- if noTileContentexists at the given index
-
getTexture
public com.badlogic.gdx.graphics.Texture getTexture()Returns theTextureassociated with thisTileContent.- Returns:
- the texture used for rendering, or
nullif none is set
-
setTexture
public void setTexture(com.badlogic.gdx.graphics.Texture texture) Sets the texture for thisTileContentand updates its sprite.- Parameters:
texture- the newTextureto be used for rendering
-
equals
-