Beispiel #1
0
    def __init__(self, parent, world_dirs, open_world_callback, sort=True):
        super(WorldList, self).__init__(parent)

        self.worlds = []

        world_formats = []
        for world_path in world_dirs:
            if os.path.isdir(world_path):
                try:
                    world_formats.append(
                        world_interface.load_format(world_path))
                except Exception as e:
                    log.info(f"Could not find loader for {world_path} {e}")
        if sort:
            world_formats = reversed(
                sorted(world_formats, key=lambda f: f.last_played))

        for world_format in world_formats:
            try:
                world_button = WorldUIButton(self, world_format,
                                             open_world_callback)
                self.add_object(world_button, 0, wx.ALL | wx.EXPAND)
                self.worlds.append(world_button)
            except Exception as e:
                log.info(
                    f"Failed to display world button for {world_format.world_path} {e}"
                )

        self.Layout()
Beispiel #2
0
        def test_save(self):
            output_wrapper = None
            version_string = self.world.world_wrapper.game_version_string

            if "1.12.2" in version_string:
                output_wrapper = load_format(
                    get_world_path("1.12.2 World to 1.13 World")
                )
            else:
                output_wrapper = load_format(
                    get_world_path("1.13 World to 1.12.2 World")
                )
            output_wrapper.open()

            self.world.save(output_wrapper)
            self.world.close()
            output_wrapper.close()
    def _output_world_callback(self, path):
        if path == self.world.world_path:
            wx.MessageBox("The input and output worlds must be different")
            return
        try:
            out_world_format = world_interface.load_format(path)
            self.out_world_path = path

        except Exception:
            return

        for child in list(self._output.GetChildren())[1:]:
            child.Destroy()
        self._output.add_object(WorldUI(self._output, out_world_format), 0)
        self._output.Layout()
        self._output.Fit()
        self.Layout()
Beispiel #4
0
 def _convert_method(self):
     global work_count
     try:
         out_world = world_interface.load_format(self.out_world_path)
         log.info(f'Converting world {self.world.world_path} to {out_world.world_path}')
         out_world: WorldFormatWrapper
         out_world.open()
         self.world.save(out_world, self._update_loading_bar)
         out_world.close()
         message = 'World conversion completed'
         log.info(f'Finished converting world {self.world.world_path} to {out_world.world_path}')
     except Exception as e:
         message = f'Error during conversion\n{e}'
         log.error(message, exc_info=True)
     self._update_loading_bar(0, 100)
     self.convert_button.Enable()
     wx.MessageBox(
         message
     )
     work_count -= 1
Beispiel #5
0
    def _run_operation(self, evt):
        mode = self._operation.GetStringSelection()
        if mode == 'convert to other world':
            dir_dialog = wx.DirDialog(
                None, "Choose other world directory", "",
                wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST)
            try:
                if dir_dialog.ShowModal() == wx.ID_CANCEL:
                    return
                other_world_path = dir_dialog.GetPath()
            except Exception:
                wx.LogError('Failed to open directory!')
                return
            finally:
                dir_dialog.Destroy()

            try:
                other_format = world_interface.load_format(other_world_path)
            except:
                return

            self._world.save(other_format)
            print('Finished saving world')
                for block in chunk.blocks[
                    0, :, 0
                ].ravel():  # the blockstates of one vertical column
                    print(world.palette[block])
            else:
                print("Not enough arguments given. Format must be:")
                print("random_chunk/air <origin_world_path> <cx> <cz>")

        elif mode == "convert":
            if len(args) >= 3:
                world_path = args[1]
                destination_path = args[2]

                print(f"Loading world at {world_path}")
                world = load_world(world_path)
                output_wrapper = load_format(destination_path)
                output_wrapper.open()
                world.save(output_wrapper)
                world.close()
                output_wrapper.close()
            else:
                print("Not enough arguments given. Format must be:")
                print("convert <origin_world_path> <destination_world_path>")

        elif mode == "delete_chunk":
            if len(args) >= 4:
                world_path = args[1]
                cx, cz = int(args[2]), int(args[3])

                print(f"Loading world at {world_path}")
                world = load_world(world_path)