@tf2-automatic/tf2-format 8.0.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.
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SKU = void 0;
4
+ class SKU {
5
+ static fromObject(item) {
6
+ let sku = `${item.defindex};${item.quality}`;
7
+ if (item.effect) {
8
+ sku += `;u${item.effect}`;
9
+ }
10
+ if (item.australium === true) {
11
+ sku += ';australium';
12
+ }
13
+ if (item.craftable === false) {
14
+ sku += ';uncraftable';
15
+ }
16
+ if (item.tradable === false) {
17
+ sku += ';untradable';
18
+ }
19
+ if (item.wear) {
20
+ sku += `;w${item.wear}`;
21
+ }
22
+ if (item.paintkit) {
23
+ sku += `;pk${item.paintkit}`;
24
+ }
25
+ if (item.elevated === true) {
26
+ sku += ';strange';
27
+ }
28
+ if (item.killstreak !== undefined && item.killstreak !== 0) {
29
+ sku += `;kt-${item.killstreak}`;
30
+ }
31
+ if (item.target) {
32
+ sku += `;td-${item.target}`;
33
+ }
34
+ if (item.festivized === true) {
35
+ sku += ';festive';
36
+ }
37
+ if (item.crateSeries) {
38
+ sku += `;c${item.crateSeries}`;
39
+ }
40
+ if (item.output) {
41
+ sku += `;od-${item.output}`;
42
+ }
43
+ if (item.outputQuality) {
44
+ sku += `;oq-${item.outputQuality}`;
45
+ }
46
+ return sku;
47
+ }
48
+ static fromString(sku) {
49
+ const item = {
50
+ defindex: -1,
51
+ quality: -1,
52
+ craftable: true,
53
+ tradable: true,
54
+ australium: false,
55
+ festivized: false,
56
+ effect: null,
57
+ elevated: false,
58
+ killstreak: 0,
59
+ paintkit: null,
60
+ wear: null,
61
+ output: null,
62
+ outputQuality: null,
63
+ target: null,
64
+ crateSeries: null,
65
+ };
66
+ const length = sku.length;
67
+ let start = 0;
68
+ let numValue = 0;
69
+ // Extract only defindex and quality
70
+ for (let i = 0; i < length; i++) {
71
+ const charCode = sku.charCodeAt(i);
72
+ if (charCode <= 57) {
73
+ // We know that defindex and quality should only be numbers, so we
74
+ // just assume that it is the character '0' to '9'.
75
+ numValue = numValue * 10 + (charCode - 48);
76
+ }
77
+ else if (charCode === 59) {
78
+ // Found the seperator ';' ASCII 59
79
+ if (start === 0) {
80
+ // First time we found the seperator, so this is the defindex
81
+ item.defindex = numValue;
82
+ // Reset numValue for the next part
83
+ numValue = 0;
84
+ // Update the start defindex for the next part
85
+ start = i + 1;
86
+ }
87
+ else if (start !== 0) {
88
+ // Second time we found the seperator, so this is the quality
89
+ start = i + 1;
90
+ break;
91
+ }
92
+ }
93
+ }
94
+ // We have to set the quality outside of the loop because there may not be a second seperator
95
+ item.quality = numValue;
96
+ // Now process remaining attributes
97
+ while (start < length) {
98
+ let separatorIndex = length;
99
+ let numIndex = undefined;
100
+ let numValue = 0;
101
+ // Loop through the remaining part of the SKU
102
+ for (let i = start; i < length; i++) {
103
+ if (sku.charAt(i) === ';') {
104
+ // Found seperator, break the loop to process the attribute
105
+ separatorIndex = i;
106
+ break;
107
+ }
108
+ else {
109
+ // Check if the character is less than 57 (ASCII for '9')
110
+ const charCode = sku.charCodeAt(i);
111
+ if (charCode <= 57) {
112
+ // The character should be either a number or a hyphen (but we don't
113
+ // care about validating it)
114
+ if (numIndex === undefined) {
115
+ // Set the index, everything after should be a number
116
+ numIndex = i;
117
+ }
118
+ // Check if the character is a number
119
+ if (charCode >= 48) {
120
+ // It is a number, accumulate the numeric value
121
+ numValue = numValue * 10 + (charCode - 48);
122
+ }
123
+ }
124
+ }
125
+ }
126
+ const partLength = (numIndex || separatorIndex) - start;
127
+ // Handle without numeric values first
128
+ switch (partLength) {
129
+ case 11:
130
+ item.craftable = false;
131
+ break;
132
+ case 10:
133
+ if (sku.charAt(start) === 'a') {
134
+ item.australium = true;
135
+ }
136
+ else {
137
+ item.tradable = false;
138
+ }
139
+ break;
140
+ case 7:
141
+ if (sku.charAt(start) === 's') {
142
+ item.elevated = true;
143
+ }
144
+ else {
145
+ item.festivized = true;
146
+ }
147
+ break;
148
+ default: {
149
+ // Handle prefixes
150
+ const prefix = sku.charAt(start);
151
+ switch (prefix) {
152
+ case 'u':
153
+ item.effect = numValue;
154
+ break;
155
+ case 'w':
156
+ item.wear = numValue;
157
+ break;
158
+ case 'p':
159
+ item.paintkit = numValue;
160
+ break;
161
+ case 'k':
162
+ item.killstreak = numValue;
163
+ break;
164
+ case 't':
165
+ item.target = numValue;
166
+ break;
167
+ case 'c':
168
+ item.crateSeries = numValue;
169
+ break;
170
+ case 'o':
171
+ if (sku.charAt(start + 1) === 'd') {
172
+ item.output = numValue;
173
+ }
174
+ else if (sku.charAt(start + 1) === 'q') {
175
+ item.outputQuality = numValue;
176
+ }
177
+ break;
178
+ }
179
+ }
180
+ }
181
+ start = separatorIndex + 1;
182
+ }
183
+ return item;
184
+ }
185
+ }
186
+ exports.SKU = SKU;
187
+ //# sourceMappingURL=sku.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sku.js","sourceRoot":"","sources":["../../../../../../libs/tf2-format/src/lib/sku/sku.ts"],"names":[],"mappings":";;;AAEA,MAAa,GAAG;IACd,MAAM,CAAC,UAAU,CAAC,IAA4B;QAC5C,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAE7C,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,GAAG,IAAI,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;QAC5B,CAAC;QACD,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YAC7B,GAAG,IAAI,aAAa,CAAC;QACvB,CAAC;QACD,IAAI,IAAI,CAAC,SAAS,KAAK,KAAK,EAAE,CAAC;YAC7B,GAAG,IAAI,cAAc,CAAC;QACxB,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;YAC5B,GAAG,IAAI,aAAa,CAAC;QACvB,CAA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BACH,CAAC;YACH,CAAC;YAED,KAAK,GAAG,cAAc,GAAG,CAAC,CAAC;QAC7B,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA5LD,kBA4LC"}
@@ -0,0 +1,313 @@
1
+ /**
2
+ * A common representation of a TF2 item.
3
+ */
4
+ export type Item = PrimaryItemAttributes & ExtraItemAttributes;
5
+ /**
6
+ * A TF2 item from an inventory.
7
+ */
8
+ export interface InventoryItem extends Item {
9
+ assetid: string;
10
+ }
11
+ /**
12
+ * The primary attributes of a TF2 item that are used to identify it.
13
+ */
14
+ export interface PrimaryItemAttributes {
15
+ defindex: number;
16
+ quality: number;
17
+ craftable: boolean;
18
+ tradable: boolean;
19
+ australium: boolean;
20
+ festivized: boolean;
21
+ killstreak: number;
22
+ effect: number | null;
23
+ paintkit: number | null;
24
+ wear: number | null;
25
+ target: number | null;
26
+ output: number | null;
27
+ outputQuality: number | null;
28
+ elevated: boolean;
29
+ crateSeries: number | null;
30
+ }
31
+ export interface RecipeInput {
32
+ defindex?: number;
33
+ killstreak?: number;
34
+ quality: number;
35
+ amount: number;
36
+ }
37
+ /**
38
+ * Extra attributes of a TF2 item.
39
+ */
40
+ export interface ExtraItemAttributes {
41
+ paint: number | null;
42
+ spells: number[];
43
+ parts: number[];
44
+ sheen: string | null;
45
+ killstreaker: string | null;
46
+ inputs: RecipeInput[] | null;
47
+ }
48
+ type RequiredKeys<T extends keyof U, U> = {
49
+ [K in T]-?: K extends keyof U ? U[K] : never;
50
+ } & {
51
+ [K in Exclude<keyof U, T>]?: U[K];
52
+ };
53
+ export type RequiredItemAttributes = RequiredKeys<'defindex' | 'quality', PrimaryItemAttributes>;
54
+ export interface ItemsGameItem {
55
+ name: string;
56
+ capabilities?: Record<string, '0' | '1'>;
57
+ static_attrs?: Record<string, string>;
58
+ attributes?: Record<string, {
59
+ attribute_class: string;
60
+ value: string;
61
+ }>;
62
+ }
63
+ interface GetItem {
64
+ /**
65
+ * Synchronously get an item by its defindex from items_game.txt.
66
+ * @param defindex The defindex of the item.
67
+ * @returns Returns the matching item from items_game.txt, undefined if it
68
+ * is not possible to get the item synchronously or an error to exit early.
69
+ * @example schema.getItemByDefindex(5021) -> { name: "Decoder Ring", ... }
70
+ * @example schema.getItemByDefindex(-1) -> undefined
71
+ * @example schema.getItemByDefindex(-1) -> new Error("Item not found")
72
+ */
73
+ getItemByDefindex(defindex: number): ItemsGameItem | undefined | Error;
74
+ /**
75
+ * Asynchronously get an item by its defindex from items_game.txt.
76
+ * @param defindex The defindex of the item.
77
+ * @returns Returns the matching item from items_game.txt or throws an error
78
+ * if it was not found.
79
+ * @example schema.fetchItemByDefindex(5021) -> Promise.resolve({ name: "Decoder Ring", ... })
80
+ * @example schema.fetchItemByDefindex(-1) -> Promise.reject(new Error("Item not found"))
81
+ */
82
+ fetchItemByDefindex(defindex: number): Promise<ItemsGameItem>;
83
+ }
84
+ /**
85
+ * Various information needs to be retrieved externally to format the Econ items.
86
+ * This schema is used to define the getters for this information.
87
+ */
88
+ export interface EconParserSchema extends GetItem {
89
+ /**
90
+ * Syncronously get the defindex of an item by its `item_name` using the
91
+ * GetSchemaItems API.
92
+ * @param name The name of the item.
93
+ * @returns Returns the defindex of the item, null if an item with the given
94
+ * name is known not to exist or undefined if it could not be found syncronously.
95
+ * @example schema.getDefindexByName("Mann Co. Supply Crate Key") -> 5021
96
+ * @example schema.getDefindexByName("Mann Co. Supply Crate Key") -> undefined
97
+ * @example schema.getDefindexByName("Non-existent item") -> null
98
+ */
99
+ getDefindexByName(name: string): number | null | undefined;
100
+ /**
101
+ * Asyncronously get the defindex of an item by its `item_name` using
102
+ * the GetSchemaItems API.
103
+ * @param name The name of the item.
104
+ * @returns Returns the defindex of the item or null if an item with the given
105
+ * name does not exist.
106
+ * @example schema.fetchDefindexByName("Mann Co. Supply Crate Key") -> Promise.resolve(5021)
107
+ * @example schema.fetchDefindexByName("Non-existent item") -> Promise.resolve(null)
108
+ */
109
+ fetchDefindexByName(name: string): Promise<number | null>;
110
+ /**
111
+ * Synchronously get the id of a quality by its name.
112
+ * @param name The name of the quality.
113
+ * @returns Returns the id of the quality, undefined if the quality cannot be
114
+ * found syncronously or an error to exit early.
115
+ * @example schema.getQualityByName("Unique") -> 6
116
+ * @example schema.getQualityByName("Non-existent quality") -> undefined
117
+ * @example schema.getQualityByName("Non-existent quality") -> new Error("Quality not found")
118
+ */
119
+ getQualityByName(name: string): number | undefined | Error;
120
+ /**
121
+ * Asynchronously get the id of a quality by its name.
122
+ * @param name The name of the quality.
123
+ * @returns Returns the id of the quality or throws an error if the quality
124
+ * cannot be found.
125
+ * @example schema.fetchQualityByName("Unique") -> Promise.resolve(6)
126
+ * @example schema.fetchQualityByName("Non-existent quality") -> Promise.reject(new Error("Quality not found"))
127
+ */
128
+ fetchQualityByName(name: string): Promise<number>;
129
+ /**
130
+ * Synchronously get the id of an effect by its name.
131
+ * @param name The name of the effect.
132
+ * @returns Returns the id of the effect, undefined if the effect cannot be
133
+ * found synchronously or an error to exit early.
134
+ * @example schema.getEffectByName("Burning Flames") -> 13
135
+ * @example schema.getEffectByName("Non-existent effect") -> undefined
136
+ * @example schema.getEffectByName("Non-existent effect") -> new Error("Effect not found")
137
+ */
138
+ getEffectByName(name: string): number | undefined | Error;
139
+ /**
140
+ * Asynchronously get the id of an effect by its name.
141
+ * @param name The name of the effect.
142
+ * @returns Returns the id of the effect or throws an error if the effect
143
+ * cannot be found.
144
+ * @example schema.fetchEffectByName("Burning Flames") -> Promise.resolve(13)
145
+ * @example schema.fetchEffectByName("Non-existent effect") -> Promise.reject(new Error("Effect not found"))
146
+ */
147
+ fetchEffectByName(name: string): Promise<number>;
148
+ /**
149
+ * Synchronously get the id of a texture by its name.
150
+ * @param name The name of the texture.
151
+ * @returns Returns the id of the texture, undefined if the texture cannot be
152
+ * found synchronously or an error to exit early.
153
+ * @example schema.getTextureByName("Night Owl") -> 14
154
+ * @example schema.getTextureByName("Non-existent texture") -> undefined
155
+ * @example schema.getTextureByName("Non-existent texture") -> new Error("Texture not found")
156
+ */
157
+ getTextureByName(name: string): number | undefined | Error;
158
+ /**
159
+ * Asynchronously get the id of a texture by its name.
160
+ * @param name The name of the texture.
161
+ * @returns Returns the id of the texture or throws an error if the texture
162
+ * cannot be found.
163
+ * @example schema.fetchTextureByName("Night Owl") -> Promise.resolve(14)
164
+ * @example schema.fetchTextureByName("Non-existent texture") -> Promise.reject(new Error("Texture not found"))
165
+ */
166
+ fetchTextureByName(name: string): Promise<number>;
167
+ /**
168
+ * Syncronously get the id of a spell by its name.
169
+ * @param name The name of the spell.
170
+ * @returns Returns the id of the spell, undefined if the spell cannot be
171
+ * found syncronously or an error to exit early.
172
+ * @example schema.getSpellByName("Exorcism") -> 1009
173
+ * @example schema.getSpellByName("Non-existent spell") -> undefined
174
+ * @example schema.getSpellByName("Non-existent spell") -> new Error("Spell not found")
175
+ */
176
+ getSpellByName(name: string): number | undefined | Error;
177
+ /**
178
+ * Asynchronously get the id of a spell by its name.
179
+ * @param name The name of the spell.
180
+ * @returns Returns the id of the spell or throws an error if the spell
181
+ * cannot be found.
182
+ * @example schema.fetchSpellByName("Exorcism") -> Promise.resolve(1009)
183
+ * @example schema.fetchSpellByName("Non-existent spell") -> Promise.reject(new Error("Spell not found"))
184
+ */
185
+ fetchSpellByName(name: string): Promise<number>;
186
+ /**
187
+ * Syncronously get the defindex of a strange part by its score type. Because
188
+ * some score types may not have a corresponding strange part, e.g. "Kills", then
189
+ * this method has to return null when no match instead of throwing an error.
190
+ * @param scoreType The score type.
191
+ * @returns Returns the id of the strange part, null if a strange part with the
192
+ * given score type does not exist or undefined if it could not be found syncronously.
193
+ * @example schema.getStrangePartByScoreType("Kills Under A Full Moon") -> 6015
194
+ * @example schema.getStrangePartByScoreType("Kills Under A Full Moon") -> undefined
195
+ * @example schema.getStrangePartByScoreType("Non-existent score type") -> null
196
+ */
197
+ getStrangePartByScoreType(scoreType: string): number | null | undefined;
198
+ /**
199
+ * Asynchronously get the defindex of a strange part by its score type. Because
200
+ * some score types may not have a corresponding strange part, e.g. "Kills", then
201
+ * this method has to return null when no match instead of throwing an error.
202
+ * @param scoreType The score type.
203
+ * @returns Returns the id of the strange part or null if a strange part with
204
+ * the given score type does not exist.
205
+ * @example schema.fetchStrangePartByScoreType("Kills Under A Full Moon") -> Promise.resolve(6015)
206
+ * @example schema.fetchStrangePartByScoreType("Non-existent score type") -> Promise.resolve(null)
207
+ */
208
+ fetchStrangePartByScoreType(scoreType: string): Promise<number | null>;
209
+ }
210
+ /**
211
+ * Various information needs to be retrieved externally to format the TF2 items.
212
+ * This schema is used to define the getters for this information.
213
+ */
214
+ export interface TF2ParserSchema extends GetItem {
215
+ /**
216
+ * Syncronously get the name of a sheen by its id.
217
+ * @param id The id of the sheen.
218
+ * @returns Returns the name of the sheen, undefined if the sheen cannot be
219
+ * found syncronously or an error to exit early.
220
+ * @example schema.getSheenById(6) -> "Villainous Violet"
221
+ * @example schema.getSheenById(6) -> undefined
222
+ * @example schema.getSheenById(-1) -> new Error("Sheen not found")
223
+ */
224
+ getSheenById(id: number): string | undefined | Error;
225
+ /**
226
+ * Asynchronously get the name of a sheen by its id.
227
+ * @param id The id of the sheen.
228
+ * @returns Returns the name of the sheen or throws an error if the sheen
229
+ * cannot be found.
230
+ * @example schema.fetchSheenById(6) -> Promise.resolve("Villainous Violet")
231
+ * @example schema.fetchSheenById(-1) -> Promise.reject(new Error("Sheen not found"))
232
+ */
233
+ fetchSheenById(id: number): Promise<string>;
234
+ /**
235
+ * Syncronously get the name of a killstreaker by its id.
236
+ * @param id The id of the killstreaker.
237
+ * @returns Returns the name of the killstreaker, undefined if the killstreaker
238
+ * cannot be found syncronously or an error to exit early.
239
+ * @example schema.getKillstreakerById(2003) -> "Cerebral Discharge"
240
+ * @example schema.getKillstreakerById(2003) -> undefined
241
+ * @example schema.getKillstreakerById(-1) -> new Error("Killstreaker not found")
242
+ */
243
+ getKillstreakerById(id: number): string | undefined | Error;
244
+ /**
245
+ * Asynchronously get the name of a killstreaker by its id.
246
+ * @param id The id of the killstreaker.
247
+ * @returns Returns the name of the killstreaker or throws an error if the
248
+ * killstreaker cannot be found.
249
+ * @example schema.fetchKillstreakerById(2003) -> Promise.resolve("Cerebral Discharge")
250
+ * @example schema.fetchKillstreakerById(-1) -> Promise.reject(new Error("Killstreaker not found"))
251
+ */
252
+ fetchKillstreakerById(id: number): Promise<string>;
253
+ /**
254
+ * Syncronously get the defindex of a spell by the attribute defindex and value.
255
+ * @param defindex The defindex of the spell attribute.
256
+ * @param id The value of the spell attribute.
257
+ * @returns Returns the defindex of the spell, undefined if the spell cannot
258
+ * be found syncronously or an error to exit early.
259
+ * @example schema.getSpellById(1004, 1) -> 8902
260
+ * @example schema.getSpellById(1004, 1) -> undefined
261
+ * @example schema.getSpellById(-1, -1) -> new Error("Spell not found")
262
+ */
263
+ getSpellById(defindex: number, id: number): number | undefined | Error;
264
+ /**
265
+ * Asynchronously get the defindex of a spell by the attribute defindex and value.
266
+ * @param defindex The defindex of the spell attribute.
267
+ * @param id The value of the spell attribute.
268
+ * @returns Returns the defindex of the spell or throws an error if the spell
269
+ * cannot be found.
270
+ * @example schema.fetchSpellById(1004, 1) -> Promise.resolve(8902)
271
+ * @example schema.fetchSpellById(1004, 1) -> Promise.reject(new Error("Spell not found"))
272
+ */
273
+ fetchSpellById(defindex: number, id: number): Promise<number>;
274
+ /**
275
+ * Syncronously get the defindex of a paint by its hex color code.
276
+ * @param color The hex color code of the paint.
277
+ * @returns Returns the defindex of the paint, undefined if the paint cannot
278
+ * be found syncronously or an error to exit early.
279
+ * @example schema.getPaintByColor("e7b53b") -> 5037
280
+ * @example schema.getPaintByColor("e7b53b") -> undefined
281
+ * @example schema.getPaintByColor("") -> new Error("Paint not found")
282
+ */
283
+ getPaintByColor(color: string): number | undefined | Error;
284
+ /**
285
+ * Asynchronously get the defindex of a paint by its hex color code.
286
+ * @param color The hex color code of the paint.
287
+ * @returns Returns the defindex of the paint or throws an error if the paint
288
+ * cannot be found.
289
+ * @example schema.fetchPaintByColor("e7b53b") -> Promise.resolve(5037)
290
+ * @example schema.fetchPaintByColor("e7b53b") -> Promise.reject(new Error("Paint not found"))
291
+ */
292
+ fetchPaintByColor(color: string): Promise<number>;
293
+ /**
294
+ * Syncronously get the defindex of a strange part by its id.
295
+ * @param id The id of the strange part.
296
+ * @returns Returns the defindex of the strange part, undefined if the strange
297
+ * part cannot be found syncronously or an error to exit early.
298
+ * @example schema.getStrangePartById(27) -> 6015
299
+ * @example schema.getStrangePartById(27) -> undefined
300
+ * @example schema.getStrangePartById(-1) -> new Error("Strange part not found")
301
+ */
302
+ getStrangePartById(id: number): number | undefined | Error;
303
+ /**
304
+ * Asynchronously get the defindex of a strange part by its id.
305
+ * @param id The id of the strange part.
306
+ * @returns Returns the defindex of the strange part or throws an error if the
307
+ * strange part cannot be found.
308
+ * @example schema.fetchStrangePartById(27) -> Promise.resolve(6015)
309
+ * @example schema.fetchStrangePartById(-1) -> Promise.reject(new Error("Strange part not found"))
310
+ */
311
+ fetchStrangePartById(id: number): Promise<number>;
312
+ }
313
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../libs/tf2-format/src/lib/types.ts"],"names":[],"mappings":""}