class WAD

Overview

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

Included Modules

Defined in:

raylib.cr
wa-cr/wad/wad-data/demo.cr
wa-cr/wad/wad-data/directory.cr
wa-cr/wad/wad-data/map.cr
wa-cr/wad/wad-data/music.cr
wa-cr/wad/wad-data/sound.cr
wa-cr/wad/wad-data/texture.cr
wa-cr/wad/wad.cr
write.cr

Constant Summary

HEADER_SIZE = 16

The size of the header in bytes

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module WritingAdditions::WAD

write(file : String | Path) : UInt32
write(io : IO) : UInt32
write

Instance methods inherited from module RaylibAdditions::WAD

export_texture(texture_name : String, filename : String | Path, palette : ::WAD::Playpal::Palette) export_texture, get_texture(name : String, palette : ::WAD::Playpal::Palette) : Raylib::Image get_texture

Constructor Detail

def self.new(type : Type = Type::Broken) #

def self.read(filename : Path | String) : WAD #

Reads in a WAD file given the filename:

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

def self.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

def self.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

def self.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 Method Detail

def self.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

def self.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")

def self.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]

def self.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"

def self.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 Method Detail

def 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")

def 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

def clone #

Returns a copy of self with all instance variables cloned.


def colormap : Colormap #

The Colormap in the WAD.


def colormap=(colormap : Colormap) #

The Colormap in the WAD.


def demos : Hash(String, Demo) #

Array of Demos in the WAD.


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

Array of Demos in the WAD.


def directories : Array(Directory) #

Array of all directories in the WAD.


def directories=(directories : Array(Directory)) #

Array of all directories in the WAD.


def directories_count : UInt32 #

An integer specifying the number of lumps in the WAD.


def directories_count=(directories_count : UInt32) #

An integer specifying the number of lumps in the WAD.


def directory_pointer : UInt32 #

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


def directory_pointer=(directory_pointer : UInt32) #

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


def dmxgus : Dmxgus #

The Dmxgus in the WAD.


def dmxgus=(dmxgus : Dmxgus) #

The Dmxgus in the WAD.


def endoom : EnDoom #

The Endoom in the WAD.


def endoom=(endoom : EnDoom) #

The Endoom in the WAD.


def flats : Hash(String, Flat) #

Array of Flats in the WAD.


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

Array of Flats in the WAD.


def genmidi : Genmidi #

The Genmidi in the WAD.


def genmidi=(genmidi : Genmidi) #

The Genmidi in the WAD.


def graphics : Hash(String, Graphic) #

Array of Graphics and patches in the WAD.


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

Array of Graphics and patches in the WAD.


def maps : Hash(String, Map) #

Array of maps in the WAD.


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

Array of maps in the WAD.


def music : Hash(String, Music) #

Array of music in the WAD.


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

Array of music in the WAD.


def 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

def pcsounds : Hash(String, PcSound) #

Array of speaker sounds in the WAD.


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

Array of speaker sounds in the WAD.


def playpal : Playpal #

The Playpal in the WAD.


def playpal=(playpal : Playpal) #

The Playpal in the WAD.


def pnames : Pnames #

The Pnames in the WAD.


def pnames=(pnames : Pnames) #

The Pnames in the WAD.


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

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


def sounds : Hash(String, Sound) #

Array of sounds in the WAD.


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

Array of sounds in the WAD.


def sprites : Hash(String, Graphic) #

Array of Sprites in the WAD.


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

Array of Sprites in the WAD.


def texmaps : Hash(String, TextureX) #

Array of texture maps in the WAD.


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

Array of texture maps in the WAD.


def type : Type #

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


def type=(type : Type) #

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


def what_is?(name : String) : String #

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