~ubuntu-branches/ubuntu/natty/balder2d/natty

« back to all changes in this revision

Viewing changes to bin/maps/balder2d_export.py

  • Committer: Bazaar Package Importer
  • Author(s): Bjørn Hansen
  • Date: 2008-06-15 17:15:38 UTC
  • mfrom: (1.1.1 upstream) (3.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080615171538-e407e07wbtdy0qs8
Tags: 1.0-1
* new upstream release
* update for guichan 8.1 (Closes: #482584)
* use physicsfs to make data/config/map/aiscript loading more flexible
* new skins for menus
* fix typo in control file long description (Closes: #458401)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
 
 
 
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.
11
11
 
12
12
from gimpfu import *
13
13
 
14
 
def python_balder2d_export(timg, tdrawable):
 
14
def python_balder2d_export(timg, tdrawable, maptags=False):
15
15
    width = timg.width
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)
37
37
 
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')
43
 
    for spawn in spawns:
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')
50
 
    out_file.close()
51
 
    gimp.progress_update(max_progress)
 
39
    if maptags:
 
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')
 
44
        for spawn in spawns:
 
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')
 
51
        out_file.close()
 
52
        gimp.progress_update(max_progress)
52
53
            
53
54
register(
54
55
        "python_fu_balder2d",
55
 
        "Export into a Balder2D map",
56
 
        "Export into a Balder2D map",
57
 
        "Bjørn Hansen",
58
 
        "Bjørn Hansen",
 
56
        "Export into a Balder2D map", 
 
57
        "Export into a Balder2D map",
 
58
        "Bjorn Hansen",
 
59
        "Bjorn Hansen",
59
60
        "October 2006",
60
61
        "<Image>/Python-Fu/Export/_Balder2D",
61
62
        "RGB*, GRAY*",
62
 
        [],
 
63
        [
 
64
            (PF_TOGGLE, "maptags", "Write maptags.xml", False)
 
65
        ],
63
66
        [],
64
67
        python_balder2d_export)
65
68