class WAD
- WAD
- Reference
- Object
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.crwa-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
- .new(type : Type = Type::Broken)
-
.read(filename : Path | String) : WAD
Reads in a WAD file given the filename:
-
.read(file : IO, *, throw_errors : Bool = false) : WAD
Reads in a WAD file given the io:
-
.read!(file : IO) : WAD
Reads in a WAD file given the io but returns all errors thrown when parsing lumps:
-
.read!(filename : Path | String) : WAD
Reads in a WAD file given the filename but returns all errors thrown when parsing lumps:
Class Method Summary
-
.read?(file : IO) : WAD | Nil
Reads in a WAD file given the io but returns
Nil
if parsing theWAD
throws an error: -
.read?(filename : Path | String) : WAD | Nil
Reads in a WAD file given the filename but returns
Nil
if parsing theWAD
throws an error: -
.slice_cut(slice : Slice, len : Int = 8) : Slice
Cuts a slice down to length len if it is larger than len:
-
.string_cut(string : String, len : Int = 8) : String
Cuts a string down to length len if it is larger than len:
-
.string_sub_chars(string : String) : String
Replaces all instances of ms-dos name incompatible chars of a string with "~":
Instance Method Summary
-
#add(name : String, type : AddTypes, file : Path | String)
Allows easy parsing of lumps into the WAD
-
#add(name : String, type : AddTypes, file : IO)
Allows easy parsing of lumps into the WAD
-
#clone
Returns a copy of
self
with all instance variables cloned. -
#colormap : Colormap
The Colormap in the WAD.
-
#colormap=(colormap : Colormap)
The Colormap in the WAD.
-
#demos : Hash(String, Demo)
Array of Demos in the WAD.
-
#demos=(demos : Hash(String, Demo))
Array of Demos in the WAD.
-
#directories : Array(Directory)
Array of all directories in the WAD.
-
#directories=(directories : Array(Directory))
Array of all directories in the WAD.
-
#directories_count : UInt32
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 : UInt32
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 : Dmxgus
The Dmxgus in the WAD.
-
#dmxgus=(dmxgus : Dmxgus)
The Dmxgus in the WAD.
-
#endoom : EnDoom
The Endoom in the WAD.
-
#endoom=(endoom : EnDoom)
The Endoom in the WAD.
-
#flats : Hash(String, Flat)
Array of Flats in the WAD.
-
#flats=(flats : Hash(String, Flat))
Array of Flats in the WAD.
-
#genmidi : Genmidi
The Genmidi in the WAD.
-
#genmidi=(genmidi : Genmidi)
The Genmidi in the WAD.
-
#graphics : Hash(String, Graphic)
Array of Graphics and patches in the WAD.
-
#graphics=(graphics : Hash(String, Graphic))
Array of Graphics and patches in the WAD.
-
#maps : Hash(String, Map)
Array of maps in the WAD.
-
#maps=(maps : Hash(String, Map))
Array of maps in the WAD.
-
#music : Hash(String, 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.
-
#pcsounds : Hash(String, PcSound)
Array of speaker sounds in the WAD.
-
#pcsounds=(pcsounds : Hash(String, PcSound))
Array of speaker sounds in the WAD.
-
#playpal : Playpal
The Playpal in the WAD.
-
#playpal=(playpal : Playpal)
The Playpal in the WAD.
-
#pnames : 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 : Hash(String, Sound)
Array of sounds in the WAD.
-
#sounds=(sounds : Hash(String, Sound))
Array of sounds in the WAD.
-
#sprites : Hash(String, Graphic)
Array of Sprites in the WAD.
-
#sprites=(sprites : Hash(String, Graphic))
Array of Sprites in the WAD.
-
#texmaps : Hash(String, TextureX)
Array of texture maps in the WAD.
-
#texmaps=(texmaps : Hash(String, TextureX))
Array of texture maps in the WAD.
-
#type : 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
Instance methods inherited from module WritingAdditions::WAD
write(file : String | Path) : UInt32write(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
Reads in a WAD file given the filename:
my_wad = WAD.read("Path/To/Wad")
Reads in a WAD file given the io:
File.open("Path/To/Wad") do |file|
my_wad = WAD.read(file)
end
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
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
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
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")
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]
Cuts a string down to length len if it is larger than len:
WAD.string_cut("Aberdine", 4) # => "Aber"
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
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")
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
An integer specifying the number of lumps in the WAD.
An integer holding a pointer to the location of the directory.
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
Renames a lump that can be renamed in the WAD Usually used when renaming a directory