Class: Doom::Wad::Patch
- Inherits:
-
Object
- Object
- Doom::Wad::Patch
- Defined in:
- lib/doom/wad/patch.rb
Defined Under Namespace
Classes: Post
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#left_offset ⇒ Object
readonly
Returns the value of attribute left_offset.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#top_offset ⇒ Object
readonly
Returns the value of attribute top_offset.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, width, height, left_offset, top_offset, columns) ⇒ Patch
constructor
A new instance of Patch.
Constructor Details
#initialize(name, width, height, left_offset, top_offset, columns) ⇒ Patch
Returns a new instance of Patch.
10 11 12 13 14 15 16 17 |
# File 'lib/doom/wad/patch.rb', line 10 def initialize(name, width, height, left_offset, top_offset, columns) @name = name @width = width @height = height @left_offset = left_offset @top_offset = top_offset @columns = columns end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
8 9 10 |
# File 'lib/doom/wad/patch.rb', line 8 def columns @columns end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
8 9 10 |
# File 'lib/doom/wad/patch.rb', line 8 def height @height end |
#left_offset ⇒ Object (readonly)
Returns the value of attribute left_offset.
8 9 10 |
# File 'lib/doom/wad/patch.rb', line 8 def left_offset @left_offset end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/doom/wad/patch.rb', line 8 def name @name end |
#top_offset ⇒ Object (readonly)
Returns the value of attribute top_offset.
8 9 10 |
# File 'lib/doom/wad/patch.rb', line 8 def top_offset @top_offset end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
8 9 10 |
# File 'lib/doom/wad/patch.rb', line 8 def width @width end |
Class Method Details
.load(wad, name) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/doom/wad/patch.rb', line 19 def self.load(wad, name) data = wad.read_lump(name) return nil unless data parse(name, data) end |
.parse(name, data) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/doom/wad/patch.rb', line 26 def self.parse(name, data) width = data[0, 2].unpack1('v') height = data[2, 2].unpack1('v') left_offset = data[4, 2].unpack1('s<') top_offset = data[6, 2].unpack1('s<') column_offsets = width.times.map do |i| data[8 + i * 4, 4].unpack1('V') end columns = column_offsets.map do |offset| read_column(data, offset) end new(name, width, height, left_offset, top_offset, columns) end |
.read_column(data, offset) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/doom/wad/patch.rb', line 43 def self.read_column(data, offset) posts = [] pos = offset loop do top_delta = data[pos].ord break if top_delta == 0xFF length = data[pos + 1].ord pixels = data[pos + 3, length].bytes posts << Post.new(top_delta, pixels) pos += length + 4 end posts end |