Package edu.ntnu.idi.idatt.dto
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Enum representing the type of game board component.static enum
Enum representing the direction of a component's dimension (width or height). -
Constructor Summary
ConstructorsConstructorDescriptionComponentSpec
(int widthTiles, ComponentSpec.Direction widthDirection, int heightTiles, ComponentSpec.Direction heightDirection, ComponentSpec.ComponentType type) Creates an instance of aComponentSpec
record class. -
Method Summary
Modifier and TypeMethodDescriptiondouble
calculateHeight
(double tileHeight) Calculates the height of the component in pixels.double
calculateTranslateX
(double tileWidth) Calculates the X-axis translation needed for the component based on its width and direction.double
calculateTranslateY
(double tileHeight) Calculates the Y-axis translation needed for the component based on its height and direction.double
calculateWidth
(double tileWidth) Calculates the width of the component in pixels.final boolean
Indicates whether some other object is "equal to" this one.static ComponentSpec
fromFilename
(String filename) Creates aComponentSpec
by parsing a filename string.final int
hashCode()
Returns a hash code value for this object.Returns the value of theheightDirection
record component.int
Returns the value of theheightTiles
record component.final String
toString()
Returns a string representation of this record class.type()
Returns the value of thetype
record component.Returns the value of thewidthDirection
record component.int
Returns the value of thewidthTiles
record component.
-
Constructor Details
-
ComponentSpec
public ComponentSpec(int widthTiles, ComponentSpec.Direction widthDirection, int heightTiles, ComponentSpec.Direction heightDirection, ComponentSpec.ComponentType type) Creates an instance of aComponentSpec
record class.- Parameters:
widthTiles
- the value for thewidthTiles
record componentwidthDirection
- the value for thewidthDirection
record componentheightTiles
- the value for theheightTiles
record componentheightDirection
- the value for theheightDirection
record componenttype
- the value for thetype
record component
-
-
Method Details
-
fromFilename
Creates aComponentSpec
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
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. -
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. -
equals
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 withObjects::equals(Object,Object)
; primitive components are compared with '=='. -
widthTiles
public int widthTiles()Returns the value of thewidthTiles
record component.- Returns:
- the value of the
widthTiles
record component
-
widthDirection
Returns the value of thewidthDirection
record component.- Returns:
- the value of the
widthDirection
record component
-
heightTiles
public int heightTiles()Returns the value of theheightTiles
record component.- Returns:
- the value of the
heightTiles
record component
-
heightDirection
Returns the value of theheightDirection
record component.- Returns:
- the value of the
heightDirection
record component
-
type
Returns the value of thetype
record component.- Returns:
- the value of the
type
record component
-