-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuilder.go
More file actions
275 lines (195 loc) · 9.2 KB
/
Copy pathbuilder.go
File metadata and controls
275 lines (195 loc) · 9.2 KB
1
2
3
4
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
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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
package avatar
import "github.com/go-universal/cache"
// FactoryBuilder defines the interface for building an avatar factory.
type FactoryBuilder interface {
// WithStorage sets a root path of storage to save avatars.
WithStorage(root string) FactoryBuilder
// WithPrefix sets a path prefix to exclude from the file URL.
WithPrefix(prefix string) FactoryBuilder
// WithQueue sets the queue for managing files that failed to delete.
// Files in the queue must be deleted manually later.
WithQueue(queue cache.Queue) FactoryBuilder
// WithNumberedFile enables numeric file naming.
WithNumberedFile() FactoryBuilder
// WithTimestampedFile enables timestamp-based file naming.
WithTimestampedFile() FactoryBuilder
// AddAccessory adds a custom accessory to the avatar factory.
// Shape can include fill="{decorator}" to match the avatar palette.
AddAccessory(isMale bool, name, shape string) FactoryBuilder
// DefaultAccessories add all predefined accessories to the avatar factory.
DefaultAccessories() FactoryBuilder
// NecklaceAccessory add necklace accessory for female to the avatar factory.
NecklaceAccessory() FactoryBuilder
// ChokerAccessory add choker accessory for female to the avatar factory.
ChokerAccessory() FactoryBuilder
// AddBeard adds a custom beard to the avatar factory.
// Shape can include fill="{hair}", fill="{hair_shadow}" and fill="{hair_highlight}" to match the avatar palette.
AddBeard(name, shape string) FactoryBuilder
// DefaultBeards add all predefined beards to the avatar factory.
DefaultBeards() FactoryBuilder
// MustachBeard add mustache beard to the avatar factory.
MustachBeard() FactoryBuilder
// FancyMustachBeard add fancy mustache beard to the avatar factory.
FancyMustachBeard() FactoryBuilder
// NormalBeard add normal beard to the avatar factory.
NormalBeard() FactoryBuilder
// MediumBeard add medium-length beard to the avatar factory.
MediumBeard() FactoryBuilder
// LongBeard add long beard to the avatar factory.
LongBeard() FactoryBuilder
// SetBodyShape sets the default body shape for the avatar factory.
// Shape can include fill="{skin}" and fill="{skin_shadow}" to match the avatar palette.
SetBodyShape(shape string) FactoryBuilder
// AddDress adds a custom dress to the avatar factory.
// Shape can include fill="{dress}", fill="{dress_shadow}" and fill="{decorator}" to match the avatar palette.
AddDress(isMale bool, name, shape string) FactoryBuilder
// DefaultDresses add all predefined dresses to the avatar factory.
DefaultDresses() FactoryBuilder
// SuitDress add suit dress to the avatar factory.
SuitDress() FactoryBuilder
// ShirtDress add shirt dress to the avatar factory.
ShirtDress() FactoryBuilder
// TShirtDress add t-shirt dress to the avatar factory.
TShirtDress() FactoryBuilder
// AddEye adds a custom eye to the avatar factory.
AddEye(isMale bool, name, shape string) FactoryBuilder
// AddEyebrow adds a custom eyebrow to the avatar factory.
AddEyebrow(isMale bool, name, shape string) FactoryBuilder
// AddGlasses adds a custom glasses to the avatar factory.
// Shape can include fill="{decorator}" to match the avatar palette.
AddGlasses(isMale bool, name, shape string) FactoryBuilder
// DefaultGlasses add all predefined glasses to the avatar factory.
DefaultGlasses() FactoryBuilder
// PrescriptionGlasses add prescription glasses to the avatar factory.
PrescriptionGlasses() FactoryBuilder
// RoundPrescriptionGlasses add round prescription glasses to the avatar factory.
RoundPrescriptionGlasses() FactoryBuilder
// SunglassGlasses add sunglass glasses to the avatar factory.
SunglassGlasses() FactoryBuilder
// RoundSunglassGlasses add round sunglass glasses to the avatar factory.
RoundSunglassGlasses() FactoryBuilder
// AddHair adds a custom hair to the avatar factory.
// Shape can include fill="{hair}", fill="{hair_shadow}" and fill="{hair_highlight}" to match the avatar palette.
AddHair(isMale bool, name, shape string) FactoryBuilder
// DefaultHairs add all predefined hairs to the avatar factory.
DefaultHairs() FactoryBuilder
// ShortHair add short hair to the avatar factory.
ShortHair() FactoryBuilder
// MediumHair add medium hair to the avatar factory.
MediumHair() FactoryBuilder
// WavyHair add wavy hair to the avatar factory.
WavyHair() FactoryBuilder
// CurlyHair add curly hair to the avatar factory.
CurlyHair() FactoryBuilder
// AddHaircolor adds a custom hair color to the avatar factory.
AddHaircolor(name string, color SVGHairColor) FactoryBuilder
// DefaultHairColors add all predefined hair colors to the avatar factory.
DefaultHairColors() FactoryBuilder
// BrownHairColor add brown hair color to the avatar factory.
BrownHairColor() FactoryBuilder
// LightHairColor add light hair color to the avatar factory.
LightHairColor() FactoryBuilder
// DarkHairColor add dark hair color to the avatar factory.
DarkHairColor() FactoryBuilder
// AddMouth adds a custom mouth to the avatar factory.
AddMouth(isMale bool, name, shape string) FactoryBuilder
// AddPalette adds a custom palette to the avatar factory.
AddPalette(name string, palette SVGPalette) FactoryBuilder
// DefaultPalettes add all predefined palettes to the avatar factory.
DefaultPalettes() FactoryBuilder
// PurplePalette add purple palette to the avatar factory.
PurplePalette() FactoryBuilder
// GreenPalette add green palette to the avatar factory.
GreenPalette() FactoryBuilder
// BluePalette add blue palette to the avatar factory.
BluePalette() FactoryBuilder
// YellowPalette add yellow palette to the avatar factory.
YellowPalette() FactoryBuilder
// OrangePalette add orange palette to avatarthe factory.
OrangePalette() FactoryBuilder
// RedPalette add red palette to the avatar factory.
RedPalette() FactoryBuilder
// TealPalette add teal palette to the avatar factory.
TealPalette() FactoryBuilder
// PinkPalette add pink palette to the avatar factory.
PinkPalette() FactoryBuilder
// AddShape adds a custom background shape to the avatar factory.
// Shape can include fill="{shape}" to match the avatar palette.
AddShape(name string, shape SVGShape) FactoryBuilder
// DefaultShapes add all predefined background shapes to the avatar factory.
DefaultShapes() FactoryBuilder
// FillShape add square background shape to the avatar factory.
FillShape() FactoryBuilder
// CircleShape add circle background shape to the avatar factory.
CircleShape() FactoryBuilder
// PolygonShape add polygon background shape to the avatar factory.
PolygonShape() FactoryBuilder
// AddSkinColor adds a custom skin color to the avatar factory.
AddSkinColor(name string, color SVGSkinColor) FactoryBuilder
// DefaultSkinColors add all predefined skin colors to the avatar factory.
DefaultSkinColors() FactoryBuilder
// WhiteSkin add white skin color to the avatar factory.
WhiteSkin() FactoryBuilder
// BrownSkin add brown skin color to the avatar factory.
BrownSkin() FactoryBuilder
// BlackSkin add black skin color to the avatar factory.
BlackSkin() FactoryBuilder
// AddSticker adds a custom sticker to the avatar factory.
// Shape can include fill="{text}" to match the avatar palette.
AddSticker(name, shape string) FactoryBuilder
// AddLetter adds a custom letter shape to the avatar factory.
// Shape can include fill="{text}" to match the avatar palette.
AddLetter(letter rune, shape string) FactoryBuilder
// AddTransformer adds a custom letter transformer to the avatar factory.
AddTransformer(letter, replacement rune) FactoryBuilder
// PersianLetters add all predefined persian letters to the avatar factory.
PersianLetters() FactoryBuilder
// PersianTransformers add all predefined persian transformers to the avatar factory.
PersianTransformers() FactoryBuilder
// englishLetters add all predefined english letters to the avatar factory.
englishLetters() FactoryBuilder
// Build creates a new AvatarFactory instance.
Build() AvatarFactory
}
// builder struct is used to build the avatar factory.
type builder struct {
factory *factory
}
// New creates a new FactoryBuilder instance.
func New() FactoryBuilder {
b := &builder{
factory: &factory{
numbered: false,
storage: "",
prefix: "",
queue: nil,
shapes: make(map[string]SVGShape),
palettes: make(map[string]SVGPalette),
stickers: make(map[string]string),
letters: make(map[string]string),
transforms: make(map[string]string),
skinColors: make(map[string]SVGSkinColor),
hairColors: make(map[string]SVGHairColor),
maleHairs: make(map[string]string),
maleBeards: make(map[string]string),
maleDresses: make(map[string]string),
maleEyes: make(map[string]string),
maleEyebrows: make(map[string]string),
maleMouths: make(map[string]string),
maleGlasses: make(map[string]string),
maleAccessories: make(map[string]string),
femaleHairs: make(map[string]string),
femaleDresses: make(map[string]string),
femaleEyes: make(map[string]string),
femaleEyebrows: make(map[string]string),
femaleMouths: make(map[string]string),
femaleGlasses: make(map[string]string),
femaleAccessories: make(map[string]string),
},
}
b.englishLetters()
return b
}
func (b *builder) Build() AvatarFactory {
return b.factory
}