Skip to content

Commit

Permalink
Revert "Refactor format wrapper (#264)"
Browse files Browse the repository at this point in the history
This reverts commit 5c0207c.
  • Loading branch information
gentlegiantJGC committed Sep 20, 2023
1 parent 5c0207c commit b62447b
Show file tree
Hide file tree
Showing 19 changed files with 214 additions and 374 deletions.
25 changes: 13 additions & 12 deletions amulet/api/level/base_level/base_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,19 @@ class BaseLevel:
It exposes chunk data and other data using a history system to track and enable undoing changes.
"""

def __init__(self, path: str, format_wrapper: api_wrapper.BaseFormatWrapper):
def __init__(self, path: str, format_wrapper: api_wrapper.FormatWrapper):
"""
Construct a :class:`BaseLevel` object from the given data.
This should not be used directly. You should instead use :func:`amulet.load_level`.
:param path: The path to the data being loaded. May be a file or directory. If blank there is no data on disk associated with this.
:param format_wrapper: The :class:`BaseFormatWrapper` instance that the level will wrap around.
:param format_wrapper: The :class:`FormatWrapper` instance that the level will wrap around.
"""
self._path = path

self._level_wrapper = format_wrapper
if not self.level_wrapper.is_open:
self.level_wrapper.open()
self.level_wrapper.open()

self._block_palette = BlockManager()
self._block_palette.get_add_block(
Expand All @@ -87,7 +86,7 @@ def __del__(self):
self.close()

@property
def level_wrapper(self) -> api_wrapper.BaseFormatWrapper:
def level_wrapper(self) -> api_wrapper.FormatWrapper:
"""A class to access data directly from the level."""
return self._level_wrapper

Expand Down Expand Up @@ -413,11 +412,11 @@ def pre_save_operation(self) -> Generator[float, None, bool]:

def save(
self,
wrapper: api_wrapper.BaseFormatWrapper = None,
wrapper: api_wrapper.FormatWrapper = None,
progress_callback: Callable[[int, int], None] = None,
):
"""
Save the level to the given :class:`BaseFormatWrapper`.
Save the level to the given :class:`FormatWrapper`.
:param wrapper: If specified will save the data to this wrapper instead of self.level_wrapper
:param progress_callback: Optional progress callback to let the calling program know the progress. Input format chunk_index, chunk_count
Expand All @@ -428,10 +427,10 @@ def save(
progress_callback(chunk_index, chunk_count)

def save_iter(
self, wrapper: api_wrapper.BaseFormatWrapper = None
self, wrapper: api_wrapper.FormatWrapper = None
) -> Generator[Tuple[int, int], None, None]:
"""
Save the level to the given :class:`BaseFormatWrapper`.
Save the level to the given :class:`FormatWrapper`.
This will yield the progress which can be used to update a UI.
Expand All @@ -455,7 +454,9 @@ def save_iter(
if save_as:
# The input wrapper is not the same as the loading wrapper (save-as)
# iterate through every chunk in the input level and save them to the wrapper
log.info(f"Converting level {self.level_wrapper} to level {wrapper}")
log.info(
f"Converting level {self.level_wrapper.path} to level {wrapper.path}"
)
wrapper.translation_manager = (
self.level_wrapper.translation_manager
) # TODO: this might cause issues in the future
Expand Down Expand Up @@ -502,9 +503,9 @@ def save_iter(
wrapper.unload()

self.history_manager.mark_saved()
log.info(f"Saving changes to level {wrapper}")
log.info(f"Saving changes to level {wrapper.path}")
wrapper.save()
log.info(f"Finished saving changes to level {wrapper}")
log.info(f"Finished saving changes to level {wrapper.path}")

def purge(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(
To extract a section of a world you should use :meth:`~amulet.api.level.BaseLevel.extract_structure`.
"""
super().__init__("", VoidFormatWrapper.create())
super().__init__("", VoidFormatWrapper(""))
self._selection = SelectionGroup(
[
SelectionBox(
Expand Down
28 changes: 17 additions & 11 deletions amulet/api/level/immutable_structure/void_format_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
AnyNDArray,
VersionNumberTuple,
)
from amulet.api.wrapper import BaseFormatWrapper, CreatableFormatWrapper
from amulet.api.wrapper import FormatWrapper
from amulet.api.errors import ChunkDoesNotExist, PlayerDoesNotExist
from amulet.api.player import Player
from amulet.api.chunk import Chunk
Expand All @@ -18,7 +18,7 @@
from amulet.api.wrapper import Interface


class VoidFormatWrapper(BaseFormatWrapper[VersionNumberTuple], CreatableFormatWrapper):
class VoidFormatWrapper(FormatWrapper[VersionNumberTuple]):
"""
A custom :class:`FormatWrapper` class that has no associated data.
Expand All @@ -27,25 +27,21 @@ class VoidFormatWrapper(BaseFormatWrapper[VersionNumberTuple], CreatableFormatWr
All methods effectively do nothing.
"""

def __init__(self):
super().__init__()
def __init__(self, path: str):
super().__init__(path)
self._platform = "Unknown Platform"
self._version = (0, 0, 0)

@classmethod
def create(cls) -> BaseFormatWrapper:
return cls()

@property
def level_name(self) -> str:
return "Void"

@staticmethod
def is_valid(token) -> bool:
def is_valid(path: str) -> bool:
return False

@staticmethod
def valid_formats() -> Dict[PlatformType, Tuple[bool, bool]]:
@property
def valid_formats(self) -> Dict[PlatformType, Tuple[bool, bool]]:
return {}

@property
Expand All @@ -71,6 +67,16 @@ def _encode(
) -> Any:
raise Exception("If this is called something is wrong")

def _create(
self,
overwrite: bool,
bounds: Union[
SelectionGroup, Dict[Dimension, Optional[SelectionGroup]], None
] = None,
**kwargs
):
pass

def _open(self):
pass

Expand Down
4 changes: 0 additions & 4 deletions amulet/api/wrapper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
from amulet.api.wrapper.format_wrapper import (
BaseFormatWrapper,
CreatableFormatWrapper,
LoadableFormatWrapper,
DiskFormatWrapper,
FormatWrapper,
DefaultSelection,
)
Expand Down
Loading

0 comments on commit b62447b

Please sign in to comment.