Class: EhbGameLib::Palettes::Palette

Inherits:
Object
  • Object
show all
Defined in:
lib/ehb_game_lib/palettes/palette.rb

Direct Known Subclasses

Nes::Palette

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(colors) ⇒ Palette

Returns a new instance of Palette.



19
20
21
22
23
24
25
26
# File 'lib/ehb_game_lib/palettes/palette.rb', line 19

def initialize(colors)
  colors.each_with_index do |color, index|
    unless color.is_a?(::EhbGameLib::Palettes::Color)
      raise "\##{index} is not a Palette::Color (#{color})"
    end
  end
  @colors = colors.to_a.freeze
end

Instance Attribute Details

#colorsArray<Gosu::Color> (readonly)

Returns:

  • (Array<Gosu::Color>)


17
18
19
# File 'lib/ehb_game_lib/palettes/palette.rb', line 17

def colors
  @colors
end

Class Method Details

.from_file(file_path) ⇒ EhbGameLib::Palettes::Palette



11
12
13
# File 'lib/ehb_game_lib/palettes/palette.rb', line 11

def from_file(file_path)
  new(::EhbGameLib::Palettes::Color.array_from_file(file_path))
end

Instance Method Details

#[](index) ⇒ EhbGameLib::Palettes::Color



34
35
36
# File 'lib/ehb_game_lib/palettes/palette.rb', line 34

def [](index)
  colors.fetch(index)
end

#color(index) ⇒ EhbGameLib::Palettes::Color



29
30
31
# File 'lib/ehb_game_lib/palettes/palette.rb', line 29

def color(index)
  colors.fetch(index)
end

#sub(*indexes) ⇒ EhbGameLib::Palettes::Palette



39
40
41
# File 'lib/ehb_game_lib/palettes/palette.rb', line 39

def sub(*indexes)
  sub_class.new(indexes.map { |index| color(index) })
end

#sub_classObject



43
44
45
# File 'lib/ehb_game_lib/palettes/palette.rb', line 43

def sub_class
  ::EhbGameLib::Palettes::Palette
end