Example #1
0
    def __init__(self, editor, sourceLevel, sourceBox, originSourceBox,
                 destLevel, destPoint, copyAir, copyWater, repeatCount):
        self.blockCopyOps = []
        dirtyBoxes = []
        if repeatCount > 1:  # clone tool only
            delta = map(operator.sub, destPoint,
                        editor.toolbar.tools[0].selectionBox().origin)
        else:
            delta = (0, 0, 0)

        for i in range(repeatCount):
            op = BlockCopyOperation(editor, sourceLevel, sourceBox, destLevel,
                                    destPoint, copyAir, copyWater)
            dirty = op.dirtyBox()

            # bounds check - xxx move to BoundingBox
            if dirty.miny >= destLevel.Height or dirty.maxy < 0:
                continue
            if destLevel.Width != 0:
                if dirty.minx >= destLevel.Width or dirty.maxx < 0:
                    continue
                if dirty.minz >= destLevel.Length or dirty.maxz < 0:
                    continue

            dirtyBoxes.append(dirty)
            self.blockCopyOps.append(op)

            destPoint = map(operator.add, delta, destPoint)

        if len(dirtyBoxes):

            def enclosingBox(dirtyBoxes):
                minx = min(map(lambda x: x.minx, dirtyBoxes))
                miny = min(map(lambda x: x.miny, dirtyBoxes))
                minz = min(map(lambda x: x.minz, dirtyBoxes))

                maxx = max(map(lambda x: x.maxx, dirtyBoxes))
                maxy = max(map(lambda x: x.maxy, dirtyBoxes))
                maxz = max(map(lambda x: x.maxz, dirtyBoxes))

                origin = (minx, miny, minz)
                maximum = (maxx, maxy, maxz)

                return BoundingBox(origin, map(operator.sub, maximum, origin))

            self._dirtyBox = enclosingBox(dirtyBoxes)

            if repeatCount > 1 and self.selectOriginalAfterRepeat:
                dirtyBoxes.append(originSourceBox)

            dirty = enclosingBox(dirtyBoxes)
            points = (dirty.origin, map(lambda x: x - 1, dirty.maximum))

            self.selectionOps = [
                SelectionOperation(editor.selectionTool, points)
            ]

        else:
            self._dirtyBox = None
            self.selectionOps = []
Example #2
0
    def __init__(self, editor, sourceLevel, sourceBox, originSourceBox,
                 destLevel, destPoint, copyAir, copyWater, copyBiomes,
                 staticCommands, moveSpawnerPos, regenerateUUID, repeatCount):
        super(CloneOperation, self).__init__(editor, destLevel)

        self.blockCopyOps = []
        dirtyBoxes = []
        if repeatCount > 1:  # clone tool only
            delta = destPoint - editor.toolbar.tools[0].selectionBox().origin
        else:
            delta = (0, 0, 0)

        for i in range(repeatCount):
            op = BlockCopyOperation(editor, sourceLevel, sourceBox, destLevel,
                                    destPoint, copyAir, copyWater, copyBiomes,
                                    staticCommands, moveSpawnerPos,
                                    regenerateUUID)
            dirty = op.dirtyBox()

            # bounds check - xxx move to BoundingBox
            if dirty.miny >= destLevel.Height or dirty.maxy < 0:
                continue
            if destLevel.Width != 0:
                if dirty.minx >= destLevel.Width or dirty.maxx < 0:
                    continue
                if dirty.minz >= destLevel.Length or dirty.maxz < 0:
                    continue

            dirtyBoxes.append(dirty)
            self.blockCopyOps.append(op)

            destPoint += delta

        if len(dirtyBoxes):

            def enclosingBox(dirtyBoxes):
                return reduce(lambda a, b: a.union(b), dirtyBoxes)

            self._dirtyBox = enclosingBox(dirtyBoxes)

            if repeatCount > 1 and self.selectOriginalAfterRepeat:
                dirtyBoxes.append(originSourceBox)

            dirty = enclosingBox(dirtyBoxes)
            points = (dirty.origin, dirty.maximum - (1, 1, 1))

            self.selectionOps = [
                SelectionOperation(editor.selectionTool, points)
            ]

        else:
            self._dirtyBox = None
            self.selectionOps = []

        self.canUndo = False