-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprite_simple.py
84 lines (79 loc) · 2.41 KB
/
sprite_simple.py
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
#!/usr/bin/env python
from gimpfu import *
import math, re, sprite;
def sprite_simple(img, drawable, s = 1, t = 0, l = 0, dir = 'v', order = False):
if order:
sprite.order_layers(img, drawable, s)
x = 0 #valor actual de x
y = 0 # valor actual de y
w = 0 # el ancho de la image
h = 0 #alto de l layer
c = 0 # contador
lh = 0 #alto del layer mas grade
layers = [];
if dir == 'h':
v = 0;
for layer in img.layers:
if layer.visible == True:
v = v + 1;
layers.append(layer);
s = int(round(v / s))
else :
layers = img.layers;
for layer in layers:
#eliminamos la extencion del layer
layer.name = re.sub(r'(\..*$)', '', layer.name)
# Movemos el layer a la posicion x y
layer.set_offsets(x, y)
if s == 1:
if dir == 'v':
x = 0
y += layer.height + t
if h < y:
h = y
if w < layer.width:
w = layer.width
else:
x += layer.width + l
y = 0
if h < layer.height:
h = layer.height
if w < x:
w = x
else:
c += 1
x += layer.width + l
if w < x:
w = x
#se debe manter el layer mas grande que sera la posicion
# del siguiente grupo
if lh < layer.height:
lh = layer.height
#guardamos el maximo ancho de la imagen
#ajustamos para generar el nuevo grupo
if c == s:
y += lh + t
c = lh = x = 0
if h < y:
h = y
#resize image
img.resize(w - l, h - t, 0, 0)
register(
'sprite_simple',
'Crea un sprite desde un conjunto de capas importadas',
'Crea un sprite desde un conjunto de capas importadas',
'Loduis Madariaga',
'Loduis Madariaga',
'2010',
'<Image>/Filters/Web/Sprite/Simple',
'RGBA, RGB',
[
(PF_INT, 'split', 'Split:', 1),
(PF_INT, 'vertical', 'Vertical Offset:', 0),
(PF_INT, 'horizontal', 'Horizontal Offset:', 0),
(PF_RADIO, 'direction', 'Build Direction:', 'v', (('Vertical', 'v'), ('Horizontal', 'h'))),
(PF_TOGGLE, 'order', 'Order layers:', False)
],
[],
sprite_simple)
main()