@spyglassmc/nbt 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/checker/index.js +10 -7
- package/lib/index.d.ts +1 -1
- package/lib/node/index.d.ts +5 -5
- package/package.json +4 -4
package/lib/checker/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
|
-
import * as mcdoc from '@spyglassmc/mcdoc';
|
|
3
2
|
import { localeQuote, localize } from '@spyglassmc/locales';
|
|
3
|
+
import * as mcdoc from '@spyglassmc/mcdoc';
|
|
4
4
|
import { NbtListNode } from '../node/index.js';
|
|
5
5
|
import { localizeTag } from '../util.js';
|
|
6
6
|
import { getBlocksFromItem, getEntityFromItem, getSpecialStringParser } from './mcdocUtil.js';
|
|
@@ -241,7 +241,10 @@ export function path(registry, id) {
|
|
|
241
241
|
};
|
|
242
242
|
}
|
|
243
243
|
export function fieldValue(type, options) {
|
|
244
|
-
const isInRange = (value,
|
|
244
|
+
const isInRange = (value, { kind, min = -Infinity, max = Infinity }) => {
|
|
245
|
+
const comparator = (a, b, exclusive) => exclusive ? a < b : a <= b;
|
|
246
|
+
return comparator(min, value, kind & 0b10) && comparator(value, max, kind & 0b01);
|
|
247
|
+
};
|
|
245
248
|
const ExpectedTypes = {
|
|
246
249
|
boolean: 'nbt:byte',
|
|
247
250
|
byte: 'nbt:byte',
|
|
@@ -276,12 +279,12 @@ export function fieldValue(type, options) {
|
|
|
276
279
|
case 'long_array':
|
|
277
280
|
node = node;
|
|
278
281
|
if (type.lengthRange && !isInRange(node.children.length, type.lengthRange)) {
|
|
279
|
-
ctx.err.report(localize('expected', localize('nbt.checker.collection.length-between', localizeTag(node.type), type.lengthRange
|
|
282
|
+
ctx.err.report(localize('expected', localize('nbt.checker.collection.length-between', localizeTag(node.type), type.lengthRange.min ?? '-∞', type.lengthRange.max ?? '+∞')), node, 2 /* core.ErrorSeverity.Warning */);
|
|
280
283
|
}
|
|
281
284
|
if (type.valueRange) {
|
|
282
285
|
for (const { value: childNode } of node.children) {
|
|
283
286
|
if (childNode && !isInRange(Number(childNode.value), type.valueRange)) {
|
|
284
|
-
ctx.err.report(localize('number.between', type.valueRange
|
|
287
|
+
ctx.err.report(localize('number.between', type.valueRange.min ?? '-∞', type.valueRange.max ?? '+∞'), node, 2 /* core.ErrorSeverity.Warning */);
|
|
285
288
|
}
|
|
286
289
|
}
|
|
287
290
|
}
|
|
@@ -294,7 +297,7 @@ export function fieldValue(type, options) {
|
|
|
294
297
|
case 'double':
|
|
295
298
|
node = node;
|
|
296
299
|
if (type.valueRange && !isInRange(Number(node.value), type.valueRange)) {
|
|
297
|
-
ctx.err.report(localize('number.between', type.valueRange
|
|
300
|
+
ctx.err.report(localize('number.between', type.valueRange.min ?? '-∞', type.valueRange.max ?? '+∞'), node, 2 /* core.ErrorSeverity.Warning */);
|
|
298
301
|
}
|
|
299
302
|
break;
|
|
300
303
|
case 'dispatcher':
|
|
@@ -312,7 +315,7 @@ export function fieldValue(type, options) {
|
|
|
312
315
|
node = node;
|
|
313
316
|
type = mcdoc.simplifyListType(type);
|
|
314
317
|
if (type.lengthRange && !isInRange(node.children.length, type.lengthRange)) {
|
|
315
|
-
ctx.err.report(localize('expected', localize('nbt.checker.collection.length-between', localizeTag(node.type), type.lengthRange
|
|
318
|
+
ctx.err.report(localize('expected', localize('nbt.checker.collection.length-between', localizeTag(node.type), type.lengthRange.min ?? '-∞', type.lengthRange.max ?? '+∞')), node, 2 /* core.ErrorSeverity.Warning */);
|
|
316
319
|
}
|
|
317
320
|
for (const { value: childNode } of node.children) {
|
|
318
321
|
if (childNode) {
|
|
@@ -338,7 +341,7 @@ export function fieldValue(type, options) {
|
|
|
338
341
|
const parser = ctx.meta.getParser(parserName);
|
|
339
342
|
const result = core.parseStringValue(parser, node.value, node.valueMap, ctx);
|
|
340
343
|
if (result !== core.Failure) {
|
|
341
|
-
|
|
344
|
+
node.children = [result];
|
|
342
345
|
result.parent = node;
|
|
343
346
|
}
|
|
344
347
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export * as checker from './checker/index.js';
|
|
|
3
3
|
export * as colorizer from './colorizer/index.js';
|
|
4
4
|
export * from './node/index.js';
|
|
5
5
|
export * as parser from './parser/index.js';
|
|
6
|
-
export declare const initialize: core.
|
|
6
|
+
export declare const initialize: core.SyncProjectInitializer;
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/node/index.d.ts
CHANGED
|
@@ -67,8 +67,8 @@ export declare namespace NbtCollectionNode {
|
|
|
67
67
|
function is(node: core.AstNode | undefined): node is NbtCollectionNode;
|
|
68
68
|
}
|
|
69
69
|
export interface NbtListNode extends core.ListNode<NbtNode> {
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
type: 'nbt:list';
|
|
71
|
+
valueType?: NbtNode['type'];
|
|
72
72
|
}
|
|
73
73
|
export declare namespace NbtListNode {
|
|
74
74
|
function is(node: core.AstNode | undefined): node is NbtListNode;
|
|
@@ -78,19 +78,19 @@ export declare namespace NbtPrimitiveArrayNode {
|
|
|
78
78
|
function is(node: core.AstNode | undefined): node is NbtPrimitiveArrayNode;
|
|
79
79
|
}
|
|
80
80
|
export interface NbtByteArrayNode extends core.ListNode<NbtByteNode> {
|
|
81
|
-
|
|
81
|
+
type: 'nbt:byte_array';
|
|
82
82
|
}
|
|
83
83
|
export declare namespace NbtByteArrayNode {
|
|
84
84
|
function is(node: core.AstNode | undefined): node is NbtByteArrayNode;
|
|
85
85
|
}
|
|
86
86
|
export interface NbtIntArrayNode extends core.ListNode<NbtIntNode> {
|
|
87
|
-
|
|
87
|
+
type: 'nbt:int_array';
|
|
88
88
|
}
|
|
89
89
|
export declare namespace NbtIntArrayNode {
|
|
90
90
|
function is(node: core.AstNode | undefined): node is NbtIntArrayNode;
|
|
91
91
|
}
|
|
92
92
|
export interface NbtLongArrayNode extends core.ListNode<NbtLongNode> {
|
|
93
|
-
|
|
93
|
+
type: 'nbt:long_array';
|
|
94
94
|
}
|
|
95
95
|
export declare namespace NbtLongArrayNode {
|
|
96
96
|
function is(node: core.AstNode | undefined): node is NbtLongArrayNode;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spyglassmc/nbt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/SpyglassMC/Spyglass/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@spyglassmc/core": "0.
|
|
29
|
-
"@spyglassmc/locales": "0.
|
|
30
|
-
"@spyglassmc/mcdoc": "0.
|
|
28
|
+
"@spyglassmc/core": "0.3.0",
|
|
29
|
+
"@spyglassmc/locales": "0.3.0",
|
|
30
|
+
"@spyglassmc/mcdoc": "0.3.0"
|
|
31
31
|
}
|
|
32
32
|
}
|