simplified-mojang-jsons 0.0.8 → 0.0.9
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/dist/builders/behaviors/lootTables/LootTablesBuilder.d.ts.map +1 -1
- package/dist/builders/behaviors/lootTables/LootTablesTemplateBuilder.d.ts +33 -0
- package/dist/builders/behaviors/lootTables/LootTablesTemplateBuilder.d.ts.map +1 -1
- package/dist/index.js +107 -3
- package/dist/index.js.map +2 -2
- package/dist/types/behaviors/lootTables/LootTablesTemplate.d.ts +20 -0
- package/dist/types/behaviors/lootTables/LootTablesTemplate.d.ts.map +1 -1
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LootTablesBuilder.d.ts","sourceRoot":"","sources":["../../../../src/builders/behaviors/lootTables/LootTablesBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wDAAwD,CAAC;AAG1F;;;;;GAKG;AACH,qBAAa,wBAAwB;IACjC;;;;OAIG;IACH,OAAO,CAAC,KAAK,CAA0B;IAEvC,SAAS,eAAmB;IAE5B;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAIlD;IAED;;;;;;;;;OASG;IACH,SAAS,CAAC,aAAa,CAAC,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC;IACjD,SAAS,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"LootTablesBuilder.d.ts","sourceRoot":"","sources":["../../../../src/builders/behaviors/lootTables/LootTablesBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wDAAwD,CAAC;AAG1F;;;;;GAKG;AACH,qBAAa,wBAAwB;IACjC;;;;OAIG;IACH,OAAO,CAAC,KAAK,CAA0B;IAEvC,SAAS,eAAmB;IAE5B;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAIlD;IAED;;;;;;;;;OASG;IACH,SAAS,CAAC,aAAa,CAAC,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC;IACjD,SAAS,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAWvE"}
|
|
@@ -7,6 +7,13 @@ import { BehaviorLooTablesBuilder } from "./LootTablesBuilder";
|
|
|
7
7
|
* @author HaJuegos - 08-10-2026
|
|
8
8
|
*/
|
|
9
9
|
export declare class FinalLootTableBuilderTemplate extends BehaviorLooTablesBuilder {
|
|
10
|
+
/**
|
|
11
|
+
* Símbolo interno para marcar nodos a eliminar por completo.
|
|
12
|
+
* @type {symbol}
|
|
13
|
+
* @readonly
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
private readonly removedList;
|
|
10
17
|
/**
|
|
11
18
|
* Argumentos principales para la creacion de un Loot Table de una plantilla en concreto.
|
|
12
19
|
* @param {BPLootTableTemplateDef} def Los valores a definir fijos en el loot table.
|
|
@@ -16,6 +23,32 @@ export declare class FinalLootTableBuilderTemplate extends BehaviorLooTablesBuil
|
|
|
16
23
|
* @public
|
|
17
24
|
*/
|
|
18
25
|
constructor(def: BPLootTableTemplateDef<any>, over?: BPLootTableFinalOverDefinition);
|
|
26
|
+
/**
|
|
27
|
+
* Comprueba de forma recursiva si un nodo contiene, como subconjunto, todo lo indicado en la máscara. `true` solo exige que la clave exista.
|
|
28
|
+
* @param {unknown} node Nodo real a evaluar.
|
|
29
|
+
* @param {unknown} mask Máscara a comparar.
|
|
30
|
+
* @returns {boolean} Devuelve true si el nodo coincide con la máscara.
|
|
31
|
+
* @author HaJuegos - 27-10-2026
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
private matches;
|
|
35
|
+
/**
|
|
36
|
+
* Indica si una máscara contiene algo a eliminar (`true` o un array de selectores). Si no, solo funciona como selector.
|
|
37
|
+
* @param {unknown} mask Máscara a evaluar.
|
|
38
|
+
* @returns {boolean}
|
|
39
|
+
* @author HaJuegos - 27-10-2026
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
private hasRemoval;
|
|
43
|
+
/**
|
|
44
|
+
* Elimina de forma no mutante lo indicado en la máscara de un nodo.
|
|
45
|
+
* @param {unknown} node Nodo real de la plantilla base.
|
|
46
|
+
* @param {unknown} mask Máscara que describe lo que se elimina.
|
|
47
|
+
* @returns {unknown} Devuelve el nodo resultante o removedList si el nodo debe eliminarse por completo.
|
|
48
|
+
* @author HaJuegos - 27-10-2026
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
private prune;
|
|
19
52
|
/**
|
|
20
53
|
* Metodo principal final que convierte toda la plantilla definitiva en JSON en texto estructurado.
|
|
21
54
|
* @returns {string} Devuelve el JSON final en su estructura final.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LootTablesTemplateBuilder.d.ts","sourceRoot":"","sources":["../../../../src/builders/behaviors/lootTables/LootTablesTemplateBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,wDAAwD,CAAC;AAC3K,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAE/D;;;;;GAKG;AACH,qBAAa,6BAA8B,SAAQ,wBAAwB;IACvE;;;;;;;OAOG;IACH,YAAoB,GAAG,EAAE,sBAAsB,CAAC,GAAG,CAAC,EAAE,IAAI,GAAE,8BAAmC,
|
|
1
|
+
{"version":3,"file":"LootTablesTemplateBuilder.d.ts","sourceRoot":"","sources":["../../../../src/builders/behaviors/lootTables/LootTablesTemplateBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,wDAAwD,CAAC;AAC3K,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAE/D;;;;;GAKG;AACH,qBAAa,6BAA8B,SAAQ,wBAAwB;IACvE;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA6B;IAEzD;;;;;;;OAOG;IACH,YAAoB,GAAG,EAAE,sBAAsB,CAAC,GAAG,CAAC,EAAE,IAAI,GAAE,8BAAmC,EAkD9F;IAED;;;;;;;OAOG;IACH,OAAO,CAAC,OAAO;IAiBf;;;;;;OAMG;IACH,OAAO,CAAC,UAAU;IAQlB;;;;;;;OAOG;IACH,OAAO,CAAC,KAAK;IAsDb;;;;;OAKG;IACI,UAAU,IAAI,MAAM,CAE1B;CACJ;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC7B,KAAK,CAAC,KAAK,SAAS,SAAS,gBAAgB,EAAE,EACjD,GAAG,EAAE,sBAAsB,CAAC,KAAK,CAAC,IAE5B,KAAK,CAAC,QAAQ,SAAS,SAAS,gBAAgB,EAAE,GAAG,EAAE,SACnD,uBAAuB,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAQ,6BAA6B,CAGxF"}
|
package/dist/index.js
CHANGED
|
@@ -84235,9 +84235,6 @@ var BehaviorLooTablesBuilder = class {
|
|
|
84235
84235
|
return this;
|
|
84236
84236
|
}
|
|
84237
84237
|
convertToJSON(stringify) {
|
|
84238
|
-
if (!this.pools || this.pools.length <= 0) {
|
|
84239
|
-
throw new Error("[CATLOG] Error: No se han creado pools dentro de este loot table. Crea al menos un pool.");
|
|
84240
|
-
}
|
|
84241
84238
|
const preLootTable = {
|
|
84242
84239
|
pools: this.pools
|
|
84243
84240
|
};
|
|
@@ -84259,6 +84256,13 @@ var FinalLootTableBuilderTemplate = class extends BehaviorLooTablesBuilder {
|
|
|
84259
84256
|
*/
|
|
84260
84257
|
constructor(def, over = {}) {
|
|
84261
84258
|
super();
|
|
84259
|
+
/**
|
|
84260
|
+
* Símbolo interno para marcar nodos a eliminar por completo.
|
|
84261
|
+
* @type {symbol}
|
|
84262
|
+
* @readonly
|
|
84263
|
+
* @private
|
|
84264
|
+
*/
|
|
84265
|
+
this.removedList = /* @__PURE__ */ Symbol("removed");
|
|
84262
84266
|
let pools = [];
|
|
84263
84267
|
if (!over.clearAllData) {
|
|
84264
84268
|
pools = [...def.pools ?? []];
|
|
@@ -84270,12 +84274,112 @@ var FinalLootTableBuilderTemplate = class extends BehaviorLooTablesBuilder {
|
|
|
84270
84274
|
}
|
|
84271
84275
|
}
|
|
84272
84276
|
}
|
|
84277
|
+
const removed = /* @__PURE__ */ new Set();
|
|
84278
|
+
for (const [indexStr, mask] of Object.entries(over.remove?.pools ?? {})) {
|
|
84279
|
+
const index = Number(indexStr);
|
|
84280
|
+
if (!Number.isInteger(index) || !pools[index]) {
|
|
84281
|
+
throw new Error(`LootTable remove.pools: el pool "${indexStr}" no existe en la plantilla base.`);
|
|
84282
|
+
}
|
|
84283
|
+
let res = pools[index];
|
|
84284
|
+
if (this.hasRemoval(mask)) {
|
|
84285
|
+
res = this.prune(pools[index], mask);
|
|
84286
|
+
} else if (this.matches(pools[index], mask)) {
|
|
84287
|
+
res = this.removedList;
|
|
84288
|
+
}
|
|
84289
|
+
if (res === this.removedList || !res.entries?.length) {
|
|
84290
|
+
removed.add(index);
|
|
84291
|
+
} else {
|
|
84292
|
+
pools[index] = res;
|
|
84293
|
+
}
|
|
84294
|
+
}
|
|
84295
|
+
pools = pools.filter((_, i) => !removed.has(i));
|
|
84273
84296
|
}
|
|
84274
84297
|
if (over.add?.pools) {
|
|
84275
84298
|
pools.push(...over.add.pools);
|
|
84276
84299
|
}
|
|
84277
84300
|
this.setPools(pools);
|
|
84278
84301
|
}
|
|
84302
|
+
/**
|
|
84303
|
+
* Comprueba de forma recursiva si un nodo contiene, como subconjunto, todo lo indicado en la máscara. `true` solo exige que la clave exista.
|
|
84304
|
+
* @param {unknown} node Nodo real a evaluar.
|
|
84305
|
+
* @param {unknown} mask Máscara a comparar.
|
|
84306
|
+
* @returns {boolean} Devuelve true si el nodo coincide con la máscara.
|
|
84307
|
+
* @author HaJuegos - 27-10-2026
|
|
84308
|
+
* @private
|
|
84309
|
+
*/
|
|
84310
|
+
matches(node, mask) {
|
|
84311
|
+
if (mask === true) {
|
|
84312
|
+
return true;
|
|
84313
|
+
}
|
|
84314
|
+
if (Array.isArray(mask)) {
|
|
84315
|
+
return Array.isArray(node) && mask.every((m) => node.some((n) => this.matches(n, m)));
|
|
84316
|
+
}
|
|
84317
|
+
if (mask && typeof mask == "object") {
|
|
84318
|
+
return !!node && typeof node == "object" && !Array.isArray(node) && Object.entries(mask).every(([k, v]) => k in node && this.matches(node[k], v));
|
|
84319
|
+
}
|
|
84320
|
+
return node === mask;
|
|
84321
|
+
}
|
|
84322
|
+
/**
|
|
84323
|
+
* Indica si una máscara contiene algo a eliminar (`true` o un array de selectores). Si no, solo funciona como selector.
|
|
84324
|
+
* @param {unknown} mask Máscara a evaluar.
|
|
84325
|
+
* @returns {boolean}
|
|
84326
|
+
* @author HaJuegos - 27-10-2026
|
|
84327
|
+
* @private
|
|
84328
|
+
*/
|
|
84329
|
+
hasRemoval(mask) {
|
|
84330
|
+
if (mask === true || Array.isArray(mask)) {
|
|
84331
|
+
return true;
|
|
84332
|
+
}
|
|
84333
|
+
return !!mask && typeof mask == "object" && Object.values(mask).some((v) => this.hasRemoval(v));
|
|
84334
|
+
}
|
|
84335
|
+
/**
|
|
84336
|
+
* Elimina de forma no mutante lo indicado en la máscara de un nodo.
|
|
84337
|
+
* @param {unknown} node Nodo real de la plantilla base.
|
|
84338
|
+
* @param {unknown} mask Máscara que describe lo que se elimina.
|
|
84339
|
+
* @returns {unknown} Devuelve el nodo resultante o removedList si el nodo debe eliminarse por completo.
|
|
84340
|
+
* @author HaJuegos - 27-10-2026
|
|
84341
|
+
* @private
|
|
84342
|
+
*/
|
|
84343
|
+
prune(node, mask) {
|
|
84344
|
+
if (mask === true) {
|
|
84345
|
+
return this.removedList;
|
|
84346
|
+
}
|
|
84347
|
+
if (Array.isArray(node) && Array.isArray(mask)) {
|
|
84348
|
+
const out = [];
|
|
84349
|
+
for (const item of node) {
|
|
84350
|
+
let current = item;
|
|
84351
|
+
for (const m of mask) {
|
|
84352
|
+
if (current === this.removedList) {
|
|
84353
|
+
break;
|
|
84354
|
+
}
|
|
84355
|
+
if (!this.matches(current, m)) {
|
|
84356
|
+
continue;
|
|
84357
|
+
}
|
|
84358
|
+
current = this.hasRemoval(m) ? this.prune(current, m) : this.removedList;
|
|
84359
|
+
}
|
|
84360
|
+
if (current !== this.removedList) {
|
|
84361
|
+
out.push(current);
|
|
84362
|
+
}
|
|
84363
|
+
}
|
|
84364
|
+
return out.length ? out : this.removedList;
|
|
84365
|
+
}
|
|
84366
|
+
if (node && mask && typeof node == "object" && typeof mask == "object" && !Array.isArray(node) && !Array.isArray(mask)) {
|
|
84367
|
+
const out = { ...node };
|
|
84368
|
+
for (const [key, sub] of Object.entries(mask)) {
|
|
84369
|
+
if (!(key in out) || !this.hasRemoval(sub)) {
|
|
84370
|
+
continue;
|
|
84371
|
+
}
|
|
84372
|
+
const res = this.prune(out[key], sub);
|
|
84373
|
+
if (res === this.removedList) {
|
|
84374
|
+
delete out[key];
|
|
84375
|
+
} else {
|
|
84376
|
+
out[key] = res;
|
|
84377
|
+
}
|
|
84378
|
+
}
|
|
84379
|
+
return Object.keys(out).length ? out : this.removedList;
|
|
84380
|
+
}
|
|
84381
|
+
return node;
|
|
84382
|
+
}
|
|
84279
84383
|
/**
|
|
84280
84384
|
* Metodo principal final que convierte toda la plantilla definitiva en JSON en texto estructurado.
|
|
84281
84385
|
* @returns {string} Devuelve el JSON final en su estructura final.
|