예제 #1
0
    def _operation(self, world: "World", dimension: Dimension,
                   selection: SelectionGroup) -> OperationReturnType:
        if len(selection.selection_boxes) == 0:
            raise OperationError("No selection was given to export.")
        elif len(selection.selection_boxes) != 1:
            raise OperationError(
                "The mcstructure format only supports a single selection box.")

        path = self._file_picker.GetPath()
        version = self._version_define.version

        if isinstance(path, str) and path.endswith('.mcstructure') and version:
            wrapper = MCStructureFormatWrapper(path, 'w')
            wrapper.selection = selection
            wrapper.version = version
            wrapper.translation_manager = world.translation_manager
            wrapper.open()
            for cx, cz in wrapper.selection.chunk_locations():
                try:
                    chunk = world.get_chunk(cx, cz, dimension)
                    wrapper.commit_chunk(chunk, world.palette)
                except ChunkLoadError:
                    continue

            wrapper.close()
        else:
            raise OperationError(
                'Please specify a save location and version in the options before running.'
            )
예제 #2
0
    def _operation(self, world: "World", dimension: Dimension,
                   selection: SelectionGroup) -> OperationReturnType:
        if len(selection.selection_boxes) == 0:
            raise OperationError("No selection was given to export.")
        elif len(selection.selection_boxes) != 1:
            raise OperationError(
                "The mcstructure format only supports a single selection box.")

        path = self._file_picker.GetPath()
        version = self._version_define.version_number

        if isinstance(path, str) and path.endswith(".mcstructure") and version:
            wrapper = MCStructureFormatWrapper(path, "w")
            wrapper.selection = selection
            wrapper.version = version
            wrapper.translation_manager = world.translation_manager
            wrapper.open()
            chunk_count = len(list(selection.chunk_locations()))
            yield 0, f"Exporting {os.path.basename(path)}"
            for chunk_index, (cx,
                              cz) in enumerate(selection.chunk_locations()):
                try:
                    chunk = world.get_chunk(cx, cz, dimension)
                    wrapper.commit_chunk(chunk, world.palette)
                except ChunkLoadError:
                    continue
                yield (chunk_index + 1) / chunk_count

            wrapper.close()
        else:
            raise OperationError(
                "Please specify a save location and version in the options before running."
            )
 def _operation(
     self, world: "World", dimension: Dimension, selection: SelectionGroup
 ) -> OperationReturnType:
     path = self._file_picker.GetPath()
     platform = self._version_define.platform
     version = self._version_define.version_number
     if isinstance(path, str) and platform and version:
         wrapper = ConstructionFormatWrapper(path)
         if wrapper.exists:
             response = wx.MessageDialog(
                 self,
                 f"A file is already present at {path}. Do you want to continue?",
                 style=wx.YES | wx.NO,
             ).ShowModal()
             if response == wx.ID_CANCEL:
                 return
         wrapper.create_and_open(platform, version, selection)
         wrapper.translation_manager = world.translation_manager
         wrapper_dimension = wrapper.dimensions[0]
         chunk_count = len(list(selection.chunk_locations()))
         yield 0, f"Exporting {os.path.basename(path)}"
         for chunk_index, (cx, cz) in enumerate(selection.chunk_locations()):
             try:
                 chunk = world.get_chunk(cx, cz, dimension)
                 wrapper.commit_chunk(chunk, wrapper_dimension)
             except ChunkLoadError:
                 continue
             yield (chunk_index + 1) / chunk_count
         wrapper.save()
         wrapper.close()
     else:
         raise OperationError(
             "Please specify a save location and version in the options before running."
         )
예제 #4
0
    def _operation(self, world: "World", dimension: Dimension,
                   selection: SelectionGroup):
        path = self._file_picker.GetPath()
        if isinstance(
                path,
                str) and path.endswith('.schematic') and os.path.isfile(path):
            wrapper = SchematicFormatWrapper(path, 'r')
            wrapper.translation_manager = world.translation_manager
            wrapper.open()
            selection = wrapper.selection

            global_palette = BlockManager()
            chunks = {}
            for (cx, cz) in wrapper.all_chunk_coords():
                try:
                    chunks[(cx,
                            cz)] = wrapper.load_chunk(cx, cz, global_palette)
                except ChunkLoadError:
                    pass

            wrapper.close()
            self.canvas.paste(Structure(chunks, global_palette, selection))
        else:
            raise OperationError(
                'Please specify a schematic file in the options before running.'
            )
예제 #5
0
    def _operation(self, world: "World", dimension: Dimension,
                   selection: SelectionGroup):
        path = self._file_picker.GetPath()

        if (isinstance(path, str) and path.endswith(".mcstructure")
                and os.path.isfile(path)):
            wrapper = MCStructureFormatWrapper(path, "r")
            wrapper.translation_manager = world.translation_manager
            wrapper.open()
            selection = wrapper.selection

            global_palette = BlockManager()
            chunks = {}
            chunk_count = len(list(wrapper.all_chunk_coords()))
            yield 0, f"Importing {os.path.basename(path)}"
            for chunk_index, (cx, cz) in enumerate(wrapper.all_chunk_coords()):
                try:
                    chunk = chunks[(cx, cz)] = wrapper.load_chunk(cx, cz)
                    chunk.block_palette = global_palette
                except ChunkLoadError:
                    pass
                yield (chunk_index + 1) / chunk_count

            wrapper.close()
            self.canvas.paste(Structure(chunks, global_palette, selection))
        else:
            raise OperationError(
                "Please specify a mcstructure file in the options before running."
            )
예제 #6
0
    def _operation(self, world: "World", dimension: Dimension,
                   selection: SelectionGroup):
        path = self._file_picker.GetPath()
        if isinstance(path, str) and path.endswith(
                '.construction') and os.path.isfile(path):
            wrapper = ConstructionFormatWrapper(path, 'r')
            wrapper.translation_manager = world.translation_manager
            wrapper.open()
            selection = wrapper.selection

            global_palette = BlockManager()
            chunks = {}
            chunk_count = len(list(wrapper.all_chunk_coords()))
            for chunk_index, (cx, cz) in enumerate(wrapper.all_chunk_coords()):
                try:
                    chunks[(cx,
                            cz)] = wrapper.load_chunk(cx, cz, global_palette)
                    yield 100 * (chunk_index + 1) / chunk_count
                except ChunkLoadError:
                    pass

            wrapper.close()
            self.canvas.paste(Structure(chunks, global_palette, selection))
        else:
            raise OperationError(
                'Please specify a construction file in the options before running.'
            )
예제 #7
0
def copy(world: "World", dimension: Dimension, selection: SelectionGroup):
    if selection:
        structure = Structure.from_world(world, selection, dimension)
        structure_cache.add_structure(structure)
        raise OperationSilentAbort
    else:
        raise OperationError(
            "At least one selection is required for the copy operation.")
예제 #8
0
def copy(world: "World", dimension: Dimension,
         selection: SelectionGroup) -> OperationReturnType:
    if selection:
        yield 0, "Copying"
        structure = yield from world.extract_structure_iter(
            selection, dimension)
        structure_cache.add_structure(structure, structure.dimensions[0])
        raise OperationSilentAbort
    else:
        raise OperationError(
            "At least one selection is required for the copy operation.")
예제 #9
0
 def _operation(self, world: "World", dimension: Dimension,
                selection: SelectionGroup):
     path = self._file_picker.GetPath()
     if (isinstance(path, str) and path.endswith(".mcstructure")
             and os.path.isfile(path)):
         wrapper = MCStructureFormatWrapper(path)
         wrapper.translation_manager = world.translation_manager
         self.canvas.paste(Structure(path, wrapper), wrapper.dimensions[0])
     else:
         raise OperationError(
             "Please specify a mcstructure file in the options before running."
         )
예제 #10
0
def cut(world: "World", dimension: Dimension,
        selection: SelectionGroup) -> OperationReturnType:
    if selection:
        structure = world.extract_structure(selection, dimension)
        structure_cache.add_structure(structure, structure.dimensions[0])
        yield from delete(
            world,
            dimension,
            selection,
        )
    else:
        raise OperationError(
            "At least one selection is required for the copy operation.")
예제 #11
0
    def _operation(self, world: "World", dimension: Dimension, selection: SelectionGroup) -> OperationReturnType:
        path = self._file_picker.GetPath()
        platform = self._version_define.platform
        version = self._version_define.version
        if isinstance(path, str) and path.endswith('.construction') and platform and version:
            wrapper = ConstructionFormatWrapper(path, 'w')
            wrapper.platform = platform
            wrapper.version = version
            wrapper.selection = selection
            wrapper.translation_manager = world.translation_manager
            wrapper.open()
            for cx, cz in selection.chunk_locations():
                try:
                    chunk = world.get_chunk(cx, cz, dimension)
                    wrapper.commit_chunk(chunk, world.palette)
                except ChunkLoadError:
                    continue

            wrapper.close()
        else:
            raise OperationError('Please specify a save location and version in the options before running.')