Beispiel #1
0
    def loadMap(self, file, playable_pos=LPoint2i(0, 0)):
        xmldoc = minidom.parse(file)

        data = xmldoc.getElementsByTagName('data')
        for d in data:
            if d.attributes > 0:
                if d.attributes.has_key('tilesize'):
                    self.tileDimension = float(d.attributes['tilesize'].value)
                else:
                    self.tileDimension = 32.0
                if d.attributes.has_key('showcollisions'):
                    if d.attributes['showcollisions'].value == 'false':
                        self.showCollisions = False
                    else:
                        self.showCollisions = True
                else:
                    self.showCollisions = False
                if d.attributes.has_key('camdistance'):
                    customCamera.setDistance(
                        float(d.attributes['camdistance'].value))
                else:
                    customCamera.setDistance(15)
                if d.attributes.has_key('onLoad'):
                    self.loadScript = d.attributes['onLoad'].value
                else:
                    self.loadScript = False

                if d.attributes.has_key('onUnload'):
                    self.unloadScript = d.attributes['onUnload'].value
                else:
                    self.unloadScript = False

        rowsdata = xmldoc.getElementsByTagName('row')

        currentx = 0
        currenty = 0

        for row in rowsdata:  #for every row
            for tile in row.childNodes:  #for every tile
                if tile.nodeType == Node.ELEMENT_NODE:  #if child is tile
                    t = Tile(self.tileDimension)
                    t.setX(currentx)
                    t.setY(currenty)

                    #apending lolol
                    self.tileset.append(t)

                    o = Once(
                    )  #lo switch viene fatto solo in presenza di una texture 'ground'

                    for res in tile.childNodes:
                        if res.nodeType == Node.ELEMENT_NODE:  # adding resources to tile
                            if res.nodeName == 'ground':
                                t.addTexture(res.attributes)
                                if o.get():
                                    currentx += 1
                            elif res.nodeName == 'object':
                                t.addObject(res.attributes)
                            elif res.nodeName == 'grass':
                                g = Grass(res.attributes,
                                          self.tileDimension)  #creating object
                                t.addCustomObject(
                                    g)  #setting coordinates of tile
                                g.getNode().wrtReparentTo(self.grassnode)
                            elif res.nodeName == 'light':
                                t.addLight(res.attributes)
                            elif res.nodeName == 'scrollable':
                                c = Scrollable(
                                    res.attributes['url'].value,
                                    res.attributes['inclination'].value,
                                    self.tileDimension)
                                c.setX(currentx)
                                c.setY(currenty)
                                self.scrollableset.append(c)
                            elif res.nodeName == 'character':
                                t.addCharacter(res.attributes,
                                               self.showCollisions,
                                               playable_pos)

                    t.node.reparentTo(self.node)
            currentx = 0
            currenty += 1

        self.grassnode.flattenStrong(
        )  #pumping performance for dynamic grass (like, 120x)