class WAD::Graphic

Overview

A WAD graphic

WARNING The max graphic height is 255. The max width is unlimited

NOTE Graphic has no is_graphic? method. Instead, Graphic#parse will return nil if io is not a valid graphic

Included Modules

Extended Modules

Defined in:

raylib.cr
wa-cr/wad/wad-data/texture.cr
write.cr

Class Method Summary

Instance Method Summary

Instance methods inherited from module WritingAdditions::Graphic

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

Instance methods inherited from module RaylibAdditions::Graphic

get_pixel(x : Int, y : Int, palette : ::WAD::Playpal::Palette) : Raylib::Color get_pixel, to_image(palette : ::WAD::Playpal::Palette) : Raylib::Image to_image, to_png(filename : String | Path, palette : ::WAD::Playpal::Palette) to_png

Class Method Detail

def self.is_sprite_mark_end?(name : String) #

Checks to see if name is "S_END".

Returns true if the name is a sprite marker end:

sprite_mark_name = "S_END"
if WAD::Graphic.is_sprite_mark_end?(sprite_mark_name)
  puts "Is a Sprite Marker End"
else
  puts "Is not a Sprite Marker End"
end

def self.is_sprite_mark_start?(name : String) #

Checks to see if name is "S_START".

Returns true if the name is a sprite marker start:

sprite_mark_name = "S_START"
if WAD::Graphic.is_sprite_mark_start?(sprite_mark_name)
  puts "Is a Sprite Marker Start"
else
  puts "Is not a Sprite Marker Start"
end

def self.parse(filename : String | Path) : Graphic | Nil #

Parses a graphic file given the filename

Opens a graphic file and parses it:

my_graphic = WAD::Graphic.parse("Path/To/Graphic")

def self.parse(file : File, file_pos : Int = 0, size : Int = -1) : Graphic | Nil #

Parses a graphic file given the file

Opens a graphic file and parses it:

File.open("Path/To/Graphic") do |file|
  my_graphic = WAD::Graphic.parse(file)
end

Instance Method Detail

def [](x : Int, y : Int) #

def clone #

Returns a copy of self with all instance variables cloned.


def data : Array(UInt8 | Nil) #

def file_size : UInt32 #

def file_size=(file_size : UInt32) #

def height : UInt16 #

def height=(height : UInt16) #

def leftoffset : Int16 #

def leftoffset=(leftoffset : Int16) #

def reset_data #

def set_pixel(x : Int, y : Int, value : Int) #

Sets a pixel in the graphic to be value. Raises an error if value is not within the bounds of a UInt8

NOTE value does not refer to an rgb color, but instead to an index in the colors of a WAD::Playpal::Palette

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

my_graphic = my_wad.graphics["MyGraphic"]

my_graphic[2, 3] # => Returns the value of the pixel at x=2 y=3

my_graphic.set_pixel(2, 3, 120) # => Sets the value of the pixel at x=2 y=3 to be 120

my_graphic[2, 3] # => 120

my_graphic.set_pixel(2, 3, -1) # => Raises an exception

my_graphic.set_pixel(2, 3, 256) # => Raises an exception

def topoffset : Int16 #

def topoffset=(topoffset : Int16) #

def width : UInt16 #

def width=(width : UInt16) #