当前位置: 首页>>代码示例>>Python>>正文


Python Map.addTileset方法代码示例

本文整理汇总了Python中map.Map.addTileset方法的典型用法代码示例。如果您正苦于以下问题:Python Map.addTileset方法的具体用法?Python Map.addTileset怎么用?Python Map.addTileset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在map.Map的用法示例。


在下文中一共展示了Map.addTileset方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: endCapture

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import addTileset [as 别名]
    def endCapture(self):
        if (self.mBrushBehavior != BrushBehavior.Capture):
            return
        self.mBrushBehavior = BrushBehavior.Free
        tileLayer = self.currentTileLayer()
        # Intersect with the layer and translate to layer coordinates
        captured = self.capturedArea()
        captured &= QRect(tileLayer.x(), tileLayer.y(),
                          tileLayer.width(), tileLayer.height())
        if (captured.isValid()):
            captured.translate(-tileLayer.x(), -tileLayer.y())
            map = tileLayer.map()
            capture = tileLayer.copy(captured)
            
            stamp = Map(map.orientation(),
                             capture.width(),
                             capture.height(),
                             map.tileWidth(),
                             map.tileHeight())
            # Add tileset references to map
            for tileset in capture.usedTilesets():
                stamp.addTileset(tileset)

            stamp.addLayer(capture)

            self.stampCaptured.emit(TileStamp(stamp))
        else:
            self.updatePreview()
开发者ID:theall,项目名称:Python-Tiled,代码行数:30,代码来源:stampbrush.py

示例2: read

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import addTileset [as 别名]
 def read(self, fileName):
     uncompressed = QByteArray()
     # Read data
     f = QFile(fileName)
     if (f.open(QIODevice.ReadOnly)) :
         compressed = f.readAll()
         f.close()
         uncompressed, length = decompress(compressed, 48 * 48)
     
     # Check the data
     if (uncompressed.count() != 48 * 48) :
         self.mError = self.tr("This is not a valid Droidcraft map file!")
         return None
     
     uncompressed = uncompressed.data()
     # Build 48 x 48 map
     # Create a Map -> Create a Tileset -> Add Tileset to map
     # -> Create a TileLayer -> Fill layer -> Add TileLayer to Map
     map = Map(Map.Orientation.Orthogonal, 48, 48, 32, 32)
     mapTileset = Tileset.create("tileset", 32, 32)
     mapTileset.loadFromImage(QImage(":/tileset.png"), "tileset.png")
     map.addTileset(mapTileset)
     # Fill layer
     mapLayer =  TileLayer("map", 0, 0, 48, 48)
     # Load
     for i in range(0, 48 * 48):
         tileFile = int(uncompressed[i])&0xff
         y = int(i / 48)
         x = i - (48 * y)
         tile = mapTileset.tileAt(tileFile)
         mapLayer.setCell(x, y, Cell(tile))
     
     map.addLayer(mapLayer)
     return map
开发者ID:theall,项目名称:Python-Tiled,代码行数:36,代码来源:droidcraftplugin.py

示例3: copySelection

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import addTileset [as 别名]
    def copySelection(self, mapDocument):
        currentLayer = mapDocument.currentLayer()
        if (not currentLayer):
            return
        map = mapDocument.map()
        selectedArea = mapDocument.selectedArea()
        selectedObjects = mapDocument.selectedObjects()
        tileLayer = currentLayer
        copyLayer = None
        if (not selectedArea.isEmpty() and type(tileLayer)==TileLayer):
            # Copy the selected part of the layer
            copyLayer = tileLayer.copy(selectedArea.translated(-tileLayer.x(), -tileLayer.y()))
        elif (not selectedObjects.isEmpty()):
            # Create a new object group with clones of the selected objects
            objectGroup = ObjectGroup()
            for mapObject in selectedObjects:
                objectGroup.addObject(mapObject.clone())
            copyLayer = objectGroup
        else:
            return

        # Create a temporary map to write to the clipboard
        copyMap = Map(map.orientation(),
                    copyLayer.width(), copyLayer.height(),
                    map.tileWidth(), map.tileHeight())
        copyMap.setRenderOrder(map.renderOrder())
        # Resolve the set of tilesets used by this layer
        for tileset in copyLayer.usedTilesets():
            copyMap.addTileset(tileset)
        copyMap.addLayer(copyLayer)
        self.setMap(copyMap)
