Skip to content

Commit

Permalink
feat: remove root
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The Root class is gone and so is the root attribute on files

Fixes #145
  • Loading branch information
vberlier committed Oct 23, 2021
1 parent 09eb844 commit e9180a2
Show file tree
Hide file tree
Showing 32 changed files with 196 additions and 254 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ its python counterpart. This means that all the builtin operations defined on th
import nbtlib

nbt_file = nbtlib.load('bigtest.nbt')
assert nbt_file.root['intTest'] == 2147483647
assert nbt_file['intTest'] == 2147483647
```

For example, instances of `nbtlib.File` inherit from regular `Compound` tags, which themselves inherit from the builtin python dictionary `dict`. Similarly, instances of `Int` tags inherit from the builtin class `int`.
Expand All @@ -61,7 +61,7 @@ import nbtlib
from nbtlib.tag import Int

with nbtlib.load('demo.nbt') as demo:
demo.root['counter'] = Int(demo.root['counter'] + 1)
demo['counter'] = Int(demo['counter'] + 1)
```

You can also call the `save` method manually.
Expand All @@ -71,7 +71,7 @@ import nbtlib
from nbtlib.tag import Int

demo = nbtlib.load('demo.nbt')
demo.root['counter'] = Int(demo.root['counter'] + 1)
demo['counter'] = Int(demo['counter'] + 1)
demo.save()
```

Expand Down
Loading

1 comment on commit e9180a2

@MestreLion
Copy link
Contributor

@MestreLion MestreLion commented on e9180a2 Oct 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason to remove the Root class and shove the new write(), parse() and root_name directly in File?

The new methods and attributes, as well as removing .root (the attribute, not the class), are a very welcome feature as it removes the extra layer. But that could have been done in the existing Root class, no?

It's important to keep a distinction between a file, with .load() and .filename, and a root tag, containing the special .write(), .parse() and root_name, as per #55

  • All file Compounds are also root tags, such as in .dat files, but...
  • Not all root tag Compounds are also files, such as chunks in .mca files.

Please do not revert #55! That is not needed to fix #145 which this commit is intended to.

Please sign in to comment.