1
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
3
# a script for exporting balder2d maps from the gimp
4
4
# to use this script put it in your .gimp-2.2/plug-ins/ directory (make sure
5
5
# it is excecutable) then open up
6
6
# the gimp and create/open an image in the directory where you want your map
7
7
# created. Create two layers named 'background' and 'geometry'. Edit them
8
8
# and then go to python-fu->Export->Balder2D and it will save them as separate
9
# png images. In the future there will be a spawn layer too, and the script
10
# will create the maptags.xml file.
9
# png images. You may also creat a third layer, named 'spawns'. Any red pixel
10
# (rgb value FF0000) will become a spawn location in the exported maptags.xml.
12
12
from gimpfu import *
14
def python_balder2d_export(timg, tdrawable):
14
def python_balder2d_export(timg, tdrawable, maptags=False):
16
16
height = timg.height
17
17
layers = timg.layers
26
26
pdb.gimp_file_save(timg, layer, path+'/background.png', 'background.png')
27
27
elif name.lower() == 'geometry':
28
28
pdb.gimp_file_save(timg, layer, path+'/geometry.png', 'geometry.png')
29
elif name.lower() == 'spawns' :
29
elif maptags and name.lower() == 'spawns' :
30
30
p = layer.get_pixel_rgn(0,0,width,height)
31
31
for x in range(0,width):
32
32
for y in range(0,height):
36
36
gimp.progress_update(float(progress) / max_progress)
38
38
# found all the spawns, now write them out to the file
39
out_file = open(path+"/maptags.xml", "w")
40
out_file.write('<?xml version="1.0"?>\n<!-- information about the map -->\n')
41
out_file.write('<Map name="'+timg.name.rsplit('.',1)[0]+'">\n')
42
out_file.write('\t<Size width="'+`width`+'" height="'+`height`+'" />\n')
44
out_file.write('\t<spawn>\n')
45
out_file.write('\t\t<location x="'+`spawn[0]`+'" y="'+`spawn[1]`+'" />\n')
46
out_file.write('\t\t<velocity x="0" y="0" />\n')
47
out_file.write('\t\t<stuck status="true" />\n')
48
out_file.write('\t</spawn>\n')
49
out_file.write('</Map>\n')
51
gimp.progress_update(max_progress)
40
out_file = open(path+"/maptags.xml", "w")
41
out_file.write('<?xml version="1.0"?>\n<!-- information about the map -->\n')
42
out_file.write('<Map name="'+timg.name.rsplit('.',1)[0]+'">\n')
43
out_file.write('\t<Size width="'+`width`+'" height="'+`height`+'" />\n')
45
out_file.write('\t<spawn>\n')
46
out_file.write('\t\t<location x="'+`spawn[0]`+'" y="'+`spawn[1]`+'" />\n')
47
out_file.write('\t\t<velocity x="0" y="0" />\n')
48
out_file.write('\t\t<stuck status="true" />\n')
49
out_file.write('\t</spawn>\n')
50
out_file.write('</Map>\n')
52
gimp.progress_update(max_progress)
54
55
"python_fu_balder2d",
55
"Export into a Balder2D map",
56
"Export into a Balder2D map",
56
"Export into a Balder2D map",
57
"Export into a Balder2D map",
60
61
"<Image>/Python-Fu/Export/_Balder2D",
64
(PF_TOGGLE, "maptags", "Write maptags.xml", False)
64
67
python_balder2d_export)