开发者ID:theall,项目名称:Python-Tiled,代码行数:33,代码来源:clipboardmanager.py

示例4: toMap

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import addTileset [as 别名]
 def toMap(self, variant, mapDir):
     self.mGidMapper.clear()
     self.mMapDir = mapDir
     variantMap = variant
     orientationString = variantMap.get("orientation", '')
     orientation = orientationFromString(orientationString)
     if (orientation == Map.Orientation.Unknown):
         self.mError = self.tr("Unsupported map orientation: \"%s\""%orientationString)
         return None
     
     staggerAxisString = variantMap.get("staggeraxis", '')
     staggerAxis = staggerAxisFromString(staggerAxisString)
     staggerIndexString = variantMap.get("staggerindex", '')
     staggerIndex = staggerIndexFromString(staggerIndexString)
     renderOrderString = variantMap.get("renderorder", '')
     renderOrder = renderOrderFromString(renderOrderString)
     nextObjectId = variantMap.get("nextobjectid", 0)
     map = Map(orientation,
                        variantMap.get("width",0),
                        variantMap.get("height",0),
                        variantMap.get("tilewidth",0),
                        variantMap.get("tileheight",0))
     map.setHexSideLength(variantMap.get("hexsidelength", 0))
     map.setStaggerAxis(staggerAxis)
     map.setStaggerIndex(staggerIndex)
     map.setRenderOrder(renderOrder)
     if (nextObjectId):
         map.setNextObjectId(nextObjectId)
     self.mMap = map
     map.setProperties(self.toProperties(variantMap.get("properties", {})))
     bgColor = variantMap.get("backgroundcolor", '')
     if (bgColor!='' and QColor.isValidColor(bgColor)):
         map.setBackgroundColor(QColor(bgColor))
     for tilesetVariant in variantMap.get("tilesets", []):
         tileset = self.__toTileset(tilesetVariant)
         if not tileset:
             return None
         
         map.addTileset(tileset)
     
     for layerVariant in variantMap.get("layers", []):
         layer = self.toLayer(layerVariant)
         if not layer:
             return None
         
         map.addLayer(layer)
     
     return map
开发者ID:theall,项目名称:Python-Tiled,代码行数:50,代码来源:varianttomapconverter.py

示例5: stampFromContext

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import addTileset [as 别名]
def stampFromContext(selectedTool):
    stamp = TileStamp()
    stampBrush = dynamic_cast(selectedTool, StampBrush)
    if stampBrush:
        # take the stamp from the stamp brush
        stamp = stampBrush.stamp()
    else:
        fillTool = dynamic_cast(selectedTool, BucketFillTool)
        if fillTool:
            # take the stamp from the fill tool
            stamp = fillTool.stamp()
        else:
            mapDocument = DocumentManager.instance().currentDocument()
            if mapDocument:
                # try making a stamp from the current tile selection
                tileLayer = dynamic_cast(mapDocument.currentLayer(), TileLayer)
                if (not tileLayer):
                    return stamp
                selection = mapDocument.selectedArea()
                if (selection.isEmpty()):
                    return stamp
                selection.translate(-tileLayer.position())
                copy = tileLayer.copy(selection)
                if (copy.size().isEmpty()):
                    return stamp
                map = mapDocument.map()
                copyMap = Map(map.orientation(),
                                       copy.width(), copy.height(),
                                       map.tileWidth(), map.tileHeight())
                # Add tileset references to map
                for tileset in copy.usedTilesets():
                    copyMap.addTileset(tileset)
                copyMap.setRenderOrder(map.renderOrder())
                copyMap.addLayer(copy.take())
                stamp.addVariation(copyMap)
    
    return stamp
开发者ID:theall,项目名称:Python-Tiled,代码行数:39,代码来源:tilestampmanager.py

