Class Item

java.lang.Object
group24.escaperoom.entities.Item
All Implemented Interfaces:
com.badlogic.gdx.utils.Json.Serializable, Drawable

public class Item extends Object implements com.badlogic.gdx.utils.Json.Serializable, Drawable
  • Field Details

    • map

      @Null public MapScreen map
      A reference to the MapScreen that this item is current on.
    • id

      public int id
    • position

      public Types.IntVector2 position
    • renderPriority

      public int renderPriority
      The render priority of this item. This is how "high up" the item is in the world.
    • selected

      public boolean selected
      Whether this item is currently selected
    • flipped

      public boolean flipped
      flipped represents whether or not an item is rotated in such a way that it's width and height are "flipped". This is only relevant for items with widths and heigts that are not equal e.g. _______ | | -------
    • mirrorH

      public boolean mirrorH
      Whether this item's texture is mirrored horizontally (mirrorH) and/or mirrored vertically (mirrorV)
    • mirrorV

      public boolean mirrorV
      Whether this item's texture is mirrored horizontally (mirrorH) and/or mirrored vertically (mirrorV)
    • color

      public com.badlogic.gdx.graphics.Color color
      color is the color applied to this batch before drawing this item
    • occupiedSize

      public Types.Size occupiedSize
      occupiedSize is the dynamically adjusted size of this item that changes with rotations
    • itemSize

      public Types.Size itemSize
      item is the effectively final size of the item in world units, as if no transformations have occured.
  • Constructor Details

    • Item

      public Item()
      Empty constructor for Json.Serializable compatability
    • Item

      public Item(ObjectTypeData typeData)
      Construct an item from ObjectTypeData
      Parameters:
      typeData - to construct from
  • Method Details

    • initItem

      public void initItem(ObjectTypeData typeData)
    • write

      public void write(com.badlogic.gdx.utils.Json json)
      Write our this items json to json
      Specified by:
      write in interface com.badlogic.gdx.utils.Json.Serializable
    • read

      public void read(com.badlogic.gdx.utils.Json json, com.badlogic.gdx.utils.JsonValue jsonData)
      Read item json to initialize this item
      Specified by:
      read in interface com.badlogic.gdx.utils.Json.Serializable
    • printString

      public String printString()
    • update

      public void update(float delta)
      Update item state
      Parameters:
      delta - amount of time since the last call
    • reloadTexture

      public void reloadTexture()
      Force an item to reload its texture
    • clone

      public Item clone()
      Get an exact clone of this item, copying all attributes except id
      Overrides:
      clone in class Object
      Returns:
      an clone of this item with a new id
    • clone

      public Item clone(boolean preserveID)
      Get an exact clone of this item
      Parameters:
      preserveID - whether or not to assign a new id to the newly created item
      Returns:
      A clone of this item
    • copy

      public Item copy()
      Returns:
      a copy of this item, respecting any property values that are non-copyable (like ItemContainsItem)
    • getItemName

      public String getItemName()
      Returns:
      the User-facing String describing this Item - This includes an optional style prefix followed by the name spcecified by ObjectTypeData.name
    • getPlayerActions

      public com.badlogic.gdx.utils.Array<PlayerAction> getPlayerActions(GameContext ctx)
      Parameters:
      ctx - the GameContext
      Returns:
      the available PlayerActions for this item
    • adjustTextureRegion

      public void adjustTextureRegion(int x, int y, int width, int height)
      Set the region of the underlying texture for this item
      Parameters:
      x - region-local offset in the x-direction
      y - region-local offset in the y-direction
      width - new width
      height - new height
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

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

      public void remove(boolean temporary)
      Remove this item from the map
      Parameters:
      temporary - whether or not this removal is temporary this param signals to the map that this item will likely soon be replaced
    • remove

      public void remove()
      Remove this item from the map
      See Also:
    • addProperty

      public void addProperty(ItemProperty<? extends ItemPropertyValue> property)
      Add a property to this item
      Parameters:
      property - to add
    • removeProperty

      public void removeProperty(PropertyType type)
      remove a property to from item
      Parameters:
      type - to remove
    • hasProperty

      public boolean hasProperty(PropertyType type)
      Parameters:
      type - to query
      Returns:
      whether this item has a certain property
    • getProperties

      public Collection<ItemProperty<? extends ItemPropertyValue>> getProperties()
    • getProperty

      public Optional<ItemProperty<? extends ItemPropertyValue>> getProperty(PropertyType type)
    • getProperty

      public <T extends ItemPropertyValue, P extends ItemProperty<T>> Optional<P> getProperty(PropertyType type, Class<P> expectedClass)
    • getProperties

      public com.badlogic.gdx.utils.Array<ItemProperty<? extends ItemPropertyValue>> getProperties(PropertyType... types)
    • mirrorHorizontal

      public void mirrorHorizontal()
      Set whether this item's texture is mirrored horizontally
    • setRenderPriority

      public void setRenderPriority(int priority)
      Set the render priority of this item
      Parameters:
      priority - new value
    • setWidth

      public void setWidth(int width)
      Set width - This is the original width of the item, not the currently occupied width
      Parameters:
      width - new value
    • setHeight

      public void setHeight(int height)
      Set height - This is the original height of the item, not the currently occupied height
      Parameters:
      height - new value
    • increaseRenderPriotity

      public void increaseRenderPriotity()
      Increase this item's render priority
    • decreaseRenderPriotity

      public void decreaseRenderPriotity()
      Decrease this item's render priority
    • mirrorVertical

      public void mirrorVertical()
      Set whether this item's texture is mirrored veritcally
    • setHighlighed

      public void setHighlighed(boolean highlighted)
    • setDimmed

      public void setDimmed(boolean dimmed)
    • setPosition

      public void setPosition(Types.IntVector2 pos)
      Set the position of this item
      Parameters:
      pos - new value
      See Also:
    • setPosition

      public void setPosition(int x, int y)
      Set the position of this item
      Parameters:
      x - new x coord
      y - new y coord
      See Also:
    • moveTo

      public void moveTo(int x, int y)
      Move the item. This differs from setPosition(int,int) in it updates various properties that depend on position. e.g. TiledBrushable items need to refresh their adjacency
      Parameters:
      x - new x coord
      y - new y coord
    • setBlocksPlayer

      public void setBlocksPlayer(float offsetX, float offsetY, float blockWidth, float blockHeight)
      Set if this object should block player movement
      Parameters:
      offsetX - from the bottom left corner for the start of the blocking region
      offsetY - from the bottom left corner for the start of the blocking region
      blockWidth - width of the blocking region
      blockHeight - height of the blocking region
    • setTexture

      public void setTexture(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion region)
      Set the texture of this item.
      Parameters:
      region - new region
    • setFocus

      public void setFocus(boolean isFocused)
      Set whether this item is currently focused by the Player
      Parameters:
      isFocused - whether or not is focused
    • setContained

      public void setContained(boolean isContained)
    • setBlocksPlayer

      public void setBlocksPlayer(boolean blocksPlayer)
      Set if this object should block player movement The region that is blocked is assumed to be the region defined by
       new Rectangle(getX(), getY(), getWidth(), getHeight());
       
      Unless a different region was specified setBlocksPlayer(int,int,int,int)
      Parameters:
      blocksPlayer - whether or not the entire item blocks the player
    • setSelected

      public void setSelected(boolean isSelected)
      Set whether this object is selected in the LevelEditorScreen
      Parameters:
      isSelected - whether or not the item is selected
    • setColor

      public void setColor(com.badlogic.gdx.graphics.Color color)
      Parameters:
      color - new color
    • setColor

      public void setColor(float r, float b, float g, float a)
      Parameters:
      r - red component
      g - green component
      b - blue component
      a - alpha component
    • setAlpha

      public void setAlpha(float alpha)
      Convience method to set the alpha component of this items's Color
      Parameters:
      alpha - new alpha
    • getAlpha

      public float getAlpha()
    • setRotation

      public void setRotation(int degrees)
      Set the logical rotation of this item
      Parameters:
      degrees - new value
    • rotateBy

      public void rotateBy(int degrees)
      Add degrees to this item's logical rotation
      Parameters:
      degrees - amount to add
    • flip

      public void flip()
      This function swaps the item's occuped with and height, toggling its flipped state
    • getX

      public int getX()
      Returns:
      x coordinate of the lower left corner of this item
    • getY

      public int getY()
      Returns:
      y coordinate of the lower left corner of this item
    • blockingRegion

      public Optional<com.badlogic.gdx.math.Rectangle> blockingRegion()
      Returns:
      an Optional region where this object should block player movement If Optional.empty() is returned, this object should not block player movement
      See Also:
    • getTexture

      public com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion getTexture()
      Returns:
      this item's texture
    • getOccupiedRegion

      public com.badlogic.gdx.math.Rectangle getOccupiedRegion()
      This is different than the blockingRegion() in that every object must have an occupied region, but not all objects must block the player. For objects which block the player, it need not be that the blocking region == occupied region
      Returns:
      the items occupied region
    • getPosition

      public Types.IntVector2 getPosition()
      Returns:
      the lower left corner of this item
    • getType

      public ObjectTypeData getType()
      Returns:
      the ObjectTypeData describing this item
    • getOccupiedSize

      public Types.Size getOccupiedSize()
      Returns:
      the occupied size of this item.
      See Also:
    • getID

      public int getID()
    • getHeight

      public int getHeight()
      Returns:
      ths items height getOccupiedSize()
    • getWidth

      public int getWidth()
      Returns:
      ths items width getOccupiedSize()
    • isContained

      public boolean isContained()
      Returns:
      whether or not this item is contained
    • getRotation

      public int getRotation()
      Returns:
      the logical rotation of this item
    • getDrawRotation

      public float getDrawRotation()
      Draw rotation versus logical rotation is relevant for SpinnableProperty items The draw rotation for a spinnable item is always 0; draw(com.badlogic.gdx.graphics.g2d.Batch)
      Returns:
      the draw rotation
    • renderPriority

      public int renderPriority()
      Specified by:
      renderPriority in interface Drawable
      Returns:
      the renderPriority of this Drawable
    • position

      public com.badlogic.gdx.math.Vector2 position()
      Specified by:
      position in interface Drawable
      Returns:
      coordinates of the lower left corner of this Drawable
    • getTileDepth

      public int getTileDepth()
      Specified by:
      getTileDepth in interface Drawable
      Returns:
      the tile depth of this Drawable
    • draw

      public void draw(com.badlogic.gdx.graphics.g2d.Batch batch)
      Description copied from interface: Drawable
      Draw this Drawable on the Batch
      Specified by:
      draw in interface Drawable
      Parameters:
      batch - to draw on