@ianlucas/cs2-lib-inspect 2.0.0-rc.1 → 2.0.0-rc.2

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/index.d.ts CHANGED
@@ -1,3 +1,14 @@
1
- import { CS2EconomyItem, CS2InventoryItem } from "@ianlucas/cs2-lib";
1
+ import { CS2EconomyItem, CS2InventoryItem, CS2ItemTypeValues } from "@ianlucas/cs2-lib";
2
+ export declare const CS2PreviewRarity: {
3
+ "#b0c3d9": number;
4
+ "#5e98d9": number;
5
+ "#4b69ff": number;
6
+ "#8847ff": number;
7
+ "#d32ce6": number;
8
+ "#eb4b4b": number;
9
+ "#e4ae39": number;
10
+ };
11
+ export declare const CS2_PREVIEW_HAS_STICKERS: CS2ItemTypeValues[];
12
+ export declare const CS2_PREVIEW_INSPECTABLE_ITEMS: CS2ItemTypeValues[];
2
13
  export declare const CS2_PREVIEW_URL = "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20";
3
14
  export declare function generateInspectLink(item: CS2EconomyItem | CS2InventoryItem): string;
package/dist/index.js CHANGED
@@ -2,11 +2,11 @@
2
2
  * Copyright (c) candyboyz, Ian Lucas. All rights reserved.
3
3
  * Licensed under the MIT License. See License.txt in the project root for license information.
4
4
  *--------------------------------------------------------------------------------------------*/
5
- import { CS2InventoryItem, CS2RarityColor, CS2_MIN_SEED, CS2_MIN_STICKER_WEAR, CS2_MIN_WEAR } from "@ianlucas/cs2-lib";
5
+ import { CS2InventoryItem, CS2ItemType, CS2RarityColor, CS2_MIN_SEED, CS2_MIN_STICKER_WEAR } from "@ianlucas/cs2-lib";
6
6
  import { Buffer } from "buffer";
7
7
  import CRC32 from "crc-32";
8
8
  import { CEconItemPreviewDataBlock } from "./econ-item-preview-data-block.js";
9
- const CS2_RARITY_INT = {
9
+ export const CS2PreviewRarity = {
10
10
  [CS2RarityColor.Common]: 1,
11
11
  [CS2RarityColor.Uncommon]: 2,
12
12
  [CS2RarityColor.Rare]: 3,
@@ -15,12 +15,24 @@ const CS2_RARITY_INT = {
15
15
  [CS2RarityColor.Ancient]: 6,
16
16
  [CS2RarityColor.Immortal]: 7
17
17
  };
18
- const MISSING_ITEM_DEF = {
19
- graffiti: 1348,
20
- patch: 4609,
21
- sticker: 1209,
22
- musickit: 1314
23
- };
18
+ export const CS2_PREVIEW_HAS_STICKERS = [
19
+ CS2ItemType.Graffiti,
20
+ CS2ItemType.Patch,
21
+ CS2ItemType.Sticker,
22
+ CS2ItemType.MusicKit
23
+ ];
24
+ export const CS2_PREVIEW_INSPECTABLE_ITEMS = [
25
+ CS2ItemType.Agent,
26
+ CS2ItemType.Container,
27
+ CS2ItemType.Collectible,
28
+ CS2ItemType.Gloves,
29
+ CS2ItemType.Graffiti,
30
+ CS2ItemType.Melee,
31
+ CS2ItemType.MusicKit,
32
+ CS2ItemType.Patch,
33
+ CS2ItemType.Sticker,
34
+ CS2ItemType.Weapon
35
+ ];
24
36
  export const CS2_PREVIEW_URL = "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20";
25
37
  function floatToBytes(floatValue) {
26
38
  const floatArray = new Float32Array(1);
@@ -29,17 +41,17 @@ function floatToBytes(floatValue) {
29
41
  return byteArray[0];
30
42
  }
31
43
  function getEconomyItemPreviewData(item) {
32
- const { def, index, rarity, type, tint, wearMin } = item;
33
- const hasStickerObject = MISSING_ITEM_DEF[type] !== undefined;
34
- const hasPaintIndex = !hasStickerObject && type !== "musickit";
44
+ const { def, index, rarity, type, tint } = item;
45
+ const hasStickers = CS2_PREVIEW_HAS_STICKERS.includes(type);
46
+ const hasPaintIndex = !hasStickers && !item.isMusicKit();
35
47
  return {
36
- defindex: MISSING_ITEM_DEF[type] ?? def,
37
- musicindex: type === "musickit" ? index : undefined,
48
+ defindex: def,
49
+ musicindex: item.isMusicKit() ? index : undefined,
38
50
  paintindex: hasPaintIndex ? index : undefined,
39
51
  paintseed: item.hasSeed() ? CS2_MIN_SEED : undefined,
40
- paintwear: item.hasWear() ? wearMin ?? CS2_MIN_WEAR : undefined,
41
- rarity: CS2_RARITY_INT[rarity] ?? 0,
42
- stickers: hasStickerObject
52
+ paintwear: item.hasWear() ? item.getMinimumWear() : undefined,
53
+ rarity: CS2PreviewRarity[rarity] ?? 0,
54
+ stickers: hasStickers
43
55
  ? [
44
56
  {
45
57
  tintId: tint,
@@ -51,7 +63,7 @@ function getEconomyItemPreviewData(item) {
51
63
  };
52
64
  }
53
65
  function getInventoryItemPreviewData(item) {
54
- const { nameTag, seed, statTrak, stickers, wear } = item;
66
+ const { nameTag, seed, statTrak, stickers } = item;
55
67
  const baseAttributes = getEconomyItemPreviewData(item);
56
68
  return {
57
69
  ...baseAttributes,
@@ -59,7 +71,7 @@ function getInventoryItemPreviewData(item) {
59
71
  killeaterscoretype: statTrak !== undefined ? 0 : undefined,
60
72
  killeatervalue: statTrak,
61
73
  paintseed: item.hasSeed() ? seed ?? CS2_MIN_SEED : undefined,
62
- paintwear: item.hasWear() ? floatToBytes(wear ?? item.wearMin ?? CS2_MIN_WEAR) : undefined,
74
+ paintwear: item.hasWear() ? floatToBytes(item.getWear()) : undefined,
63
75
  stickers: stickers !== undefined
64
76
  ? item.someStickers().map(([slot, { id, wear }]) => ({
65
77
  slot,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ianlucas/cs2-lib-inspect",
3
- "version": "2.0.0-rc.1",
3
+ "version": "2.0.0-rc.2",
4
4
  "description": "A utility for creating inspect links for CS2 items",
5
5
  "license": "MIT",
6
6
  "repository": "ianlucas/cs2-lib-inspect",
@@ -18,7 +18,7 @@
18
18
  "crc-32": "^1.2.2"
19
19
  },
20
20
  "peerDependencies": {
21
- "@ianlucas/cs2-lib": "^5.0.0-rc.7"
21
+ "@ianlucas/cs2-lib": "^5.0.0-rc.19"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@protobuf-ts/plugin": "^2.9.3",