Class: Spritely::ImageSet

Inherits:
Object
  • Object
show all
Defined in:
lib/spritely/image_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options) ⇒ ImageSet

Returns a new instance of ImageSet.



8
9
10
11
12
13
14
# File 'lib/spritely/image_set.rb', line 8

def initialize(path, options)
  @path = path
  @options = options
  @data = File.read(path)
  @width, @height = data[0x10..0x18].unpack('NN')
  @left = 0
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/spritely/image_set.rb', line 6

def data
  @data
end

#heightObject (readonly)

Returns the value of attribute height.



6
7
8
# File 'lib/spritely/image_set.rb', line 6

def height
  @height
end

#leftObject (readonly)

Returns the value of attribute left.



6
7
8
# File 'lib/spritely/image_set.rb', line 6

def left
  @left
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/spritely/image_set.rb', line 6

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/spritely/image_set.rb', line 6

def path
  @path
end

#topObject

Returns the value of attribute top.



5
6
7
# File 'lib/spritely/image_set.rb', line 5

def top
  @top
end

#widthObject (readonly)

Returns the value of attribute width.



6
7
8
# File 'lib/spritely/image_set.rb', line 6

def width
  @width
end

Instance Method Details

#imagesObject



20
21
22
# File 'lib/spritely/image_set.rb', line 20

def images
  @images ||= []
end

#nameObject



16
17
18
# File 'lib/spritely/image_set.rb', line 16

def name
  File.basename(path, ".png")
end

#outer_heightObject



24
25
26
# File 'lib/spritely/image_set.rb', line 24

def outer_height
  height + spacing
end

#position_in!(collection_width) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/spritely/image_set.rb', line 40

def position_in!(collection_width)
  if repeated?
    left_position = 0
    while left_position < collection_width
      add_image!(left_position)
      left_position += width
    end
  elsif right?
    add_image!(@left = collection_width - width)
  else
    add_image!(0)
  end
end

#repeated?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/spritely/image_set.rb', line 32

def repeated?
  !!options[:repeat]
end

#right?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/spritely/image_set.rb', line 36

def right?
  options[:position] == 'right'
end

#spacingObject



28
29
30
# File 'lib/spritely/image_set.rb', line 28

def spacing
  options[:spacing] || 0
end