示例6: setTile

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import addTileset [as 别名]
    def setTile(self, tile):
        if type(tile)==list:
            tile = tile[0]
        if (self.mTile == tile):
            return
        self.mTile = tile
        self.mMapScene.disableSelectedTool()
        previousDocument = self.mMapScene.mapDocument()
        if (tile):
            self.mMapView.setEnabled(not self.mTile.tileset().isExternal())
            map = Map(Map.Orientation.Orthogonal, 1, 1, tile.width(), tile.height())
            map.addTileset(tile.sharedTileset())
            tileLayer = TileLayer(QString(), 0, 0, 1, 1)
            tileLayer.setCell(0, 0, Cell(tile))
            map.addLayer(tileLayer)
            objectGroup = None
            if (tile.objectGroup()):
                objectGroup = tile.objectGroup().clone()
            else:
                objectGroup = ObjectGroup()
            objectGroup.setDrawOrder(ObjectGroup.DrawOrder.IndexOrder)
            map.addLayer(objectGroup)
            mapDocument = MapDocument(map)
            self.mMapScene.setMapDocument(mapDocument)
            self.mToolManager.setMapDocument(mapDocument)
            mapDocument.setCurrentLayerIndex(1)
            self.mMapScene.enableSelectedTool()
            mapDocument.undoStack().indexChanged.connect(self.applyChanges)
        else:
            self.mMapView.setEnabled(False)
            self.mMapScene.setMapDocument(None)
            self.mToolManager.setMapDocument(None)

        if (previousDocument):
            previousDocument.undoStack().disconnect()
            del previousDocument
开发者ID:theall,项目名称:Python-Tiled,代码行数:38,代码来源:tilecollisioneditor.py

示例7: MapReaderPrivate

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import addTileset [as 别名]
class MapReaderPrivate():
    def tr(self, sourceText, disambiguation = '', n = -1):
        return QCoreApplication.translate('MapReader', sourceText, disambiguation, n)

    def trUtf8(self, sourceText, disambiguation = '', n = -1):
        return QCoreApplication.translate('MapReader', sourceText, disambiguation, n)

    def __init__(self, mapReader):
        self.p = mapReader
        self.mMap = None
        self.mError = QString('')
        self.mReadingExternalTileset = False
        self.xml = QXmlStreamReader()
        self.mGidMapper = GidMapper()

    def readMap(self, device, path):
        self.mError = QString('')
        self.mPath = path
        map = None
        self.xml.setDevice(device)
        if (self.xml.readNextStartElement() and self.xml.name() == "map"):
            map = self.__readMap()
        else:
            self.xml.raiseError(self.tr("Not a map file."))

        self.mGidMapper.clear()
        return map

    def readTileset(self, device, path):
        self.mError = ''
        self.mPath = path
        tileset = None
        self.mReadingExternalTileset = True
        self.xml.setDevice(device)
        if (self.xml.readNextStartElement() and self.xml.name() == "tileset"):
            tileset = self.__readTileset()
        else:
            self.xml.raiseError(self.tr("Not a tileset file."))
        self.mReadingExternalTileset = False
        return tileset

    def openFile(self, file):
        if (not file.exists()):
            self.mError = self.tr("File not found: %s"%file.fileName())
            return False
        elif (not file.open(QFile.ReadOnly | QFile.Text)):
            self.mError = self.tr("Unable to read file: %s"%file.fileName())
            return False

        return True

    def errorString(self):
        if self.mError != '':
            return self.mError
        else:
            return self.tr("%d\n\nLine %d, column %s"%(self.xml.lineNumber(), self.xml.columnNumber(), self.xml.errorString()))

    def __readUnknownElement(self):
        qDebug("Unknown element (fixme): "+self.xml.name()+" at line "+self.xml.lineNumber()+", column "+self.xml.columnNumber())
        self.xml.skipCurrentElement()

    def __readMap(self):
        atts = self.xml.attributes()
        mapWidth = Int(atts.value("width"))
        mapHeight = Int(atts.value("height"))
        tileWidth = Int(atts.value("tilewidth"))
        tileHeight = Int(atts.value("tileheight"))
        hexSideLength = Int(atts.value("hexsidelength"))
        orientationString = atts.value("orientation")
        orientation = orientationFromString(orientationString)
        if (orientation == Map.Orientation.Unknown):
            self.xml.raiseError(self.tr("Unsupported map orientation: \"%s\""%orientationString))

        staggerAxisString = atts.value("staggeraxis")
        staggerAxis = staggerAxisFromString(staggerAxisString)
        staggerIndexString = atts.value("staggerindex")
        staggerIndex = staggerIndexFromString(staggerIndexString)
        renderOrderString = atts.value("renderorder")
        renderOrder = renderOrderFromString(renderOrderString)
        nextObjectId = Int(atts.value("nextobjectid"))
        self.mMap = Map(orientation, mapWidth, mapHeight, tileWidth, tileHeight)
        self.mMap.setHexSideLength(hexSideLength)
        self.mMap.setStaggerAxis(staggerAxis)
        self.mMap.setStaggerIndex(staggerIndex)
        self.mMap.setRenderOrder(renderOrder)
        if (nextObjectId):
            self.mMap.setNextObjectId(nextObjectId)

        bgColorString = atts.value("backgroundcolor")
        if len(bgColorString)>0:
            self.mMap.setBackgroundColor(QColor(bgColorString))
        while (self.xml.readNextStartElement()):
            if (self.xml.name() == "properties"):
                self.mMap.mergeProperties(self.__readProperties())
            elif (self.xml.name() == "tileset"):
                self.mMap.addTileset(self.__readTileset())
            elif (self.xml.name() == "layer"):
                self.mMap.addLayer(self.__readLayer())
            elif (self.xml.name() == "objectgroup"):
                self.mMap.addLayer(self.__readObjectGroup())
