Module: MineSkin::Extractor

Included in:
CapeData, SkinData
Defined in:
lib/mineskin/extractor.rb

Instance Method Summary collapse

Instance Method Details

#crop(texture) ⇒ Magick::Image

Extracts texture

Parameters:

  • texture (Hash)

    Texture coordinates (x,y,width,height)

Returns:

  • (Magick::Image)

    Image part



8
9
10
11
12
13
14
15
# File 'lib/mineskin/extractor.rb', line 8

def crop(texture)
  @image.crop(
    texture[:x] * @unit,
    texture[:y] * @unit,
    texture[:width] * @unit,
    texture[:height] * @unit
  )
end

#extract(hash) ⇒ MineSkin::Cuboid

Constructs a Cuboid from given regions

Parameters:

  • hash (Hash)

    Region data

Returns:



36
37
38
39
40
41
42
43
44
45
# File 'lib/mineskin/extractor.rb', line 36

def extract(hash)
  Cuboid.new(
    part(hash[:top]),
    part(hash[:bottom]),
    part(hash[:left]),
    part(hash[:right]),
    part(hash[:front]),
    part(hash[:back])
  )
end

#part(texture: { x: 0, y: 0, width: 0, height: 0 }, overlay: nil) ⇒ MineSkin::Texture

Constructs a Texture object from given regions

Parameters:

  • texture (Hash, Array) (defaults to: { x: 0, y: 0, width: 0, height: 0 })

    Texture coordinates in array or hash

  • overlay (Hash, Array, nil) (defaults to: nil)

    Optional overlay coords

Returns:



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mineskin/extractor.rb', line 21

def part(texture: { x: 0, y: 0, width: 0, height: 0 }, overlay: nil)
  tex = crop coords_to_h texture

  part = Texture.new(tex, nil)
  if overlay
    over = crop coords_to_h overlay
    part.overlay = over
  end

  part
end