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 = []
archetype_name = values[0]
if archetype_name.is_a?( Pixelart::Image )
archetype = archetype_name
attributes << archetype
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' )
attribute_gender = 'f'
attribute_size = 's'
else
attribute_gender = 'm'
attribute_size = 'l'
end
else 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|
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 )
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] 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
|