levelz

Python bindings & API for the LevelZ File Format

Submodules

Classes

Scroll

Represents the scroll direction of a 2D Level.

Level

Represents a LevelZ level.

Level2D

Represents a 2D Level.

Level3D

Represents a 3D Level.

Dimension

Represents a Game Dimension.

Coordinate

Represents a Game Coordinate.

Coordinate2D

Represents a 2-Dimensional Coordinate.

Coordinate3D

Represents a 3-Dimensional Coordinate.

Block

Represents a Block in a Level.

LevelObject

Utility Object for representing a Level Block and its Coordinate.

CoordinateMatrix

Represents a corodinate matrix.

CoordinateMatrix2D

Represents a 2-Dimensional Coordinate Matrix.

CoordinateMatrix3D

Represents a 3-Dimensional Coordinate Matrix.

Functions

parse_level(level)

Parses a Level from a string. Uses 'n' as the line separator.

parse_file(file)

Parses a Level from a file.

parse_lines(level)

Parses a Level from a list of strings.

Package Contents

class levelz.Scroll

Bases: enum.Enum

Represents the scroll direction of a 2D Level.

NONE = 'none'

No Scrolling

HORIZONTAL_LEFT = 'horizontal-left'

Horizontal Scrolling moving left

HORIZONTAL_RIGHT = 'horizontal-right'

Horizontal Scrolling moving right

VERTICAL_UP = 'vertical-up'

Vertical Scrolling moving up

VERTICAL_DOWN = 'vertical-down'

Vertical Scrolling moving down

class levelz.Level(dimension: levelz.coord.Dimension)

Represents a LevelZ level.

_dimension: levelz.coord.Dimension
_blocks: list[levelz.block.LevelObject] = []
_headers: dict[str, object]
property dimension
Returns the Dimension of the Level.
property blocks
Returns an immutable copy of the blocks in the Level.
property headers
Returns an immutable copy of the headers in the Level.
class levelz.Level2D(headers: dict[str, object] = {}, blocks: list[levelz.block.LevelObject] = [])

Bases: Level

Represents a 2D Level.

_headers
_blocks
property scroll
Returns the Scroll of the Level.
property spawn
Returns the spawn point of the Level.
class levelz.Level3D(headers: dict[str, object] = {}, blocks: list[levelz.block.LevelObject] = [])

Bases: Level

Represents a 3D Level.

_headers
_blocks
property spawn
Returns the spawn point of the Level.
class levelz.Dimension

Bases: enum.Enum

Represents a Game Dimension.

TWO = 2

Represents a 2D Plane.

THREE = 3

Represents a 3D Space.

property is2D
Returns True if the Dimension is 2D.
property is3D
Returns True if the Dimension is 3D.
__str__()
__eq__(other)
class levelz.Coordinate

Represents a Game Coordinate.

abstract property magnitude

Return the magnitude of the coordinate.

abstract property dimension

Return the dimension of the coordinate.

class levelz.Coordinate2D(x: float, y: float)

Bases: Coordinate

Represents a 2-Dimensional Coordinate.

x: float = 0

The x-coordinate of the 2D Coordinate.

y: float = 0

The y-coordinate of the 2D Coordinate.

property magnitude
Return the magnitude of the coordinate.
property dimension
Return the dimension of the coordinate.
__str__()
__eq__(other)
static from_string(s: str)

Parses a string to create a 2D Coordinate.

Parameters:

s (str) – The string to parse.

Returns:

The 2D Coordinate.

Return type:

Coordinate2D

class levelz.Coordinate3D(x: float, y: float, z: float)

Bases: Coordinate

Represents a 3-Dimensional Coordinate.

x: float = 0

The x-coordinate of the 3D Coordinate.

y: float = 0

The y-coordinate of the 3D Coordinate.

z: float = 0

The z-coordinate of the 3D Coordinate.

property magnitude
Return the magnitude of the coordinate.
property dimension
Return the dimension of the coordinate.
__str__()
__eq__(other)
static from_string(s: str)

Parses a string to create a 3D Coordinate.

Parameters:

s (str) – The string to parse.

Returns:

The 3D Coordinate.

Return type:

Coordiante3D

class levelz.Block(name: str, properties: dict[str, object] = {})

Represents a Block in a Level.

_name: str = ''
_properties: dict[str, object]
property name
Returns the name of the Block.
property properties
Returns an immutable copy of the properties for the Block.
__str__()
__eq__(other)
class levelz.LevelObject(block: Block | str, coordinate: levelz.coord.Coordinate | list[int | float])

Utility Object for representing a Level Block and its Coordinate.

_block: Block
_coordinate: levelz.coord.Coordinate
property block
Returns the Block of the LevelObject.
property coordinate
Returns the Coordinate of the LevelObject.
__str__()
__eq__(other)
levelz.parse_level(level: str)

Parses a Level from a string. Uses ‘n’ as the line separator.

levelz.parse_file(file: str)

Parses a Level from a file.

levelz.parse_lines(level: list[str])

Parses a Level from a list of strings.

class levelz.CoordinateMatrix

Represents a corodinate matrix.

abstract property dimension

Return the dimension of the matrix.

abstract property coordinates

Return the coordinates of the matrix.

abstract property start

Return the starting coordinate for the matrix.

class levelz.CoordinateMatrix2D(minX: int, maxX: int, minY: int, maxY: int, start: levelz.coord.Coordinate2D)

Bases: CoordinateMatrix

Represents a 2-Dimensional Coordinate Matrix.

minX: int = 0

The minimum x-coordinate of the Matrix.

maxX: int = 0

The maximum x-coordinate of the Matrix.

minY: int = 0

The minimum y-coordinate of the Matrix.

maxY: int = 0

The maximum y-coordinate of the Matrix.

_start: levelz.coord.Coordinate2D
property dimension
Return the dimension of the matrix.
property coordinates
Return the coordinates of the matrix.
property start
Return the starting coordinate for the matrix.
__iter__()
__getitem__(index)
__str__()
__eq__(other)
static from_string(string: str)

Converts a string to a 2D Coordinate Matrix.

Parameters:

string (str) – The string to convert.

Returns:

The 2D Coordinate Matrix.

Return type:

CoordinateMatrix2D

class levelz.CoordinateMatrix3D(minX: int, maxX: int, minY: int, maxY: int, minZ: int, maxZ: int, start: levelz.coord.Coordinate3D)

Bases: CoordinateMatrix

Represents a 3-Dimensional Coordinate Matrix.

minX: int = 0

The minimum x-coordinate of the Matrix.

maxX: int = 0

The maximum x-coordinate of the Matrix.

minY: int = 0

The minimum y-coordinate of the Matrix.

maxY: int = 0

The maximum y-coordinate of the Matrix.

minZ: int = 0

The minimum z-coordinate of the Matrix.

maxZ: int = 0

The maximum z-coordinate of the Matrix.

_start: levelz.coord.Coordinate3D
property dimension
Return the dimension of the matrix.
property coordinates
Return the coordinates of the matrix.
property start
Return the starting coordinate for the matrix.
__iter__()
__getitem__(index)
__str__()
__eq__(other)
static from_string(string: str)

Converts a string to a 3D Coordinate Matrix.

Parameters:

string (str) – The string to convert.

Returns:

The 3D Coordinate Matrix.

Return type:

CoordinateMatrix3D