ExPilot.Shipshape (ExPilot v0.1.1)

Copy Markdown View Source

XPilot ship shapes, as players wrote them.

ExPilot.Shipshape.parse("(SH: 15,0 -8,8 -8,-8)(EN: -8,0)(MG: 15,0)")
# => %{outline: [{15, 0}, {-8, 8}, {-8, -8}], engine: {-8, 0}, guns: [{15, 0}]}

The outline's x points to the ship's nose and y is upward. Sections not present default to an engine at the rearmost point and one gun at the nose.

Summary

Functions

The classic default ship.

Parse a shipshape string; {:error, reason} when it has no valid outline.

As parse/1, raising on a bad shape.

Types

point()

@type point() :: {integer(), integer()}

t()

@type t() :: %{outline: [point()], engine: point(), guns: [point()]}

Functions

default()

@spec default() :: t()

The classic default ship.

parse(text)

@spec parse(String.t()) :: {:ok, t()} | {:error, term()}

Parse a shipshape string; {:error, reason} when it has no valid outline.

parse!(text)

@spec parse!(String.t()) :: t()

As parse/1, raising on a bad shape.