class

WAD

Inherits WritingAdditions::WAD < RaylibAdditions::WAD < Reference < Object

Reading a .WAD file's data

To simply read in a WAD file, you just call WAD.read(file : Path | String | IO) : WAD:

my_string_wad = WAD.read("Path/To/Wad")
my_path_wad = WAD.read(Path["Path/To/Wad"])

File.open("Path/To/Wad") do |file|
  my_io_wad = WAD.read(file)
end

Creating a new WAD

To create a new WAD, you call WAD.new(type), with type being of WAD::Type

my_new_internal_wad = WAD.new(WAD::Type::Internal)
my_new_patch_wad = WAD.new(WAD::Type::Patch)

Using the WAD's data

wa-cr sorts the the parsed wad's data into easy to use variables.

To get the sample rate of the sound "MYSOUND":

my_wad.sounds["MYSOUND"].sample_rate # => returns the sample rate of the sound

To get y_position of the 34th thing in the map "MAP23":

# Gets the thing index 33 because it is zero indexed: the 33rd index is the 34th thing
my_wad.maps["MAP23"].things[33].y_position # => returns the y_position of the thing

Lumps

You can also read in .lmp lump files:

NOTE: Graphic.parse can take 2 arguments: The file to read and the position of the start of the data (Default is -1. Should almost always be -1 when reading a .lmp)

my_string_graphic = WAD::Graphic.parse("Path/To/MyGraphic.lmp")
my_path_graphic = WAD::Graphic.parse(Path["Path/To/MyGraphic.lmp"])

File.open("Path/To/MyGraphic.lmp") do |file|
  my_io_graphic = WAD::Graphic.parse(file)
end
my_string_flat = WAD::Flat.parse("Path/To/MyFlat.lmp")
my_path_flat = WAD::Flat.parse(Path["Path/To/MyFlat.lmp"])

File.open("Path/To/MyFlat.lmp") do |file|
  my_io_flat = WAD::Flat.parse(file)
end
my_string_sound = WAD::Sound.parse("Path/To/MySound.lmp")
my_path_sound = WAD::Sound.parse(Path["Path/To/MySound.lmp"])

File.open("Path/To/MySound.lmp") do |file|
  my_io_sound = WAD::Sound.parse(file)
end

Constants

HEADER_SIZE = 16

The size of the header in bytes

Constructors

new(type : Type = Type::Broken)
read(filename : Path | String) : WAD

Reads in a WAD file given the filename:

my_wad = WAD.read("Path/To/Wad")
read(file : IO, *, throw_errors : Bool = false) : WAD

Reads in a WAD file given the io:

File.open("Path/To/Wad") do |file|
  my_wad = WAD.read(file)
end
read!(file : IO) : WAD

Reads in a WAD file given the io but returns all errors thrown when parsing lumps:

File.open("Path/To/Wad") do |file|
  my_wad = WAD.read!(file)
end
read!(filename : Path | String) : WAD

Reads in a WAD file given the filename but returns all errors thrown when parsing lumps:

my_wad = WAD.read!("Path/To/Wad")

Class methods

read?(file : IO) : WAD | Nil

Reads in a WAD file given the io but returns Nil if parsing the WAD throws an error:

File.open("Path/To/Wad") do |file|
  my_wad = WAD.read?(file)
end
read?(filename : Path | String) : WAD | Nil

Reads in a WAD file given the filename but returns Nil if parsing the WAD throws an error:

my_wad = WAD.read?("Path/To/Wad")
slice_cut(slice : Slice, len : Int = 8) : Slice

Cuts a slice down to length len if it is larger than len:

my_slice = "My Test Slice".to_slice # => Bytes[77, 121, 32, 84, 101, 115, 116, 32, 83, 108, 105, 99, 101]
WAD.slice_cut(my_slice, 5)          # => Bytes[77, 121, 32, 84, 101]
string_cut(string : String, len : Int = 8) : String

Cuts a string down to length len if it is larger than len:

