@juice789/tf2items 1.0.31 → 1.0.32

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/fromEconItem.js CHANGED
@@ -40,13 +40,16 @@ const {
40
40
  isEmpty,
41
41
  join,
42
42
  filter,
43
- omit
43
+ omit,
44
+ last,
45
+ defaultTo
44
46
  } = require('ramda')
45
47
 
46
48
  const { safeItems: items } = require('./schemaItems.js')
47
49
  const { particleEffects, textures } = require('./schema.json')
48
50
  const { qualityNames, wears, paintDefindex, spellDefindex } = require('./schemaHelper.json')
49
51
  const { skuFromItem } = require('./sku.js')
52
+ const { skuFromItem753 } = require('./sku753.js')
50
53
  const { renameKeys } = require('ramda-adjunct')
51
54
 
52
55
  const marketHashIncludes = curry((string, { market_hash_name }) => market_hash_name.indexOf(string) !== -1)
@@ -57,8 +60,8 @@ const removeStrings = curry((string, strings) => compose(
57
60
  reduce((all, curr) => replace(curr, '', all), string || '')
58
61
  )(strings))
59
62
 
60
- const findTag = uncurryN(2, (tagName) => compose(
61
- prop('name'),
63
+ const findTag = uncurryN(3, (tagName, displayProp) => compose(
64
+ prop(displayProp),
62
65
  find(propEq(tagName, 'category_name')),
63
66
  map(renameKeys({
64
67
  localized_category_name: 'category_name',
@@ -69,7 +72,11 @@ const findTag = uncurryN(2, (tagName) => compose(
69
72
 
70
73
  const old_id = ({ new_assetid, rollback_new_assetid, assetid }) => (new_assetid || rollback_new_assetid) ? assetid : null
71
74
 
72
- const id = ({ new_assetid, rollback_new_assetid, assetid }) => new_assetid || rollback_new_assetid || assetid
75
+ const id = ({ new_assetid, rollback_new_assetid, assetid }) => new_assetid || rollback_new_assetid || assetid || null
76
+
77
+ const old_contextid = ({ new_contextid, rollback_new_contextid, contextid }) => (new_contextid || rollback_new_contextid) ? contextid : null
78
+
79
+ const contextid = ({ new_contextid, rollback_new_contextid, contextid }) => new_contextid || rollback_new_contextid || contextid || null
73
80
 
74
81
  const recipe = compose(
75
82
  find(__, ['Fabricator', 'Strangifier Chemistry Set', 'Chemistry Set']),
@@ -77,7 +84,7 @@ const recipe = compose(
77
84
  )
78
85
 
79
86
  const series = ifElse(
80
- compose(equals('Crate'), findTag('Type')),
87
+ compose(equals('Crate'), findTag('Type', 'name')),
81
88
  ifElse(
82
89
  marketHashIncludes('#'),
83
90
  compose(
@@ -116,11 +123,11 @@ const australium = allPass([
116
123
  const wear = compose(
117
124
  prop(__, invertObj(wears)),
118
125
  removeStrings(__, ['(', ')']),
119
- findTag('Exterior')
126
+ findTag('Exterior', 'name')
120
127
  )
121
128
 
122
129
  const texture = ifElse(
123
- findTag('Exterior'),
130
+ findTag('Exterior', 'name'),
124
131
  compose(
125
132
  propOr('-1', __, invertObj(textures)),
126
133
  ({ app_data, market_hash_name }) => removeStrings(market_hash_name, [
@@ -205,7 +212,7 @@ const setQuality = when(
205
212
  compose(complement(Boolean), path(['app_data', 'quality'])),
206
213
  chain(
207
214
  assocPath(['app_data', 'quality']),
208
- compose(prop(__, invertObj(qualityNames)), findTag('Quality'))
215
+ compose(prop(__, invertObj(qualityNames)), findTag('Quality', 'name'))
209
216
  )
210
217
  )
211
218
 
@@ -230,7 +237,9 @@ const propsTf2_1 = {
230
237
  halloweenSpell,
231
238
  paintColor,
232
239
  id,
233
- old_id
240
+ old_id,
241
+ contextid,
242
+ old_contextid
234
243
  }
235
244
 
236
245
  const isTarget = either(
@@ -315,6 +324,17 @@ const propsOtherGame = {
315
324
  old_id
316
325
  }
317
326
 
327
+ const props753 = {
328
+ market_hash_name: prop('market_hash_name'),
329
+ border: compose(last, defaultTo(''), findTag('Card Border', 'internal_name')),
330
+ game: compose(nth(1), split('_'), findTag('Game', 'internal_name')),
331
+ type: compose(last, findTag('Item Type', 'internal_name')),
332
+ id,
333
+ old_id,
334
+ contextid,
335
+ old_contextid
336
+ }
337
+
318
338
  const keyRemap = when(
319
339
  compose(
320
340
  includes(__, ['5021', '5049', '5067', '5072', '5073', '5079', '5081', '5628', '5631', '5632', '5713', '5716', '5717', '5762', '5791', '5792']), //old keys that turned into regular keys
@@ -362,7 +382,7 @@ const defaultOptions440 = {
362
382
  }
363
383
 
364
384
  const fromEconItem440 = ({ omitProps = [], uncraftRemapDefindex = [] } = defaultOptions440) => compose(
365
- pick(['sku', 'id', 'old_id']),
385
+ pick(['sku', 'id', 'old_id', 'contextid', 'old_contextid']),
366
386
  chain(assoc('sku'), skuFromItem),
367
387
  uncraftRemap(uncraftRemapDefindex),
368
388
  kitRemap,
@@ -374,22 +394,26 @@ const fromEconItem440 = ({ omitProps = [], uncraftRemapDefindex = [] } = default
374
394
  setQuality
375
395
  )
376
396
 
397
+ const fromEconItem753 = () => compose(
398
+ pick(['sku', 'id', 'old_id', 'contextid', 'old_contextid']),
399
+ chain(assoc('sku'), skuFromItem753),
400
+ map(__, props753),
401
+ unary(applyTo)
402
+ )
403
+
377
404
  const fromEconItemOther = (options = {}) => compose(
378
405
  map(__, propsOtherGame),
379
406
  unary(applyTo)
380
407
  )
381
408
 
382
- const fromEconItem = ifElse(
383
- propEq(440, 'appid'),
384
- fromEconItem440(),
385
- fromEconItemOther()
386
- )
409
+ const mainFns = {
410
+ 440: fromEconItem440,
411
+ 753: fromEconItem753
412
+ }
413
+
414
+ const fromEconItem = (econItem) => (mainFns[econItem.appid] || fromEconItemOther)()(econItem)
387
415
 
388
- const fromEconItemOptions = curry((options, econItem) => ifElse(
389
- propEq(440, 'appid'),
390
- fromEconItem440(options),
391
- fromEconItemOther(options)
392
- )(econItem))
416
+ const fromEconItemOptions = curry((options, econItem) => (mainFns[econItem.appid] || fromEconItemOther)(options)(econItem))
393
417
 
394
418
  module.exports = {
395
419
  fromEconItem,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juice789/tf2items",
3
- "version": "1.0.31",
3
+ "version": "1.0.32",
4
4
  "description": "tf2 item schema thingys",
5
5
  "main": "app.js",
6
6
  "scripts": {
package/sku753.js ADDED
@@ -0,0 +1,28 @@
1
+ const skuFromItem753 = ({
2
+ market_hash_name,
3
+ game,
4
+ border,
5
+ type,
6
+ }) => [
7
+ 753,
8
+ type === '2' ? `${type}-${border}` : type,
9
+ game,
10
+ encodeURIComponent(market_hash_name)
11
+ ].filter(Boolean).join(';')
12
+
13
+ const itemFromSku753 = (sku) => {
14
+ const [x, type, game, market_hash_name] = sku.split(';')
15
+ const item = {
16
+ type,
17
+ border: type[1],
18
+ game,
19
+ market_hash_name: decodeURIComponent(market_hash_name)
20
+ }
21
+ item.sku = sku
22
+ return item
23
+ }
24
+
25
+ module.exports = {
26
+ skuFromItem753,
27
+ itemFromSku753
28
+ }