Class: Doom::Wad::Palette

Inherits:
Object
  • Object
show all
Defined in:
lib/doom/wad/palette.rb

Constant Summary collapse

COLORS =
256
PALETTES =
14
PALETTE_SIZE =
COLORS * 3

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(colors) ⇒ Palette

Returns a new instance of Palette.



12
13
14
# File 'lib/doom/wad/palette.rb', line 12

def initialize(colors)
  @colors = colors
end

Instance Attribute Details

#colorsObject (readonly)

Returns the value of attribute colors.



10
11
12
# File 'lib/doom/wad/palette.rb', line 10

def colors
  @colors
end

Class Method Details

.load(wad, palette_index = 0) ⇒ Object

Raises:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/doom/wad/palette.rb', line 20

def self.load(wad, palette_index = 0)
  data = wad.read_lump('PLAYPAL')
  raise Error, 'PLAYPAL lump not found' unless data

  offset = palette_index * PALETTE_SIZE
  colors = COLORS.times.map do |i|
    [
      data[offset + i * 3].ord,
      data[offset + i * 3 + 1].ord,
      data[offset + i * 3 + 2].ord
    ]
  end

  new(colors)
end

Instance Method Details

#[](index) ⇒ Object



16
17
18
# File 'lib/doom/wad/palette.rb', line 16

def [](index)
  @colors[index]
end