Esempio n. 1
0
 def __str__(self):
     _params = attr(self.__parameters)
     _attr = attr({
         'session-id': self.__session_id,
         'validation': self.__validation
     })
     return '<ifmap:search ' + _attr + _params + '>' + self.__identifier + '</ifmap:search>'
Esempio n. 2
0
def parse_tileset(tileset, basepath, projroot, outdir):
    source = util.attr(tileset, "source", None)
    firstgid = int(util.attr(tileset, "firstgid"))

    if source:
        source = os.path.join(basepath, source)
        return (firstgid, tsx2dat.tsx2resources(source, projroot, outdir))
    else:
        return (firstgid, tsx2dat.tileset2resources(tileset, basepath, projroot, outdir))
Esempio n. 3
0
def tmxdata(data):
    encoding = util.attr(data, "encoding", None)
    compression = util.attr(data, "compression", None)

    textdata = text(data)
    if encoding:
        textdata = textdata.decode(encoding)
    if compression:
        textdata = textdata.decode(compression)
    n = len(textdata) / 4
    return struct.unpack("<" + "I" * n, textdata)
Esempio n. 4
0
 def __str__(self):
     __attr = attr({
         'session-id': self.__session_id,
         'validation': self.__validation,
         'ifmap-publisher-id': self.__publisher_id
     })
     return '<ifmap:purgePublisher %s' % __attr + '/>'
Esempio n. 5
0
 def __str__(self):
     _attr = attr({
         'value': self.__ip_address,
         'type': self.__type,
         'administrative-domain': self.__administrative_domain
     })
     return '<ip-address %s' % _attr + '/>'
Esempio n. 6
0
    fname = sys.argv[1]
    projroot = sys.argv[2]
    outdir = sys.argv[3]

    basepath, mapname = os.path.split(fname)
    mapname, _ = os.path.splitext(mapname)

    with open(fname) as f:
        dom = xml.dom.minidom.parse(f)

    mapdom = element(dom, "map")
    tilesets = elements(mapdom, "tileset")
    for ii in range(len(tilesets)):
        tilesets[ii] = parse_tileset(tilesets[ii], basepath, projroot, outdir)

    width = int(util.attr(mapdom, "width"))
    height = int(util.attr(mapdom, "height"))
    tile_width = int(util.attr(mapdom, "tilewidth"))
    tile_height = int(util.attr(mapdom, "tileheight"))

    layers = elements(mapdom, "layer")
    tileid2entity = {}

    for ii in range(len(layers)):
        layer = layers[ii]
        data = element(layer, "data")

        flipped_tiles = tmxdata(data)

        # flip the map vertically to fit the shape that we want to be
        # loading
Esempio n. 7
0
	def __str__(self):
		_attr = attr({'value':self.__ip_address,'type':self.__type,'administrative-domain':self.__administrative_domain})
		return '<ip-address %s' % _attr + '/>'
Esempio n. 8
0
 def __str__(self):
     if self.__filter:
         _attr = attr({'filter':self.__filter})
         return '<delete %s>' % _attr + self.__id + '</delete>'
     else:
         return '<delete>' + self.__id + '</delete>'
Esempio n. 9
0
 def __str__(self):
     return '<ifmap:endSession %s' % (attr(
         {'session-id': self.__session_id})) + '/>'
Esempio n. 10
0
	def __str__(self):
		__attr = attr({'session-id':self.__session_id, 'validation':self.__validation,'ifmap-publisher-id':self.__publisher_id})
		return '<ifmap:purgePublisher %s' % __attr + '/>';
