From 91f9dfa5605b3e19fb32de1bd4defc46b29bb6f3 Mon Sep 17 00:00:00 2001 From: David Vierra Date: Sun, 31 Jan 2016 13:32:52 -1000 Subject: [PATCH] Brush command combines multiple selections instead of using the first --- src/mcedit2/editortools/brush/__init__.py | 4 ++-- src/mcedit2/editortools/brush/modes.py | 18 ++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/mcedit2/editortools/brush/__init__.py b/src/mcedit2/editortools/brush/__init__.py index f4815fa..69d9ccd 100644 --- a/src/mcedit2/editortools/brush/__init__.py +++ b/src/mcedit2/editortools/brush/__init__.py @@ -70,11 +70,11 @@ class BrushCommand(SimplePerformCommand): def _perform(self): yield 0, len(self.points), "Applying {0} brush...".format(self.brushMode.name) try: - #xxx combine selections selections = [self.brushShape.createShapedSelection(self.brushMode.brushBoxForPoint(point, self.options), self.editorSession.currentDimension) for point in self.points] - self.brushMode.applyToSelections(self, selections) + selection = reduce(lambda a, b: a | b, selections) + self.brushMode.applyToSelection(self, selection) except NotImplementedError: for i, point in enumerate(self.points): f = self.brushMode.applyToPoint(self, point) diff --git a/src/mcedit2/editortools/brush/modes.py b/src/mcedit2/editortools/brush/modes.py index ff8cd6e..96c549d 100644 --- a/src/mcedit2/editortools/brush/modes.py +++ b/src/mcedit2/editortools/brush/modes.py @@ -35,10 +35,11 @@ class BrushMode(QtCore.QObject): """ raise NotImplementedError - def applyToSelections(self, command, selections): + def applyToSelection(self, command, selection): """ - Called by BrushCommand to apply this brush mode to the given selection. Selection is generated - by calling + Called by BrushCommand to apply this brush mode to the given selection. Selection + is generated by calling BrushShape.createShapedSelection and optionally + combining multiple selections. """ raise NotImplementedError @@ -92,13 +93,12 @@ class Fill(BrushMode): def getOptions(self): return {'blockInfo': self.blockTypeButton.block} - def applyToSelections(self, command, selections): + def applyToSelection(self, command, selection): """ :type command: BrushCommand """ - # xxx combine selections? - fill = command.editorSession.currentDimension.fillBlocksIter(selections[0], command.options['blockInfo']) + fill = command.editorSession.currentDimension.fillBlocksIter(selection, command.options['blockInfo']) showProgress("Applying brush...", fill) def brushBoxForPoint(self, point, options): @@ -139,14 +139,12 @@ class Biome(BrushMode): self.optionsWidget.setLayout(Column(Row(label, self.biomeTypeBox, margin=0), None, margin=0)) return self.optionsWidget - def applyToSelections(self, command, selections): + def applyToSelection(self, command, selection): """ :type command: BrushCommand """ - #task = command.editorSession.currentDimension.fillBlocksIter(selections[0], command.blockInfo) - #showProgress("Applying brush...", task) - selection = selections[0] + # TODO: progress bar, biome fill biomeID = command.options['biomeID'] for x, _, z in selection.positions: command.editorSession.currentDimension.setBiomeID(x, z, biomeID)