Skip to content

Commit

Permalink
SNBT Empty ListTag Types
Browse files Browse the repository at this point in the history
Check out the message about my findings for this commit, in #40 down below, above when this was referenced in that feed when you click on it.

Note how the tests are still not passing, it's because SNBT has no way of tracking the types for empty ListTag entries.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol
https://stackoverflow.com/questions/31897015/what-is-global-symbol-registry
https://stackoverflow.com/questions/49619054/whats-the-purpose-of-registry-symbols-symbol-for-in-javascript-es6

#40
#41

And woah! Who knew the fonts for road signs are standardized! The main one is called Highway Gothic, and it's been around since the 50s. The new one was going to be Clearview, but looks like they reversed making that one the new standard. It's present across a lot of the southwest, I see it a lot when crossing the river into Arizona. I really like it! I hope it stays around.
  • Loading branch information
Offroaders123 committed Nov 28, 2023
1 parent 92fc6d5 commit a0e472e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/read.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NBTData } from "./format.js";
import { Int8, Int16, Int32, Float32 } from "./primitive.js";
import { TAG } from "./tag.js";
import { TAG, NBT_LIST_TYPE } from "./tag.js";
import { decompress } from "./compression.js";

import type { Name, Endian, Compression, BedrockLevel } from "./format.js";
Expand Down Expand Up @@ -315,10 +315,13 @@ export class NBTReader {
const entry = this.#readTag(type);
value.push(entry);
}
if (type === TAG.STRING || length < 1){
console.log(type);
console.log(value);

value[NBT_LIST_TYPE] = type;

if (length < 1 && type !== TAG.END){
console.log("read:",type,value);
}

return value;
}

Expand Down
6 changes: 5 additions & 1 deletion src/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export type ByteArrayTag = Int8Array;

export type StringTag = string;

export interface ListTag<T extends Tag | undefined> extends Array<T> {}
export interface ListTag<T extends Tag | undefined> extends Array<T> {
[NBT_LIST_TYPE]?: TAG;
}

export type ListTagLike = any[];

Expand Down Expand Up @@ -60,6 +62,8 @@ export enum TAG {

Object.freeze(TAG);

export const NBT_LIST_TYPE = Symbol("nbt.list.type");

export function isTag<T extends Tag>(value: any): value is T {
return getTagType(value) !== null;
}
Expand Down
10 changes: 8 additions & 2 deletions src/write.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NBTData } from "./format.js";
import { TAG, isTag, getTagType } from "./tag.js";
import { TAG, NBT_LIST_TYPE, isTag, getTagType } from "./tag.js";
import { Int32 } from "./primitive.js";
import { compress } from "./compression.js";

Expand Down Expand Up @@ -247,9 +247,15 @@ export class NBTWriter {
}

#writeList(value: ListTag<Tag>): void {
if (value[NBT_LIST_TYPE] !== undefined) console.log(value[NBT_LIST_TYPE]);
value = value.filter(isTag);
const type: TAG = (value[0] !== undefined) ? getTagType(value[0]) : TAG.END;
const type: TAG = value[NBT_LIST_TYPE] ?? ((value[0] !== undefined) ? getTagType(value[0]) : TAG.END);
const { length } = value;

if (length < 1 && type !== TAG.END){
console.log("write:",type,value);
}

this.#writeTagType(type);
this.#writeInt(length);
for (const entry of value){
Expand Down

0 comments on commit a0e472e

Please sign in to comment.