Skip to content
Back to top
View this page

# `structures`

Module containing basic and general structures that occur in Terraria save files.

It has three submodules, each containing a different structure:

1. `lihzahrd.terraria.utils.structures.color`

2. `lihzahrd.terraria.utils.structures.coordinates`

3. `lihzahrd.terraria.utils.structures.rectangle`

## `color`

Submodule for color structures.

class lihzahrd.terraria.utils.structures.color.ColorRGB(*, r: int, g: int, b: int)
class lihzahrd.terraria.utils.structures.color.ColorRGB(*, r: float, g: float, b: float)
class lihzahrd.terraria.utils.structures.color.ColorRGB(*, h: str)

  An opaque 24-bit color.

  Can be created from RGB integers (0-255), from RGB floats (0.0-1.0), or from a hex code.

  ### Creating from RGB integers

  RGB integers are converted to floats via `component / 255`.

  Warning

  No checks are performed to make sure the components are within the expected ranges (`0` - `255`)!

  param r:

    Red component.

  param g:

    Green component.

  param b:

    Blue component.

  ### Creating from RGB floats

  RGB floats are stored directly in the structure, without being altered.

  Warning

  No checks are performed to make sure the components are within the expected ranges (`0.0` - `1.0`)!

  param r:

    Red component.

  param g:

    Green component.

  param b:

    Blue component.

  ### Creating from hex code

  Hex codes are converted to RGB floats via `int(h[n:n+2], 16) / 255`.

  Trailing `#` are optionally stripped.

  Warning

  No checks are performed to make sure the hex code is valid!

  param h:

    Hex color.

  ### Attributes and methods

  r: float

    The red component of the color.

  g: float

    The green component of the color.

  b: float

    The blue component of the color.

  __iter__() → Iterator[float]
    Returns:

      `r`, `g`, and `b` in order.

## `coordinates`

Submodule for pairs of coordinates.

class lihzahrd.terraria.utils.structures.coordinates.Coordinates(x: Value, y: Value)

  A pair of coordinates of the generic type `InternalValue`.

  In Terraria worlds, `InternalValue` will be either `float` (usually when referring to entities) or `int` (usually when referring to tiles).

  x: Value

    The horizontal coordinate, with the negative axis being left, and the positive axis being right.

  y: Value

    The vertical coordinate, with the negative axis being up, and the negative axis being down.

  __iter__() → Iterator
    Returns:

      `x` then `y`, in that order.

  __eq__(other: Any) → bool
    Returns:

      If compared with other `Coordinates`, whether both individual coordinates are equal. Otherwise, `NotImplemented`.

  __ne__(other: Any) → bool
    Returns:

      If compared with other `Coordinates`, whether either coordinate is not equal to its corrispective. Otherwise, `NotImplemented`.

## `rectangle`

Submodule for rectangle structures.

class lihzahrd.terraria.utils.structures.rectangle.Rectangle(left: Value, right: Value, top: Value, bottom: Value)

  A rectangle of generic type `InternalValue` in a cartesian plane, not locked to the origin.

  In Terraria worlds, `InternalValue` will always be `int`.

  left: Value

    Coordinate of the left edge of the rectangle.

  right: Value

    Coordinate of the right edge of the rectangle.

  top: Value

    Coordinate of the top edge of the rectangle.

  bottom: Value

    Coordinate of the bottom edge of the rectangle.

  __iter__() → Iterator
    Returns:

      The edges in the order they are written in Terraria save files: `left`, `right`, `top`, then `bottom`.