@ianlucas/cs2-lib 5.0.0-rc.21 → 5.0.0-rc.22

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/economy.js CHANGED
@@ -243,7 +243,11 @@ export class CS2EconomyItem {
243
243
  return ensure(this._contents).map((id) => this.economy.get(id));
244
244
  }
245
245
  get parent() {
246
- return this.baseId !== undefined ? this.economy.get(this.baseId) : undefined;
246
+ return this.baseId !== undefined
247
+ ? this.economy.items.has(this.baseId)
248
+ ? this.economy.get(this.baseId)
249
+ : undefined
250
+ : undefined;
247
251
  }
248
252
  get rawContents() {
249
253
  return this._contents;
@@ -45,6 +45,7 @@ export declare class CS2Inventory {
45
45
  readonly options: Readonly<CS2InventoryOptions>;
46
46
  static parse(stringValue: string | undefined | null, economy?: CS2EconomyInstance): CS2InventoryData | undefined;
47
47
  constructor({ economy, data, maxItems, storageUnitMaxItems }?: Partial<CS2InventorySpec>);
48
+ private validateAddable;
48
49
  private validateStickers;
49
50
  private validatePatches;
50
51
  validateBaseInventoryItem({ id, nameTag, patches, seed, statTrak, stickers, wear }: CS2BaseInventoryItem): void;
package/dist/inventory.js CHANGED
@@ -39,6 +39,11 @@ export class CS2Inventory {
39
39
  storageUnitMaxItems: storageUnitMaxItems ?? 32
40
40
  };
41
41
  }
42
+ validateAddable(item) {
43
+ if (item.isGloves()) {
44
+ assert(item.free || !item.base);
45
+ }
46
+ }
42
47
  validateStickers(stickers, item) {
43
48
  if (stickers === undefined) {
44
49
  return;
@@ -74,11 +79,14 @@ export class CS2Inventory {
74
79
  this.economy.validateSeed(seed, item);
75
80
  this.economy.validateNametag(nameTag, item);
76
81
  this.economy.validateStatTrak(statTrak, item);
82
+ this.validateAddable(item);
77
83
  this.validatePatches(patches, item);
78
84
  this.validateStickers(stickers, item);
79
85
  }
80
86
  toInventoryItems(items) {
81
- return new Map(Object.entries(items).map(([key, value]) => {
87
+ return new Map(Object.entries(items)
88
+ .filter(([, { id }]) => this.economy.items.has(id))
89
+ .map(([key, value]) => {
82
90
  const uid = parseInt(key, 10);
83
91
  return [uid, new CS2InventoryItem(this, uid, value, this.economy.getById(value.id))];
84
92
  }));
@@ -393,18 +401,24 @@ export class CS2InventoryItem extends CS2EconomyItem {
393
401
  wear;
394
402
  assign({ patches, stickers, storage }) {
395
403
  if (patches !== undefined) {
396
- this.patches = new Map(Object.entries(patches).map(([key, value]) => [parseInt(key, 10), value]));
404
+ this.patches = new Map(Object.entries(patches)
405
+ .filter(([, patchId]) => this.economy.items.has(patchId))
406
+ .map(([slot, patchId]) => [parseInt(slot, 10), patchId]));
397
407
  }
398
408
  if (stickers !== undefined) {
399
- this.stickers = new Map(Object.entries(stickers).map(([key, value]) => [parseInt(key, 10), value]));
409
+ this.stickers = new Map(Object.entries(stickers)
410
+ .filter(([, sticker]) => this.economy.items.has(sticker.id))
411
+ .map(([slot, sticker]) => [parseInt(slot, 10), sticker]));
400
412
  }
401
413
  if (storage !== undefined) {
402
414
  assert(this.isStorageUnit());
403
- this.storage = new Map(Object.entries(storage).map(([key, value]) => {
404
- const storedEconomyItem = this.economy.getById(value.id);
415
+ this.storage = new Map(Object.entries(storage)
416
+ .filter(([, { id }]) => this.economy.items.has(id))
417
+ .map(([key, value]) => {
418
+ const economyItem = this.economy.getById(value.id);
405
419
  assert(value.storage === undefined);
406
420
  const uid = parseInt(key, 10);
407
- return [uid, new CS2InventoryItem(this.inventory, uid, value, storedEconomyItem)];
421
+ return [uid, new CS2InventoryItem(this.inventory, uid, value, economyItem)];
408
422
  }));
409
423
  }
410
424
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ianlucas/cs2-lib",
3
- "version": "5.0.0-rc.21",
3
+ "version": "5.0.0-rc.22",
4
4
  "description": "A TypeScript library for manipulating Counter-Strike 2 data",
5
5
  "license": "MIT",
6
6
  "author": "Ian Lucas",