Offroaders123 / NBTify

A library to read and write NBT files on the web!
http://npm.im/nbtify
MIT License
42 stars 5 forks source link

Accept CompoundTag for Writing #18

Closed Offroaders123 closed 1 year ago

Offroaders123 commented 1 year ago

Accept a CompoundTag compliant object as a value to write to the buffer, when using either NBT.write() or NBTWriter.write(). This makes it so you don't have to construct an NBTData object every time you simply want to write some data to a buffer. Currently, you have to wrap your NBT data CompoundTag object in an NBTData object in order to write it to a buffer. This seems like an extra step to need to do if you don't already have an NBTData object that you are working with. You can pass the same options in to the write methods that the NBTData object would define, so you don't lose anything by doing that either, as you can just manually add the configuration there instead of on the NBTData object. Functional and class-based programming! I think? Haha.

This will eventually make things really nice when I get to JSON and SNBT support (#5, #4), since you might just have a plain JavaScript object (JSON serializable) that you would want to save as NBT, and maybe you aren't using any of the custom NBT primitives at all.

Offroaders123 commented 1 year ago

I essentially created the Issue for this feature after I finished working on this, so that's how I added it so fast, haha. I thought of adding support for this a little while ago, but I didn't make an Issue for it to track it yet. Seeing this on the list of things completed will be more helpful to track all of the changes together, that's why I still made this Issue, even though I finished implementing it already.