#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:mapreader.py

示例8: read

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import addTileset [as 别名]
    def read(self, fileName):
        file = QFile(fileName)
        if (not file.open (QIODevice.ReadOnly)):
            self.mError = self.tr("Could not open file for reading.")
            return None
        
        # default to values of the original flare alpha game.
        map = Map(Map.Orientation.Isometric, 256, 256, 64, 32)
        stream = QTextStream(file)
        line = QString()
        sectionName = QString()
        newsection = False
        path = QFileInfo(file).absolutePath()
        base = 10
        gidMapper = GidMapper()
        gid = 1
        tilelayer = None
        objectgroup = None
        mapobject = None
        tilesetsSectionFound = False
        headerSectionFound = False
        tilelayerSectionFound = False # tile layer or objects
        while (not stream.atEnd()):
            line = stream.readLine()
            if line == '':
                continue
            startsWith = line[0]
            if (startsWith == '['):
                sectionName = line[1:line.index(']')]
                newsection = True
                continue
            
            if (sectionName == "header"):
                headerSectionFound = True
                #get map properties
                epos = line.index('=')
                if (epos != -1):
                    key = line[:epos].strip()
                    value = line[epos + 1:].strip()
                    if (key == "width"):
                        map.setWidth(Int(value))
                    elif (key == "height"):
                        map.setHeight(Int(value))
                    elif (key == "tilewidth"):
                        map.setTileWidth(Int(value))
                    elif (key == "tileheight"):
                        map.setTileHeight(Int(value))
                    elif (key == "orientation"):
                        map.setOrientation(orientationFromString(value))
                    else:
                        map.setProperty(key, value)
                
            elif (sectionName == "tilesets"):
                tilesetsSectionFound = True
                epos = line.index('=')
                key = line[:epos].strip()
                value = line[epos + 1:].strip()
                if (key == "tileset"):
                    _list = value.split(',')
                    absoluteSource = _list[0]
                    if (QDir.isRelativePath(absoluteSource)):
                        absoluteSource = path + '/' + absoluteSource
                    tilesetwidth = 0
                    tilesetheight = 0
                    if len(_list) > 2:
                        tilesetwidth = Int(_list[1])
                        tilesetheight = Int(_list[2])
                    
                    tileset = Tileset.create(QFileInfo(absoluteSource).fileName(), tilesetwidth, tilesetheight)
                    ok = tileset.loadFromImage(absoluteSource)
                    if not ok:
                        self.mError = self.tr("Error loading tileset %s, which expands to %s. Path not found!"%(_list[0], absoluteSource))
                        return None
                    else :
                        if len(_list) > 4:
                            tileset.setTileOffset(QPoint(Int(_list[3]),Int(_list[4])))
                        gidMapper.insert(gid, tileset)
                        if len(_list) > 5:
                            gid += Int(_list[5])
                        else :
                            gid += tileset.tileCount()
                        
                        map.addTileset(tileset)

            elif (sectionName == "layer"):
                if (not tilesetsSectionFound):
                    self.mError = self.tr("No tilesets section found before layer section.")
                    return None
                
                tilelayerSectionFound = True
                epos = line.index('=')
                if (epos != -1):
                    key = line[:epos].strip()
                    value = line[epos + 1:].strip()
                    if (key == "type"):
                        tilelayer = TileLayer(value, 0, 0, map.width(),map.height())
                        map.addLayer(tilelayer)
                    elif (key == "format"):
                        if (value == "dec"):
                            base = 10
#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:flareplugin.py


注:本文中的map.Map.addTileset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。