Record Class ComponentSpec

java.lang.Object
java.lang.Record
edu.ntnu.idi.idatt.dto.ComponentSpec
Record Components:
widthTiles - The width of the component in tiles.
widthDirection - The direction of the width (e.g., RIGHT, LEFT).
heightTiles - The height of the component in tiles.
heightDirection - The direction of the height (e.g., UP, DOWN).
type - The type of the component (e.g., LADDER, SLIDE, PORTAL).

public record ComponentSpec(int widthTiles, ComponentSpec.Direction widthDirection, int heightTiles, ComponentSpec.Direction heightDirection, ComponentSpec.ComponentType type) extends Record
ComponentSpec.

A record that defines the specifications for a game board component (e.g., Ladder, Slide, Portal).

It includes dimensions in terms of tiles, direction, and type of the component. This class also provides utility methods to parse specifications from a filename and calculate actual pixel dimensions and translations based on tile sizes.

See Also:
  • Constructor Details

  • Method Details

    • fromFilename

      public static ComponentSpec fromFilename(String filename)
      Creates a ComponentSpec by parsing a filename string. The filename is expected to be in the format: "widthSpec_heightSpec_type.extension", e.g., "1R_2U_ladder.png".
      Parameters:
      filename - The filename string to parse.
      Returns:
      A ComponentSpec instance derived from the filename.
      Throws:
      IllegalArgumentException - if the filename format is invalid.
    • calculateWidth

      public double calculateWidth(double tileWidth)
      Calculates the width of the component in pixels.
      Parameters:
      tileWidth - The width of a single tile in pixels.
      Returns:
      The total width of the component in pixels.
    • calculateHeight

      public double calculateHeight(double tileHeight)
      Calculates the height of the component in pixels.
      Parameters:
      tileHeight - The height of a single tile in pixels.
      Returns:
      The total height of the component in pixels.
    • calculateTranslateX

      public double calculateTranslateX(double tileWidth)
      Calculates the X-axis translation needed for the component based on its width and direction. This is typically used for components that extend to the left.
      Parameters:
      tileWidth - The width of a single tile in pixels.
      Returns:
      The X-axis translation in pixels.
    • calculateTranslateY

      public double calculateTranslateY(double tileHeight)
      Calculates the Y-axis translation needed for the component based on its height and direction.
      Parameters:
      tileHeight - The height of a single tile in pixels.
      Returns:
      The Y-axis translation in pixels.
    • toString

      public final 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 '=='.
      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.
    • widthTiles

      public int widthTiles()
      Returns the value of the widthTiles record component.
      Returns:
      the value of the widthTiles record component
    • widthDirection

      public ComponentSpec.Direction widthDirection()
      Returns the value of the widthDirection record component.
      Returns:
      the value of the widthDirection record component
    • heightTiles

      public int heightTiles()
      Returns the value of the heightTiles record component.
      Returns:
      the value of the heightTiles record component
    • heightDirection

      public ComponentSpec.Direction heightDirection()
      Returns the value of the heightDirection record component.
      Returns:
      the value of the heightDirection record component
    • type

      Returns the value of the type record component.
      Returns:
      the value of the type record component