Class: Punk40::Image

Inherits:
Pixelart::Image
  • Object
show all
Defined in:
lib/punks/bodies_40.rb

Constant Summary collapse

NAMES =
['punk40', 'punks40']
DEFAULT_ATTRIBUTES =
['Male Mid 2']

Class Method Summary collapse

Class Method Details

.generate(*values, patch: nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/punks/bodies_40.rb', line 22

def self.generate( *values, patch: nil )

  attributes = []   ## collect all attribute images (32x32, 24x24, etc.) to merge/paste here


  archetype_name  = values[0]

  if archetype_name.is_a?( Pixelart::Image )
     archetype = archetype_name
     attributes << archetype
     ### for now assume (support only)
      ##    large & male (l/m) for "inline/patch" archetypes - why? why not?
      ##    change male to unisex - why? why not?  (note: for now unisex is not doing a backup lookup using male/female)
      attribute_gender = 'm'
      attribute_size   = 'l'
  elsif patch && img=patch[ Sheet.normalize_key(archetype_name) ]
     archetype = img
     attributes << archetype
     if archetype_name.downcase.index( 'female' )
     ## note: attribute lookup requires gender from archetype!!!!
      ## quick & dirty hack for now
      ##    if name incl. female (automagically) switch to f(emale)/s(mall)
       attribute_gender = 'f'
       attribute_size   = 's'
     else
      attribute_gender = 'm'
      attribute_size   = 'l'
     end
  else ## assume it's a string
    ### todo/fix:  check for nil/not found!!!!
    ## todo/check/fix:  assert meta record returned is archetype NOT attribute!!!!
    archetype  = Punk32::Sheet.find_meta_by( name: archetype_name )
    if archetype.nil?
      puts "!! ERROR -  archetype >#{archetype}< not found; sorry"
      exit 1
    end
    attributes << Punk32::Sheet.image[ archetype.id ]
    attribute_gender = archetype.gender
    attribute_size   = archetype.size
  end


  attribute_names  = values[1..-1]
  attribute_names.each do |attribute_name|
     ## note: quick hack - allow "inline" raw images for now - why? why not?
     ##         pass through as-is
    if attribute_name.is_a?( Pixelart::Image )
      attributes << attribute_name
    elsif patch && img=patch[ Sheet.normalize_key(attribute_name) ]
      attributes << img
    else
      attribute = Punk32::Sheet.find_by( name: attribute_name,
                                 gender: attribute_gender,
                                 size:   attribute_size,
                                 warn: false )
      ## try 24x24 punk attribute next
      attribute = Punk::Sheet.find_by( name: attribute_name,
                                       gender: attribute_gender,
                                       size:   attribute_size ) if attribute.nil?

      if attribute.nil?
        puts "!! ERROR - attribute >#{attribute_name}< for (#{attribute_gender}+#{attribute_size}) not found; sorry"
        exit 1
      end

      attributes << attribute
     end
  end

  punk = new( 40, 40 )

  attributes.each do |attribute|
    offset = if attribute.width == 24 && attribute.height == 24
                [6,7] ## offset x/y for classic 24x24 attributes in 40x40 canvas
             elsif attribute.width == 32 && attribute.height == 32
                [0,8]
             elsif attribute.width == 40 && attribute.height == 40
                [0,0]
             else
                puts "!! ERROR - unsupported attribute size; got #{attribute.width}x#{attribute.height} - expected 40x40, 32x32 or 24x24; sorry"
                exit 1
             end
    punk.compose!( attribute, *offset )
  end
  punk
end