Beispiel #1
0
    def loadTiles(self, pathname):
        """Loads tiles from NT tile animation file.

        When tiles are loaded, they are put onto the tile bar for usage with
        the map editor. If the file isn't a tile animation file then nothing
        will happen. Any tiles previously loaded in are removed.

        Arguments: pathname -- name of path to tile animation file.

        """
        self.clear()

        self._tilesPath = pathname

        tree = ElementTree()
        tree.parse(pathname)
        root = tree.getroot()

        sheets = root.findall('sheet')

        posX = 0
        posY = 0
        column = 0
        MAX_COLUMNS = 4

        for sheet in sheets:
            sheetPath = sheet.get('path')
            sheetImg = QtGui.QImage(subInPath(pathname, sheetPath))

            strips = sheet.findall('strip')

            for strip in strips:
                tile = Tile()
                tile.setAnimPath(self._tilesPath)
                tileId = int(strip.get('id'))
                tile.setId(tileId)
                self._tileIds[tileId] = tile

                bar.clipFromSheet(sheetImg, strip, tile)

                tile.setSize(tile.pixmap().width())
                lnX, lnY = bar.setForBar(posX, posY, self._defOpacity, tile)

                self.addItem(tile)
                self.addLine(lnX)
                self.addLine(lnY)

                posX, posY, column = bar.updateGridPos(posX, posY, column,
                    MAX_COLUMNS, tile.pixmap().width(), tile.pixmap().height())
Beispiel #2
0
    def loadObject(self, filepath):
        """Loads object located at filepath.

        If an object doesn't have an animation file, a default "script" image
        is loaded in.

        Arguments: filepath -- path to object's xml file
        """
        objTree = ElementTree()
        objTree.parse(filepath)
        objRoot = objTree.getroot()

        animElem = objRoot.find('animation')
        relAnimPath = animElem.get('path')

        # Empty path means no animation file for object. So represent it
        # via a visual representation for mod objects. 
        objIsAnimated = (relAnimPath != '')

        absAnimPath = ''
        if objIsAnimated:
            absAnimPath = subInPath(filepath, relAnimPath)
        else:
            absAnimPath = "state_editor/media/mod_rep.xml"

        animTree = ElementTree()
        animTree.parse(absAnimPath)
        animRoot = animTree.getroot()

        sheets = animRoot.findall('sheet')

        objFile = basename(filepath)
        objName = splitext(objFile)[0]

        MAX_COLUMNS = 4
        animNum = 0

        for sheet in sheets:
            sheetPath = sheet.get('path')

            sheetImg = None
            if objIsAnimated:
                sheetImg = QtGui.QImage(subInPath(filepath, sheetPath))
            else:
                sheetImg = QtGui.QImage(sheetPath)

            strips = sheet.findall('strip')

            for strip in strips:
                obj = Object()
                self._objDict[filepath].append(obj)
                obj.path = filepath
                obj.animNum = animNum

                tipSuffix = ''
                if objIsAnimated:
                    tipSuffix = 'Strip ' + str(animNum)
                else:
                    tipSuffix = 'No Anim'
                obj.setToolTip(objName + ': ' + tipSuffix)

                bar.clipFromSheet(sheetImg, strip, obj)

                lnX, lnY = bar.setForBar(self._posX, self._posY,
                    self._defOpacity, obj)
                self.addItem(obj)
                self.addLine(lnX)
                self.addLine(lnY)

                if obj.pixmap().height() > self._greatestHeight:
                    self._greatestHeight = obj.pixmap().height()

                self._posX, self._posY, self._column = bar.updateGridPos(
                    self._posX, self._posY, self._column, MAX_COLUMNS,
                    obj.pixmap().width(), self._greatestHeight)

                # On a new row
                if self._column == 0:
                    self._greatestHeight = 0

                animNum += 1