Cauldron2D.GameMaker.Data (Cauldron2D.GameMaker v0.2.1)

Copy Markdown View Source

A GameMaker game's data file read whole: data.win on Windows, game.ios on macOS and iOS, game.unx on Linux, game.droid on Android. Every platform's file has the same layout.

{:ok, data} = Cauldron2D.GameMaker.Data.read("path/to/data.win")
data.general.name
Enum.map(data.rooms, & &1.name)

Resources are lists in the game's own order, so a resource's index, which the game's code and other resources refer to it by, is its place in its list. textures are the texture pages, still encoded; Cauldron2D.GameMaker.Pictures decodes them. audio holds the stored sounds' bytes, indexed by Cauldron2D.GameMaker.Sound's audio.

options is nil when the file's options use the older layout (Cauldron2D.GameMaker.Options).

A file whose game code is compiled to bytecode keeps that code in its CODE, VARI and FUNC chunks; bytecode?/1 tells such a file from one whose code was compiled into the executable. The bytecode itself is not read here.

Summary

Functions

The stored sounds of the audio group file at path (audiogroup1.dat and on, beside the data file), indexed as Cauldron2D.GameMaker.Sound's audio for sounds whose group is that number.

Whether the game's code is carried in the data file as bytecode.

The index of the resource called name in list, nil if there is none; the first of that name when several share it. list is one of :sprites, :backgrounds, :objects, :rooms, :sounds, :fonts, :paths and :scripts.

The data file in bytes.

The data file at path.

Types

t()

@type t() :: %Cauldron2D.GameMaker.Data{
  audio: [binary()],
  audio_groups: [String.t()],
  backgrounds: [Cauldron2D.GameMaker.Background.t()],
  chunks: Cauldron2D.GameMaker.Chunks.t(),
  fonts: [Cauldron2D.GameMaker.Font.t()],
  general: Cauldron2D.GameMaker.General.t(),
  names: %{required(atom()) => %{required(String.t()) => non_neg_integer()}},
  objects: [Cauldron2D.GameMaker.Object.t()],
  options: Cauldron2D.GameMaker.Options.t() | nil,
  paths: [Cauldron2D.GameMaker.Path.t()],
  rooms: [Cauldron2D.GameMaker.Room.t()],
  scripts: [Cauldron2D.GameMaker.Script.t()],
  sounds: [Cauldron2D.GameMaker.Sound.t()],
  sprites: [Cauldron2D.GameMaker.Sprite.t()],
  textures: [Cauldron2D.GameMaker.Texture.t()]
}

Functions

audio_group(path)

@spec audio_group(Path.t()) :: {:ok, [binary()]} | {:error, term()}

The stored sounds of the audio group file at path (audiogroup1.dat and on, beside the data file), indexed as Cauldron2D.GameMaker.Sound's audio for sounds whose group is that number.

bytecode?(data)

@spec bytecode?(t()) :: boolean()

Whether the game's code is carried in the data file as bytecode.

index(data, list, name)

@spec index(t(), atom(), String.t()) :: non_neg_integer() | nil

The index of the resource called name in list, nil if there is none; the first of that name when several share it. list is one of :sprites, :backgrounds, :objects, :rooms, :sounds, :fonts, :paths and :scripts.

parse(bytes)

@spec parse(binary()) :: {:ok, t()} | {:error, :not_a_data_file | :no_header}

The data file in bytes.

read(path)

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

The data file at path.