class MineSkin::SkinData

Skin Data class

Attributes

body[RW]
head[RW]
left_arm[RW]
left_leg[RW]
right_arm[RW]
right_leg[RW]
unit[R]

Public Class Methods

new(filename) click to toggle source

rubocop:disable AbcSize Initializes new instance of SkinData @param [String] filename Path to input file

# File lib/mineskin/skin_data.rb, line 28
def initialize(filename)
  @image = Magick::Image.read(filename).first
  @new_format = @image.columns == @image.rows
  @unit = image_unit size: @image.columns
  @head = extract_head
  @body = extract_body
  @left_leg, @right_leg = extract_legs
  @left_arm, @right_arm = extract_arms
end

Public Instance Methods

new_format?() click to toggle source
# File lib/mineskin/skin_data.rb, line 21
def new_format?
  @new_format
end

Protected Instance Methods

extract_arms() click to toggle source

rubocop:disable RedundantReturn

# File lib/mineskin/skin_data.rb, line 83
def extract_arms
  return extract_left_arm, extract_right_arm
end
extract_body() click to toggle source
# File lib/mineskin/skin_data.rb, line 114
def extract_body
  extract(
    top:    { texture: [5, 4, 2, 1], overlay: new_only(5, 8, 2, 1) },
    bottom: { texture: [7, 4, 2, 1], overlay: new_only(7, 8, 2, 1) },
    right:  { texture: [4, 5, 1, 3], overlay: new_only(4, 9, 1, 3) },
    left:   { texture: [7, 5, 1, 3], overlay: new_only(7, 9, 1, 3) },
    front:  { texture: [5, 5, 2, 3], overlay: new_only(5, 9, 2, 3) },
    back:   { texture: [8, 5, 2, 3], overlay: new_only(8, 9, 2, 3) }
  )
end
extract_head() click to toggle source
# File lib/mineskin/skin_data.rb, line 48
def extract_head
  extract(
    top:    { texture: [2, 0, 2, 2], overlay: [10, 0, 2, 2] },
    bottom: { texture: [4, 0, 2, 2], overlay: [12, 0, 2, 2] },
    right:  { texture: [0, 2, 2, 2], overlay: [8,  2, 2, 2] },
    left:   { texture: [4, 2, 2, 2], overlay: [12, 2, 2, 2] },
    front:  { texture: [2, 2, 2, 2], overlay: [10, 2, 2, 2] },
    back:   { texture: [6, 2, 2, 2], overlay: [14, 2, 2, 2] }
  )
end
extract_left_arm() click to toggle source
# File lib/mineskin/skin_data.rb, line 59
def extract_left_arm
  return extract(
    top:    { texture: [9,  12, 1, 1], overlay: [13, 12, 1, 1] },
    bottom: { texture: [10, 12, 1, 1], overlay: [14, 12, 1, 1] },
    right:  { texture: [8,  13, 1, 3], overlay: [12, 13, 1, 3] },
    left:   { texture: [10, 13, 1, 3], overlay: [14, 13, 1, 3] },
    front:  { texture: [9,  13, 1, 3], overlay: [13, 13, 1, 3] },
    back:   { texture: [11, 13, 1, 3], overlay: [15, 13, 1, 3] }
  ) if new_format?
  extract_right_arm
end
extract_left_leg() click to toggle source
# File lib/mineskin/skin_data.rb, line 98
def extract_left_leg
  return extract(
    top:    { texture: [5, 12, 1, 1], overlay: [1, 12, 1, 1] },
    bottom: { texture: [6, 12, 1, 1], overlay: [2, 12, 1, 1] },
    right:  { texture: [4, 13, 1, 3], overlay: [0, 13, 1, 3] },
    left:   { texture: [6, 13, 1, 3], overlay: [2, 13, 1, 3] },
    front:  { texture: [5, 13, 1, 3], overlay: [1, 13, 1, 3] },
    back:   { texture: [7, 13, 1, 3], overlay: [3, 13, 1, 3] }
  ) if new_format?
  extract_right_leg
end
extract_legs() click to toggle source
# File lib/mineskin/skin_data.rb, line 110
def extract_legs
  return extract_right_leg, extract_left_leg
end
extract_right_arm() click to toggle source
# File lib/mineskin/skin_data.rb, line 71
def extract_right_arm
  extract(
    top:    { texture: [11, 4, 1, 1], overlay: new_only(11, 8, 1, 1) },
    bottom: { texture: [12, 4, 1, 1], overlay: new_only(12, 8, 1, 1) },
    right:  { texture: [10, 5, 1, 3], overlay: new_only(10, 9, 1, 3) },
    left:   { texture: [12, 5, 1, 3], overlay: new_only(12, 9, 1, 3) },
    front:  { texture: [11, 5, 1, 3], overlay: new_only(11, 9, 1, 3) },
    back:   { texture: [13, 5, 1, 3], overlay: new_only(13, 9, 1, 3) }
  )
end
extract_right_leg() click to toggle source
# File lib/mineskin/skin_data.rb, line 87
def extract_right_leg
  extract(
    top:    { texture: [1, 4, 1, 1], overlay: new_only(1, 8, 1, 1) },
    bottom: { texture: [2, 4, 1, 1], overlay: new_only(2, 8, 1, 1) },
    right:  { texture: [0, 5, 1, 3], overlay: new_only(0, 9, 1, 3) },
    left:   { texture: [2, 5, 1, 3], overlay: new_only(2, 9, 1, 3) },
    front:  { texture: [1, 5, 1, 3], overlay: new_only(1, 9, 1, 3) },
    back:   { texture: [3, 5, 1, 3], overlay: new_only(3, 9, 1, 3) }
  )
end
new_only(*x) click to toggle source
# File lib/mineskin/skin_data.rb, line 40
def new_only(*x)
  if new_format?
    return x.first if x.first.is_a? Array
    return x
  end
  nil
end