logo

Build Spec

Static Badge

Where's all the Crystal? | wa-cr

A Crystal library used to parse .wad and .lmp files into usable Crystal code, write out to a .wad or .lmp file, and convert file types.

Installation

  1. Add wa-cr to your shard.yml:
dependencies:
  wa-cr:
    github: D-Shwagginz/wa-cr
  1. Run shards install

Raylib Additions

To use the wa-cr's Raylib additions, you must have Raylib installed:

Usage

wa-cr includes many methods that make jumping into and out of a .wad or .lmp file very easy.
Following is a brief overview of what wa-cr can do.
For a complete overview see wa-cr's docs and the complete overview.

Wad Data

Reading in a .wad is easy by using WAD.read(filepath or io)

# Reads in a wad and sets it to *my_wad*
my_wad = WAD.read("Path/To/Wad.WAD")

You can read in specific .lmp files too .lmp : an exported doom Lump.

# Reads in a sound lump file and sets it to *my_sound*
my_sound = WAD::Sound.parse("Path/To/Sound.lmp")

You can also add the data into the wad file with WAD#add(name, type, file)

my_wad.add("MySound", "Sound", "Path/To/Sound.lmp")

And you can create entirely new wad files too with WAD.new(type)

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

# You can read data into that new WAD as well
my_new_wad.add("MySound", "Sound", "Path/To/Sound.lmp")

Sound Converting

Converting doom-formatted sound data to a .wav file is just as simple by using Sound#to_wav(filepath or io)

# Writes *my_sound* to a .wav file
my_sound.to_wav("Path/To/WriteSound.wav")

Writing Additions

You can write out .wad and .lmp files from the parsed data as well by using WAD#write(filepath or io) and ThingToWrite#write(filepath or io)

# Include the wa-cr write library
require "wa-cr/write"

# Write *my_wad* to *"MyWad.wad"*
my_wad.write("Path/To/MyWad.wad")


# Writes the *my_graphic* lump to a .lmp file
my_graphic.write("Path/To/MyLump.lmp")

Raylib Additions

wa-cr takes advantage of Raylib and raylib-cr with ways to convert .pngs or Raylib Images to doom graphics and doom graphics to Raylib Images or Raylib Colors and draw said images or colors to the screen

# Include the wa-cr raylib library
require "wa-cr/raylib"

palette = my_wad.playpal.palettes[0]

my_graphic_image = my_graphic.to_tex(palette)
my_flat_image = my_flat.to_tex(palette)
# You can also get textures from the texture maps
my_texture_image = my_wad.get_texture("texture_name_in_texturex", palette)

# Gets the pixel data in the graphic and the flat
my_graphic_pixel = my_graphic.get_pixel(20, 5, palette)
my_flat_pixel = my_flat.get_pixel(2, 10, palette)

# Gets a png as a doom graphic
my_graphic_png = WAD::Graphic.from_png("Path/To/MyGraphic.png", palette)
my_flat_png = WAD::Graphic.from_png("Path/To/MyFlat.png", palette)

# Png exports
my_wad.export_texture("MyTexture", "Path/To/MyTexture.png", palette)
my_graphic.to_png("Path/To/MyGraphic.png", palette)
my_flat.to_png("Path/To/MyFlat.png", palette)

Apps

wa-cr provides useful apps that will help you with using WAD data.
To access wa-cr's apps, just require wa-cr/apps Here is a full list of all modules inside Apps:

Limitations

Contributing

  1. Fork it (https://github.com/D-Shwagginz/wa-cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors