Ejemplo n.º 1
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.'
            )
Ejemplo n.º 2
0
def import_construction(
    world: "World",
    dimension: Dimension,
    options: dict
) -> Structure:
    path = options.get('path', None)
    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 = {}
        for (cx, cz) in wrapper.all_chunk_coords():
            try:
                chunks[(cx, cz)] = wrapper.load_chunk(cx, cz, global_palette)
            except ChunkLoadError:
                pass

        wrapper.close()
        return Structure(
            chunks,
            global_palette,
            selection
        )
    else:
        raise Exception('Please specify a construction file in the options before running.')
Ejemplo n.º 3
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)
         wrapper.translation_manager = world.translation_manager
         self.canvas.paste(Structure(path, wrapper), wrapper.dimensions[0])
     else:
         raise OperationError(
             "Please specify a construction file in the options before running."
         )
Ejemplo n.º 4
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_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."
         )
Ejemplo n.º 5
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.')
Ejemplo n.º 6
0
def export_construction(world: "World", dimension: Dimension,
                        selection: SelectionGroup, options: dict):
    path, platform, version = options.get('path', None), options.get(
        'platform', None), options.get('version', None)
    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 Exception(
            'Please specify a save location and version in the options before running.'
        )