Top Level Namespace

Defined Under Namespace

Modules: Profilepic Classes: ImageReq, ProfilepicService

Constant Summary collapse

ProfilePic =

convenience aliases / shortcuts / alternate spellings

Profilepic
ProfilePicService =
ProfilepicService
IMAGES =

keep cache of generated images (profile pics)

{}
FILES =

serve-up built-in spritesheet(s) and metadata

{
  # doge
  'doge-24x24.png' => "#{Shibainus.root}/config/spritesheet.png",
  'doge-24x24.csv' => "#{Shibainus.root}/config/spritesheet.csv",
  # marcs
  'marcs-24x24.png' => "#{Pixelart::Module::Punks.root}/config/marcs-24x24.png",
  'marcs-24x24.csv' => "#{Pixelart::Module::Punks.root}/config/marcs-24x24.csv",
  # saudis
  'saudis-24x24.png' => "#{Pixelart::Module::Punks.root}/config/saudis-24x24.png",
  'saudis-24x24.csv' => "#{Pixelart::Module::Punks.root}/config/saudis-24x24.csv",
  # yeoldepunks
  'yeoldepunks-24x24.png' => "#{Pixelart::Module::Punks.root}/config/yeoldepunks-24x24.png",
  'yeoldepunks-24x24.csv' => "#{Pixelart::Module::Punks.root}/config/yeoldepunks-24x24.csv",
}
SPRITESHEETS =
{
  doge:        ['doge-24x24.png', 'doge-24x24.csv'],
  marcs:       ['marcs-24x24.png', 'marcs-24x24.csv'],
  saudis:      ['saudis-24x24.png', 'saudis-24x24.csv'],
  yeoldepunks: ['yeoldepunks-24x24.png', 'yeoldepunks-24x24.csv'],
}
DOGE =
{
  t: {
    legend: 'Select a doge shiba inu base (archetype)',
    options: [
      'Classic',
      'Dark',
      'Zombie',
      'Alien',
    ]
  },

  hair: {
    legend: 'Select hair',
    none: true,
    options: [
      'Crazy Hair',
     ],
  },

  headwear: {
    legend: 'Select headwear',
    none: true,
    options: [
      'Beanie',
      'Cap',
      'Cap Forward',
      'Cowboy Hat',
      'Fedora',
      'Knitted Cap',
      'Top Hat',
      'Bandana',
      'Headband',
      'Tiara',
    ]
  },

  eyewear: {
    legend: 'Select eyewear',
    none: true,
    options: [
      '3D Glasses',
      'Big Shades',
      'Classic Shades',
      'Regular Shades',
      'Small Shades',
      'Nerd Glasses',
      'Eye Patch',
    ]
  }
}
MARC =
{

 t: {
   legend: 'Select a marc base (archetype)',
   options: [
    'Marc',
    'Marc Mid',
    'Marc Dark',
    'Marc Albino',
    'Marc Golden',
    'Mad Lad',
    'Zombie',
    'Ape',
    'Ape Golden',
    'Ape Pink',
    'Alien',
    'Alien Green',
    'Devil',
    'Orc',
    'Skeleton',
    'Bot'],
 },

 eyes: {
  legend: 'Select eyes (extras)',
  none: true,
  options: [
    'Blue Eyes',
    'Green Eyes',
  ],
 },

 face: {
  legend: 'Select face (extras)',
  none: true,
  options: [
    'Blue Eye Shadow',
    'Green Eye Shadow',
    'Purple Eye Shadow',
    'Clown Eyes Blue',
    'Clown Eyes Green',
    'Bagner',
    'Marc Tyson',
    'Tears',
  ],
 },

 beard: {
  legend: 'Select beard',
  none: true,
  options: [
    'Big Beard White',
    'Big Beard',
    'Chinstrap',
    'Front Beard',
    'Front Beard Dark',
    'Full Mustache',
    'Full Mustache Dark',
    'Goat',
    'Goat Dark',
    'Handlebar',
    'Luxurious Beard',
    'Mustache',
    'Mutton Chop',
    'Normal Beard',
    'Normal Beard Black',
    'Shadow Beard',
    'Soul Patch',
  ],
 },

 hair: {
  legend: 'Select hair',
  none: true,
  options: [
    'Blonde Bob',
    'Chad',
    'Clown Hair',
    'Crazy White Hair',
    'Crazy Hair',
    'Frumpy Hair',
    'Marc Three',
    'Purple Hair',
    'Stringy Hair',
    'Vampire Hair',
    'Wild Blonde Hair',
    'Wild Hair',
  ],
 },

 headwear: {
  legend: 'Select headwear',
  none: true,
  options: [
    'Bandana',
    'Beanie',
    'Bunny Ears',
    'Cap',
    'Skull Cap',
    'Cap Forward',
    'Police Cap',
    'Cowboy Hat',
    'Do Rag',
    'Fast Food',
    'Marcdonalds',
    'Fedora',
    'Headband',
    'Roaring Headband',
    'Hoodie',
    'Purple Hoodie',
    'Knitted Cap',
    'Laurels',
    'Shemagh',
    'Tassle Hat',
    'Tiarra',
    'Top Hat',
    'Uncle Sam',
    'Viking',
    'Welding Goggles',
  ],
 },

 eyewear: {
  legend: 'Select eyewear',
  none: true,
  options: [
    '3D Glasses',
    'Aviators',
    'Big Shades',
    'Classic Shades',
    'Deal With It',
    'Glasses',
    'Gold Glasses',
    'Horned-Rim Glasses',
    'Monocle',
    'Nerd Glasses',
    'Pink Shades',
    'Polarized',
    'Polarized White',
    'Regular Shades',
    'Small Shades',
    'VR Headset',
    'Eye Mask',
    'Eye Patch',
    'Lasers'],
 },

 mouth: {
  legend: 'Select mouth prop',
  none: true,
  options: [
    'Cigar',
    'Cigarette',
    'Hookah',
    'Pipe',
    'Vape',
    'Medical Mask',
    'Bubble Gum' ],
 },
}
SAUDI =
{

 t: {
   legend: 'Select a saudi/sheik base (archetype)',
   options: [
     'Light 1',
      'Light 2',
      'Medium 1',
      'Medium 2',
      'Dark 1',
      'Dark 2',
    ],
 },

 headwear: {
  legend: 'Select headwear',
  none: true,
  options: [
    'White Shemagh',
    'White Shemagh Agal',
    'White Shemagh Gold Agal',
    'White Shemagh Stylish Gold Agal',
    'White Shemagh Crown',
    'Brown Shemagh Agal',
    'Brown Shemagh Crown',
    'Red Shemagh',
    'Red Shemagh Agal',
    'Red Shemagh Crown',
   ],
 },


 beard: {
  legend: 'Select beard',
  none: true,
  options: [
    'messy white beard',
    'short white beard',
    'normal white beard',
    'luxurious white beard',
    'short grey beard',
    'messy brown beard',
    'normal brown beard',
    'luxurious brown beard',
    'shadow beard',
    'shadow beard mustache',
    'light beard',
    'mustache',
    'stylish mustache',
    'sideburns',
    'sideburns mustache',
    'normal beard',
    'normal brown beard mustache',
    'luxurious beard',
      ],
 },


 eyewear: {
  legend: 'Select eyewear',
  none: true,
  options: [
    'horn rimmed glasses',
    'rimless glasses',
    'nerd glasses',
    'stylish nerd glasses',
    'classic shades',
    'classic green shades',
    'classic gold shades',
    'regular pixel shades',
    'regular reflective shades',
    'big green shades',
    'big pixel shades',
    'big purple shades',
    'big shades',
    'small shades',
    'regular shades',
    'round shades',
    'big round shades',
    'square reflective shades',
    'square shades',
    '3d glasses',
    'vr',
    'laser eyes',
    'max bidding',

],
 },

 mouth: {
  legend: 'Select mouth prop',
  none: true,
  options: [
    'cigarette',
    'shadowless cigarette',
    'miswak',
    'vape',
    'shadowless vape',
    'cigar',
    'pearwood pipe',
    'rosewood pipe',
    'bubble gum',
     ],
 },
}
YEOLDEPUNK =
{
  t: {
    legend: "Select a ye olde' punk  base (archetype)",
    options: [
      'Male 1',
      'Male 2',
      'Male 3',
      'Male 4',
      'Female 1',
      'Female 2',
      'Female 3',
      'Female 4',
      'Zombie',
      'Ape',
      'Alien',
      'Bot',
      'Zombie Female',
      'Ape Female',
      'Alien Female',
      'Bot Female',
    ],
  },


  cheeks: {
    legend: 'Select cheeks',
    none: true,
    options: [
      'Rosy Cheeks (m/f)',
    ]
  },

  blemish: {
    legend: 'Select blemish',
    none: true,
    options: [
      'Mole (m/f)',
      'Spots (m/f)',
    ]
  },

  hair: {
    legend: 'Select hair',
    none: true,    ## check - use/rename to required/optional - why? why not?
    options: [
      'Shaved Head (m/f)',
      'Peak Spike (m/f)',
      'Vampire Hair (m/f)',
      'Purple Hair (m/f)',

      'Mohawk (m/f)',
      'Mohawk Dark (m/f)',
      'Mohawk Thin (m/f)',
      'Wild Hair (m/f)',
      'Crazy Hair (m/f)',
      'Messy Hair (m/f)',
      'Frumpy Hair (m/f)',
      'Stringy Hair (m/f)',
      'Clown Hair Green (m/f)',

      'Straight Hair (m/f)',
      'Straight Hair Dark (m/f)',
      'Straight Hair Blonde (m/f)',
      'Blonde Short (m/f)',
      'Blonde Bob (m/f)',
      'Wild Blonde (m/f)',
      'Wild White Hair (m/f)',
      'Orange Side (m/f)',
      'Dark Hair (m/f)',
      'Pigtails (m/f)',
      'Pink With Hat¹ (m/f)',
      'Half Shaved (m/f)',
      'Red Mohawk (m/f)',
    ],
    notes: "¹: Note: Pink With Hat is a hair+headwear combo.",
  },

  beard: {
    legend: 'Select beard',
    none: true,
    options: [
      'Shadow Beard (m)',
      'Normal Beard (m)',
      'Normal Beard Black (m)',
      'Big Beard (m)',
      'Luxurious Beard (m)',
      'Mustache (m)',
      'Goat (m)',
      'Handlebars (m)',
      'Front Beard (m)',
      'Front Beard Dark (m)',
      'Chinstrap (m)',
      'Muttonchops (m)',
    ],
  },

  eyes: {
    legend: 'Select eyes (make-up)',
    none: true,
    options: [
      'Clown Eyes Green (m/f)',
      'Clown Eyes Blue (m/f)',
      'Green Eye Shadow (f)',
      'Blue Eye Shadow (f)',
      'Purple Eye Shadow (f)',
    ]
  },

  eyewear: {
    legend: 'Select eyewear',
    none: true,
    options: [
      'Small Shades (m/f)',
      'Regular Shades (m/f)',
      'Classic Shades (m/f)',
      'Big Shades (m/f)',
      'Nerd Glasses (m/f)',
      'Horned Rim Glasses (m/f)',
      '3D Glasses (m/f)',
      'VR (m/f)',
      'Eye Mask (m/f)',
      'Eye Patch (m/f)',
      'Welding Goggles (m/f)',
    ]
  },

  nose: {
    legend: 'Select nose accessory',
    none: true,
    options: [
      'Clown Nose (m/f)',
    ]
  },

  mouth: {
    legend: 'Select mouth expression / lipstick make-up',
    none: true,
    options: [
      'Smile (m)',
      'Frown (m)',
      'Buck Teeth (m)',
      'Hot Lipstick (f)',
      'Black Lipstick (f)',
      'Purple Lipstick (f)',
     ]
  },

  mouthprop: {
    legend: 'Select mouth prop',
    none:  true,
    options: [
      'Cigarette (m/f)',
      'Vape (m/f)',
      'Pipe (m/f)',
      'Medical Mask (m/f)',
     ]
  },

  earring: {
    legend: 'Select earring',
    none: true,
    options: [
      'Earring (m/f)'
    ]
  },

  headwear: {
    legend: 'Select headwear',
    none: true,
    options: [
      'Cowboy Hat (m/f)',
      'Fedora (m/f)',
      'Hoodie (m/f)',
      'Beanie (m/f)',
      'Top Hat (m/f)',
      'Do-rag (m/f)',
      'Police Cap (m/f)',
      'Cap Forward (m/f)',
      'Cap (m/f)',
      'Knitted Cap (m/f)',
      'Bandana (m/f)',
      'Headband¹ (m/f)',
      'Pilot Helmet (m/f)',
      'Tassle Hat (m/f)',
      'Tiara (m/f)',
    ],
    notes: '¹: Note: Headband (f) is a (black) hair+headwear combo.',
  },

  neck: {
    legend: 'Select neck accessory',
    none: true,
    options: [
      'Silver Chain (m/f)',
      'Gold Chain (m/f)',
      'Choker (m/f)',
    ]
  },
}