Esempio n. 11
0
def tileset2resources(tileset, basedir, projroot, outdir):
    tile_width = int(tileset.getAttribute('tilewidth'))
    tile_height = int(tileset.getAttribute('tileheight'))
    tile_spacing = int(util.attr(tileset, 'spacing', 0))
    margin = int(util.attr(tileset, 'margin', 0))

    image = tileset.getElementsByTagName('image')[0]

    image_rel_name = image.getAttribute('source')
    _, image_name = os.path.split(image_rel_name)
    shutil.copyfile(os.path.join(basedir, image_rel_name), os.path.join(outdir, image_name))

    image_name, _ = os.path.splitext(image_name)

    base_outname = os.path.join(outdir, image_name)
    dat_outname = '%s.dat' % base_outname
    order_outname = '%s.order' % base_outname

    img_width = int(image.getAttribute('width'))
    img_height = int(image.getAttribute('height'))

    width_in_tiles = int(round((img_width - 2*margin) / (tile_width)))
    height_in_tiles = int(round((img_height - 2*margin) / (tile_height)))

    # grab terrain properties. these will be the defaults for tile
    # properties
    terrain_properties = {}
    terraintypes = tileset.getElementsByTagName('terraintypes')
    if terraintypes:
        terrains = terraintypes[0].getElementsByTagName('terrain')
        for ii in range(len(terrains)):
            tprops = {}
            terrain_properties[ii] = tprops

            terrain = terrains[ii]
            properties = terrain.getElementsByTagName('properties')
            if properties:
                for prop in properties[0].getElementsByTagName('property'):
                    tprops[prop.getAttribute('name')] = prop.getAttribute('value')

    # grab any tile properties that exist
    tile_properties = {}
    for tile in tileset.getElementsByTagName('tile'):
        tid = int(tile.getAttribute('id'))
        props = {}
        tile_properties[tid] = props

        # first grab the inherited terrain properties
        terrain = tile.getAttribute('terrain') or ''
        for terrain_id in terrain.split(','):
            props.update(terrain_properties[int(terrain_id)])

        # now merge in the tile specific properties
        properties = tile.getElementsByTagName('properties')
        if not properties: continue

        for prop in properties[0].getElementsByTagName('property'):
            props[prop.getAttribute('name')] = prop.getAttribute('value')

    nentries = width_in_tiles * height_in_tiles
    with open(dat_outname, "wb") as outdat:
        util.write_short(outdat, nentries)

        for tnum in range(nentries):
            row = int(tnum / width_in_tiles)
            col = tnum % width_in_tiles

            # compute the margin impact
            xpad = margin + col * tile_spacing
            ypad = margin + row * tile_spacing

            xstart = xpad + col * tile_width
            ystart = ypad + row * tile_height
            xend = xstart + tile_width
            yend = ystart + tile_height

            u0 = float(xstart) / img_width
            v1 = float(ystart) / img_height
            u1 = float(xend) / img_width
            v0 = float(yend) / img_height

            parms = (tile_width, tile_height, u0, v0, u1, v1, "%d" % tnum)
            #print(row, col, (xstart, ystart, xend, yend), parms)
            outdat.write(util.pack_sprite(*parms))

    with open(order_outname, "w") as outnames:
        for ii in range(nentries):
            outnames.write("%d\n" % ii)

    # revise base_outname such that it's relative to what we hope to
    # the project root
    base_outname = os.path.relpath(base_outname, projroot)

    return (base_outname, nentries, tile_properties)
Esempio n. 12
0
 def __str__(self):
     _attr = attr({
         'value': self.__mac_address,
         'administrative-domain': self.__administrative_domain
     })
     return '<mac-address %s' % _attr + '/>'
Esempio n. 13
0
 def __str__(self):
     __attr = ' '+ attr(self.__attributes)
     return '<metadata><' + self.__name + self.__ns_uri + __attr + '>' + self.__value + self.__elements + '</' + self.__name + '></metadata>'
     
Esempio n. 14
0
	def __str__(self):
	    _attr = attr({'value':self.__mac_address,'administrative-domain':self.__administrative_domain})
	    return '<mac-address %s' % _attr + '/>'
Esempio n. 15
0
	def __str__(self):
		return '<ifmap:newSession %s' % (attr({'max-poll-result-size':self.__max_poll_result})) + '/>';
Esempio n. 16
0
 def __str__(self):
     _attr = attr({
         'session-id': self.__session_id,
         'validation': self.__validation
     })
     return '<ifmap:poll %s' % _attr + '/>'
Esempio n. 17
0
	def __str__(self):
		return '<ifmap:endSession %s' % (attr({'session-id':self.__session_id})) + '/>';
Esempio n. 18
0
 def __str__(self):
     #import pdb; pdb.set_trace()
     return '<ifmap:newSession %s' % (attr(
         {'max-poll-result-size': self.__max_poll_result})) + '/>'
Esempio n. 19
0
	def __str__(self):
		_params = attr(self.__parameters)
		_attr = attr({'session-id': self.__session_id, 'validation' : self.__validation})
		return '<ifmap:search ' + _attr + _params + '>' +  self.__identifier + '</ifmap:search>'
Esempio n. 20
0
 def __str__(self):
     _attr = attr({
         'session-id': self.__session_id,
         'validation': self.__validation
     })
     return '<ifmap:publish %s' % _attr + '>' + self.__operations + '</ifmap:publish>'
Esempio n. 21
0
	def __str__(self):
		_attr = attr({'session-id': self.__session_id, 'validation' : self.__validation})
		return '<ifmap:subscribe %s' % _attr + '>' + self.__operations + '</ifmap:subscribe>'
Esempio n. 22
0
 def __str__(self):
     if self.__lifetime:
         _attr = attr({'lifetime':self.__lifetime})
         return '<update %s>' % _attr + self.__id + self.__metadata + '</update>'
     else:
         return '<update>' + self.__id + self.__metadata + '</update>'
Esempio n. 23
0
	def __str__(self):
		_attr = attr({'session-id': self.__session_id, 'validation' : self.__validation})
		return '<ifmap:poll %s' % _attr + '/>'
Esempio n. 24
0
	def __str__(self):
		__attr = attr(self.__parameters)
		return '<update name="'+ self.__name + '" ' + __attr + '>' + self.__identifier +'</update>'
Esempio n. 25
0
 def __str__(self):
     __attr = ' ' + attr(self.__attributes)
     return '<metadata><' + self.__name + self.__ns_uri + __attr + '>' + self.__value + self.__elements + '</' + self.__name + '></metadata>'