-
Notifications
You must be signed in to change notification settings - Fork 0
/
Intravenous-UI-Icons-Tool.lua
319 lines (257 loc) · 7.62 KB
/
Intravenous-UI-Icons-Tool.lua
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
-------------------------------------------------------------------------------
-- N A M E : Intravenous UI Icons Tool
-- A U T H O R : Alexandr 'JFAexe' Konichenko
-- V E R S I O N : 2022.06.04.4
-- L I C E N S E : MIT
-------------------------------------------------------------------------------
local app = app
local alert = app.alert
local command = app.command
local pixelColor = app.pixelColor
if not app.isUIAvailable then
return
end
if not app.apiVersion or app.apiVersion < 10 then
alert 'This script is unsupported. Update the Aseprite.'
return
end
-------------------------------------------------------------------------------
-- S C H E M E S
-------------------------------------------------------------------------------
local __schemes = {
idle = {
name = '_idle',
base = { r = 70, g = 84, b = 86 },
high = { r = 100, g = 135, b = 140 },
fx = false
},
active = {
name = '_active',
base = { r = 204, g = 175, b = 85 },
high = { r = 219, g = 229, b = 148 },
fx = true
},
inactive = {
name = '_inactive',
base = { r = 183, g = 38, b = 38 },
high = { r = 231, g = 116, b = 40 },
fx = true
},
custom = {
name = '_custom',
base = { r = 0 , g = 0, b = 0 },
high = { r = 255, g = 255, b = 255 },
fx = true
},
}
local __colors = {
base = __schemes.idle.base,
high = __schemes.idle.high
}
-------------------------------------------------------------------------------
-- F U N C T I O N S
-------------------------------------------------------------------------------
local rgba = pixelColor.rgba
local rgbaR = pixelColor.rgbaR
local rgbaG = pixelColor.rgbaG
local rgbaB = pixelColor.rgbaB
local rgbaA = pixelColor.rgbaA
local function checkTransparency( value )
return rgbaA( value ) < 255
end
local function checkColor( value, color )
return rgbaR( value ) == color.r and rgbaG( value ) == color.g and rgbaB( value ) == color.b
end
local function convertFromColor( color )
return { r = color.red, g = color.green, b = color.blue }
end
local function createLayer( sprite )
local layer = nil
if layer == nil then
layer = sprite:newLayer( )
layer.name = app.activeLayer.name
end
return layer
end
local function createSprite( sprite, name )
local newSprite = Sprite( sprite )
newSprite.filename = tostring( sprite.filename ):gsub( '.png', name .. '.png' )
return newSprite
end
local function applyColors( image, scheme )
local check = false
for pixel in image:pixels( ) do
local pixelValue = pixel( )
if not checkTransparency( pixelValue ) then
if checkColor( pixelValue, __colors.high ) then
pixel( rgba( scheme.high.r, scheme.high.g, scheme.high.b ) )
check = true
elseif checkColor( pixelValue, __colors.base ) then
pixel( rgba( scheme.base.r, scheme.base.g, scheme.base.b ) )
check = true
else
pixel( rgbaA( 0 ) )
end
else
pixel( rgbaA( 0 ) )
end
end
return image, check
end
local function createBase( cel )
local altered, check = applyColors( cel.image:clone( ), __colors )
if not check then
alert 'Wrong colors.'
return nil
end
command.AutocropSprite( )
command.CanvasSize {
ui = false,
left = 1,
right = 1,
top = 1,
bottom = 1,
}
return altered
end
local function createAltered( sprite, cel, base, scheme )
if not scheme then
return
end
local newSprite = createSprite( sprite, scheme.name )
local altered = applyColors( base:clone( ), scheme )
newSprite:newCel( app.activeLayer, app.activeFrame, altered, cel.position )
if not scheme.fx then
return
end
command.ConvolutionMatrix {
ui = false,
fromResource = 'blur-3x3'
}
newSprite:newCel( createLayer( newSprite ), app.activeFrame, altered, cel.position )
command.MergeDownLayer( )
command.AutocropSprite( )
end
local function generateIcons( schemes )
local cel = app.activeCel
if not cel then
alert 'There is no active cel.'
return
end
if cel.image.colorMode ~= ColorMode.RGB then
alert 'This script supports only RGB color mode.'
return
end
local sprite = app.activeSprite
local base = createBase( cel )
if base == nil then
alert 'Failed to process sprite.'
return
end
app.transaction( function( )
for scheme = 1, #schemes do
createAltered( sprite, cel, base, schemes[ scheme ] )
end
app.refresh( )
end )
end
-------------------------------------------------------------------------------
-- W I N D O W
-------------------------------------------------------------------------------
local Window = Dialog( 'IVUIIT' )
Window
:newrow {
always = true
}
:separator {
text = 'Colors'
}
:color {
id = 'baseColor',
color = Color( __colors.base )
}
:color {
id = 'highColor',
color = Color( __colors.high )
}
:separator {
text = 'Schemes'
}
:check {
id = 'schemeIdle',
text = 'Idle',
selected = true
}
:check {
id = 'schemeActive',
text = 'Active',
selected = true
}
:check {
id = 'schemeInactive',
text = 'Inactive',
selected = true
}
:check {
id = 'schemeCustom',
text = 'Custom',
selected = false,
onclick = function( )
local visible = Window.data.schemeCustom
Window
:modify {
id = 'customBaseColor',
visible = visible
}
:modify {
id = 'customHighColor',
visible = visible
}
:modify {
id = 'customFx',
visible = visible
}
end
}
:color {
id = 'customBaseColor',
color = Color( __schemes.custom.base ),
visible = false
}
:color {
id = 'customHighColor',
color = Color( __schemes.custom.high ),
visible = false
}
:check {
id = 'customFx',
text = 'Glow',
selected = __schemes.custom.fx,
visible = false
}
:button {
id = 'normalMap',
text = 'Generate icons',
focus = true,
onclick = function( )
local data = Window.data
if not ( data.schemeIdle or data.schemeActive or data.schemeInactive or data.schemeCustom ) then
alert 'Select at least one option.'
return
end
__colors.base = convertFromColor( data.baseColor )
__colors.high = convertFromColor( data.highColor )
__schemes.custom.base = convertFromColor( data.customBaseColor )
__schemes.custom.high = convertFromColor( data.customHighColor )
__schemes.custom.fx = data.customFx
generateIcons( {
data.schemeIdle and __schemes.idle,
data.schemeActive and __schemes.active,
data.schemeInactive and __schemes.inactive,
data.schemeCustom and __schemes.custom,
} )
end
}
:show {
wait = false
}