WAD.string_cut("Aberdine", 4) # => "Aber"
string_sub_chars(string : String) : String

Replaces all instances of ms-dos name incompatible chars of a string with "~":

my_string = "My.TestString"
WAD.string_sub_chars(my_string) # => "My~Test~String"

Instance methods

add(name : String, type : AddTypes, file : Path | String)

Allows easy parsing of lumps into the WAD

my_wad = WAD.new(WAD::Type::Internal)

my_wad.add("MyTest", WAD::AddTypes::Sound, "Path/To/SoundTest.lmp")
add(name : String, type : AddTypes, file : IO)

Allows easy parsing of lumps into the WAD

my_wad = WAD.new(WAD::Type::Internal)

File.open("Path/To/Sound.lmp") do |file|
  my_wad.add("MyTest", WAD::AddTypes::Sound, file)
end
clone

Returns a copy of self with all instance variables cloned.

colormap

The Colormap in the WAD.

colormap=(colormap : Colormap)

The Colormap in the WAD.

demos

Array of Demos in the WAD.

demos=(demos : Hash(String, Demo))

Array of Demos in the WAD.

directories

Array of all directories in the WAD.

directories=(directories : Array(Directory))

Array of all directories in the WAD.

directories_count

An integer specifying the number of lumps in the WAD.

directories_count=(directories_count : UInt32)

An integer specifying the number of lumps in the WAD.

directory_pointer

An integer holding a pointer to the location of the directory.

directory_pointer=(directory_pointer : UInt32)

An integer holding a pointer to the location of the directory.

dmxgus

The Dmxgus in the WAD.

dmxgus=(dmxgus : Dmxgus)

The Dmxgus in the WAD.

endoom

The Endoom in the WAD.

endoom=(endoom : EnDoom)

The Endoom in the WAD.

flats

Array of Flats in the WAD.

flats=(flats : Hash(String, Flat))

Array of Flats in the WAD.

genmidi

The Genmidi in the WAD.

genmidi=(genmidi : Genmidi)

The Genmidi in the WAD.

graphics

Array of Graphics and patches in the WAD.

graphics=(graphics : Hash(String, Graphic))

Array of Graphics and patches in the WAD.

maps

Array of maps in the WAD.

maps=(maps : Hash(String, Map))

Array of maps in the WAD.

music

Array of music in the WAD.

music=(music : Hash(String, Music))

Array of music in the WAD.

new_dir(name : String)

Creates a new empty directory with name and puts it onto the list of directories. WARNING: Directory will not work if name is not the correct name of the data

File.open("Path/To/MySound.lmp", "w+") do |file|
  my_wad.["MYSOUND"] = WAD::Sound.parse(file)
  my_wad.new_dir("MYSOUND")
end
pcsounds

Array of speaker sounds in the WAD.

pcsounds=(pcsounds : Hash(String, PcSound))

Array of speaker sounds in the WAD.

playpal

The Playpal in the WAD.

playpal=(playpal : Playpal)

The Playpal in the WAD.

pnames

The Pnames in the WAD.

pnames=(pnames : Pnames)

The Pnames in the WAD.

rename_lump(to_rename : String, name : String) : Bool

Renames a lump that can be renamed in the WAD Usually used when renaming a directory

sounds

Array of sounds in the WAD.

sounds=(sounds : Hash(String, Sound))

Array of sounds in the WAD.

sprites

Array of Sprites in the WAD.

sprites=(sprites : Hash(String, Graphic))

Array of Sprites in the WAD.

texmaps

Array of texture maps in the WAD.

texmaps=(texmaps : Hash(String, TextureX))

Array of texture maps in the WAD.

type

Type of WAD: Either Internal, IWAD, or Patch, PWAD.

type=(type : Type)

Type of WAD: Either Internal, IWAD, or Patch, PWAD.

what_is?(name : String) : String

Finds what a name is in the WAD Usually used to find what type a directory points to

Nested types