Class: Quake::Wad::Reader
- Inherits:
-
Object
- Object
- Quake::Wad::Reader
- Defined in:
- lib/quake/wad/reader.rb
Overview
Reads WAD2 archives (Quake’s texture/picture format). Used primarily for gfx.wad which contains HUD graphics.
Defined Under Namespace
Constant Summary collapse
- MAGIC =
"WAD2"
Instance Method Summary collapse
-
#initialize(data) ⇒ Reader
constructor
A new instance of Reader.
- #list ⇒ Object
- #read(name) ⇒ Object
-
#read_qpic(name) ⇒ Object
Read a QPic (status bar graphic): 4-byte width, 4-byte height, pixels.
Constructor Details
#initialize(data) ⇒ Reader
Returns a new instance of Reader.
15 16 17 18 19 |
# File 'lib/quake/wad/reader.rb', line 15 def initialize(data) @data = data @entries = {} parse_directory end |
Instance Method Details
#list ⇒ Object
21 22 23 |
# File 'lib/quake/wad/reader.rb', line 21 def list @entries.keys end |
#read(name) ⇒ Object
25 26 27 28 29 |
# File 'lib/quake/wad/reader.rb', line 25 def read(name) entry = @entries[name.downcase] return nil unless entry @data[entry.offset, entry.size] end |
#read_qpic(name) ⇒ Object
Read a QPic (status bar graphic): 4-byte width, 4-byte height, pixels
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/quake/wad/reader.rb', line 32 def read_qpic(name) entry = @entries[name.downcase] return nil unless entry raw = @data[entry.offset, entry.size] return nil unless raw && raw.bytesize >= 8 width, height = raw[0, 8].unpack("VV") pixels = raw[8, width * height] QPic.new(width: width, height: height, pixels: pixels) end |