Instance Method Summary collapse

Instance Method Details

#label_tag(content, id:) ⇒ Object



85
86
87
# File 'lib/profilepic/helper.rb', line 85

def label_tag( content, id: )
  %Q[    <label for="#{id}">#{content}</label>\n]
end

#originalsObject

3rd party libs



2
# File 'lib/profilepic.rb', line 2

require 'originals'

#radio_button_tag(name, value, checked: false, id:) ⇒ Object



78
79
80
81
82
83
# File 'lib/profilepic/helper.rb', line 78

def radio_button_tag( name, value, checked: false, id: )
  buf = %Q[  <input type="radio" id="#{id}" name="#{name}" value="#{value}" ]
  buf += " checked "   if checked
  buf += ">\n"
  buf
end

#radio_options(options, name:, legend:, sprites: false) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/profilepic/helper.rb', line 103

def radio_options( options, name:,
                            legend:,
                            sprites: false )

buf = <<TXT
<fieldset>
<legend>#{legend}:</legend>
TXT

options.each_with_index do |option,i|

  value = option.downcase

  ## auto-extract qualifiers e.g. (m)ale/(f)emale
  qualifiers = if    value.index( '(m)' )   then ['m']
               elsif value.index( '(f)' )   then ['f']
               elsif value.index( '(m/f)' ) then ['m', 'f']
               else  []
               end

  value = value.sub( '(m)', '' ).sub( '(f)', '' ).sub( '(m/f)', '' ).sub( '¹', '' )
  value = value.strip


  label = option
  id    = "#{name}#{i}"    ## use for input (dom) id / label for [id]


  ## note. add class columns - via css turns div into 250px inline-blocks
buf += "<div class='columns'>\n"
buf +=  radio_button_tag( name, value,
                          id: id,
                          checked: i==0  )

buf2 = String.new( '' )
if sprites
  if ['none'].include?( value )
    ## do nothing  - no sprite(s) - for none & friends
  elsif qualifiers.empty?
    buf2 +=  sprite_tag( value )
  else
    qualifiers.each do |qualifier|
      buf2 +=  sprite_tag( "#{value} (#{qualifier})" )
    end
  end
  ## note: add sprites (spans) inside label e.g. <label> HERE </label>
  buf += label_tag( buf2 + label, id: id )
else
  buf += label_tag( label, id: id )
end

buf += "</div>\n"
end


buf += "</fieldset>\n"
buf

end

#radio_options_w_sprites(options, name:, legend:) ⇒ Object



96
97
98
99
100
# File 'lib/profilepic/helper.rb', line 96

def radio_options_w_sprites( options, name:, legend: )
   radio_options( options, name: name,
                           legend: legend,
                           sprites: true )
end

#render_options(spec) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/profilepic/helper.rb', line 53

def render_options( spec )

  buf = String.new('')

  spec.each do |name, h|

    options = h[:options]
    options = ['None'] + options   if h[:none]

    legend = h[:legend]

    buf += radio_options_w_sprites( options,
                                      name:    name,
                                      legend:  legend )


    buf += "\n#{h[:notes]}\n\n"    if h[:notes]
  end

  buf
end

#render_spritesheet(type, image_path, meta_path, zoom: 2) ⇒ Object



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
# File 'lib/profilepic/service.rb', line 27

def render_spritesheet( type, image_path, meta_path, zoom: 2 )
buf = String.new('')
buf += <<TXT

  <h1> #{type} Spritesheet </h1>
TXT

## note: map "virtual" to real path
path = FILES[ meta_path ]
recs = read_csv( path )

recs.each do |rec|
  id         =  rec['id']
  name       =  rec['name']
  more_names = (rec['more_names'] || '').split( '|' )

  names = [name]
  names += more_names

  key = name
  if rec.has_key?( 'gender' )
    archetype  = (rec['type'] || rec['category'] || '').downcase.strip == 'archetype'
    if archetype
      ## do nothing for base archetype (e.g. male 1, alien, etc.)
    else
       ## auto-add qualifer e.g. (m) or (f) via gender
       gender = (rec['gender'] || 'm').downcase.strip
       key = "#{name} (#{gender})"
       names = names.map { |name| "#{name} (#{gender})"}
    end
end


  buf << "#{id}   "
  buf << "<span class='sprite' data-name='#{key}'></span>"
  buf << "  "
  buf << names.join( ' | ' )
  buf << "<br>\n"
end


buf += <<TXT
<script>
var sheet = Spritesheet.read( '#{image_path}',
`#{spritesheet( meta_path )}` );
sheet.draw();
</script>
TXT

buf

end

#sprite_tag(name) ⇒ Object



89
90
91
# File 'lib/profilepic/helper.rb', line 89

def sprite_tag( name )
  %Q[    <span class="sprite" data-name="#{name}"></span>\n]
end

#spritesheet(basename) ⇒ Object

spritesheet metadata / record helpers



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
# File 'lib/profilepic/helper.rb', line 5

def spritesheet( basename )  ## spritesheet metadata / record helpers
  ## note: map "virtual name" to local real path
  path = FILES[ basename ]
  recs = read_csv( path )

###
# id, category, name, more_names
# 0, , classic,
# 1, , dark,
# 2, , zombie,

##
# id, name, gender, size, type, more_names
# 0, Male 1, m, l, Archetype,
# 1, Male 2, m, l, Archetype,
# 2, Male 3, m, l, Archetype,


  buf = String.new('')
  recs.each do |rec|
    id         =  rec['id']
    name       =  rec['name']
    more_names = (rec['more_names'] || '').split( '|' )

    names = [name]
    names += more_names

    if rec.has_key?( 'gender' )
        archetype  = (rec['type'] || rec['category'] || '').downcase.strip == 'archetype'
        if archetype
          ## do nothing for base archetype (e.g. male 1, alien, etc.)
        else
           ## auto-add qualifer e.g. (m) or (f) via gender
           gender = (rec['gender'] || 'm').downcase.strip
           names = names.map { |name| "#{name} (#{gender})"}
        end
    end


    buf << "#{id}, #{names.join(' | ')}\n"
  end

  buf
end