ElixirDoom.Wad (elixir_doom v0.1.0)

Copy Markdown View Source

A Doom WAD file: its lumps by name and in order.

{:ok, wad} = ElixirDoom.Wad.open("DOOM1.WAD")
ElixirDoom.Wad.lump(wad, "PLAYPAL")
ElixirDoom.Wad.between(wad, "S_START", "S_END")

The whole file is read into memory once. Names are upper case, at most eight characters. Where several lumps share a name — a level's THINGS, say — lump/2 gives the last, and level/2 gives a level's own lumps after its marker.

Summary

Functions

The lumps strictly between the markers first and last, in order. Markers that repeat with a doubled letter (FF_START, PP_START) are matched too.

Whether the WAD has a lump called name.

The lumps of level name by lump name: THINGS, LINEDEFS and the rest.

The names of the levels in the WAD, E1M1 or MAP01 style, in order.

The last lump called name, or nil.

The last lump called name; raises KeyError where there is none.

Read the WAD at path.

Read a WAD from its bytes.

Types

lump()

@type lump() :: {String.t(), binary()}

t()

@type t() :: %ElixirDoom.Wad{
  kind: :iwad | :pwad,
  lumps: tuple(),
  names: %{required(String.t()) => non_neg_integer()}
}

Functions

between(wad, first, last)

@spec between(t(), String.t(), String.t()) :: [lump()]

The lumps strictly between the markers first and last, in order. Markers that repeat with a doubled letter (FF_START, PP_START) are matched too.

has?(wad, name)

@spec has?(t(), String.t()) :: boolean()

Whether the WAD has a lump called name.

level(wad, name)

@spec level(t(), String.t()) ::
  {:ok, %{required(String.t()) => binary()}} | {:error, :no_such_level}

The lumps of level name by lump name: THINGS, LINEDEFS and the rest.

levels(wad)

@spec levels(t()) :: [String.t()]

The names of the levels in the WAD, E1M1 or MAP01 style, in order.

lump(wad, name)

@spec lump(t(), String.t()) :: binary() | nil

The last lump called name, or nil.

lump!(wad, name)

@spec lump!(t(), String.t()) :: binary()

The last lump called name; raises KeyError where there is none.

open(path)

@spec open(Path.t()) :: {:ok, t()} | {:error, term()}

Read the WAD at path.

parse(bytes)

@spec parse(binary()) :: {:ok, t()} | {:error, :not_a_wad | :truncated}

Read a WAD from its bytes.