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

Primitive Tag Value Type Assertions #7

Closed Offroaders123 closed 1 year ago

Offroaders123 commented 2 years ago

Yet another game plan, this one expanding off of #6, the custom primitive types should allow for value type assertions. Essentially, I want to allow the Byte, Short, Int, and Float base classes to accept value assertions. Relating to that part, I want to add a shortcut to allow for better boolean descriptions, since there's not a boolean tag, only a ByteTag. It would essentially be a type shortcut that goes from ByteTag<0 | 1> | boolean to BooleanTag. It would then allow you to specify if a tag is just a plain ByteTag, a "boolean" one, or what it's possible values are. Here's an example (not tested, not sure if this will work as I think it does, yet)

*edit: Thanks wiki!

import { NBTData, BooleanTag, ByteTag, IntTag, StringTag } from "nbtify";

export interface BedrockLevel extends NBTData {
  name: "";
  endian: "little";
  compression: "none";
  data: {
    BiomeOverride: StringTag;
    CenterMapsToOrigin: BooleanTag;
    ConfirmPlatformLockedContent: BooleanTag;
    Difficulty: IntTag<0 | 1 | 2 | 3>;
    FlatWorldLayers: StringTag;
    ForceGameType: BooleanTag;
    GameType: IntTag<0 | 1 | 2 | 3>;
    Generator: IntTag<0 | 1 | 2>;
    // More entries...
  };
}
Offroaders123 commented 1 year ago

Supported! It ended up working out exactly like I wanted, super happy with the look of it.