Record Class MapDefinition

java.lang.Object
java.lang.Record
dev.zwazel.internal.game.map.MapDefinition

public record MapDefinition(long width, long depth, SimplifiedRGB floorColor, float[][] tiles, LayerDefinition[] layers, MarkerDefinition[] markers) extends Record
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final float
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    MapDefinition(long width, long depth, SimplifiedRGB floorColor, float[][] tiles, LayerDefinition[] layers, MarkerDefinition[] markers)
    Creates an instance of a MapDefinition record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Returns the value of the depth record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    Returns the value of the floorColor record component.
    Returns the Coordinates of the closest tile to the given world position in the map grid.
    getTile(int x, int y)
    Returns the tile at the given grid coordinates as a Vec3.
    Returns the tile at the given grid coordinates as a Vec3.
    float
    getTileHeight(int x, int y)
    Returns the height of the tile at the given grid coordinates.
    float
    Returns the height of the tile at the given grid coordinates.
    getWorldTileCenter(int x, int y)
    Returns the center of the tile in world coordinates.
    Returns the world coordinates of the tile centers in the map grid as a list.
    final int
    Returns a hash code value for this object.
    Returns the value of the layers record component.
    Returns the value of the markers record component.
    float[][]
    Returns the value of the tiles record component.
    Returns a string representation of this record class.
    long
    Returns the value of the width record component.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • MapDefinition

      public MapDefinition(long width, long depth, SimplifiedRGB floorColor, float[][] tiles, LayerDefinition[] layers, MarkerDefinition[] markers)
      Creates an instance of a MapDefinition record class.
      Parameters:
      width - the value for the width record component
      depth - the value for the depth record component
      floorColor - the value for the floorColor record component
      tiles - the value for the tiles record component
      layers - the value for the layers record component
      markers - the value for the markers record component
  • Method Details

    • getClosestTileFromWorld

      public Vec3 getClosestTileFromWorld(Vec3 worldPos)
      Returns the Coordinates of the closest tile to the given world position in the map grid. The closest tile is the tile whose center is closest to the given world position. The y coordinate of the world position must be positive. If the y coordinate of the world position is negative, an IllegalArgumentException is thrown. The y coordinate of the returned Vec3 is the height of the tile. The returned Vec3 is in grid coordinates, not world coordinates. The given Vec3 must be in world coordinates, not grid coordinates.
      Parameters:
      worldPos - the world position
      Returns:
      the closest tile to the world position, as a Vec3.
    • gridToWorld

      public ArrayList<Vec3> gridToWorld()
      Returns the world coordinates of the tile centers in the map grid as a list.
      Returns:
      the world coordinates of the tile centers in the map grid
    • getWorldTileCenter

      public Vec3 getWorldTileCenter(int x, int y)
      Returns the center of the tile in world coordinates.
      Parameters:
      x - the x coordinate of the tile in the map grid (0-indexed)
      y - the y coordinate of the tile in the map grid (0-indexed)
      Returns:
      the world coordinate of the center of the tile
    • getTileHeight

      public float getTileHeight(int x, int y)
      Returns the height of the tile at the given grid coordinates.
      Parameters:
      x - the x coordinate of the tile in the map grid (0-indexed)
      y - the y coordinate of the tile in the map grid (0-indexed)
      Returns:
      the height of the tile
    • getTileHeight

      public float getTileHeight(Vec3 pos)
      Returns the height of the tile at the given grid coordinates.
      Parameters:
      pos - the grid coordinates of the tile, not world coordinates! The y coordinate is the height of the tile. The y coordinate is ignored in this method. The z coordinate of the given Vec3 is the y coordinate of the tile in the 2D map grid. The x coordinate of the given Vec3 is the x coordinate of the tile in the 2D map grid.
      Returns:
      the height of the tile
    • getTile

      public Vec3 getTile(int x, int y)
      Returns the tile at the given grid coordinates as a Vec3.
      Parameters:
      x - the x coordinate of the tile in the map grid (0-indexed)
      y - the y coordinate of the tile in the map grid (0-indexed)
      Returns:
      the tile as a Vec3 in grid coordinates. the y is the height of the tile.
    • getTile

      public Vec3 getTile(Vec3 pos)
      Returns the tile at the given grid coordinates as a Vec3.
      Parameters:
      pos - the grid coordinates of the tile, not world coordinates! The y coordinate is the height of the tile. The y coordinate is ignored in this method. The z coordinate of the given Vec3 is the y coordinate of the tile in the 2D map grid. The x coordinate of the given Vec3 is the x coordinate of the tile in the 2D map grid.
      Returns:
      the tile as a Vec3 in grid coordinates. the y is always 0, as this is a 2D map.
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • width

      public long width()
      Returns the value of the width record component.
      Returns:
      the value of the width record component
    • depth

      public long depth()
      Returns the value of the depth record component.
      Returns:
      the value of the depth record component
    • floorColor

      public SimplifiedRGB floorColor()
      Returns the value of the floorColor record component.
      Returns:
      the value of the floorColor record component
    • tiles

      public float[][] tiles()
      Returns the value of the tiles record component.
      Returns:
      the value of the tiles record component
    • layers

      public LayerDefinition[] layers()
      Returns the value of the layers record component.
      Returns:
      the value of the layers record component
    • markers

      public MarkerDefinition[] markers()
      Returns the value of the markers record component.
      Returns:
      the value of the markers record component