2015-09-07 12:00:19 +08:00
module . exports = CEconItem ;
2016-12-13 14:53:30 +08:00
function CEconItem ( item , description , contextID ) {
2015-09-07 12:00:19 +08:00
var thing ;
2016-12-13 13:45:23 +08:00
for ( thing in item ) {
if ( item . hasOwnProperty ( thing ) ) {
2015-09-07 12:00:19 +08:00
this [ thing ] = item [ thing ] ;
}
}
2016-12-13 14:28:48 +08:00
var isCurrency = ! ! ( this . is _currency || this . currency ) || typeof this . currencyid !== 'undefined' ; // I don't want to put this on the object yet; it's nice to have the ids at the top of printed output
2016-12-13 13:45:23 +08:00
if ( isCurrency ) {
this . currencyid = this . id = ( this . id || this . currencyid ) ;
} else {
this . assetid = this . id = ( this . id || this . assetid ) ;
}
2015-09-07 12:00:19 +08:00
this . instanceid = this . instanceid || '0' ;
this . amount = parseInt ( this . amount , 10 ) ;
2015-09-10 00:04:28 +08:00
this . contextid = this . contextid || contextID . toString ( ) ;
2015-09-07 12:00:19 +08:00
// Merge the description
2016-12-13 14:53:30 +08:00
if ( description ) {
// Is this a listing of descriptions?
if ( description [ this . classid + '_' + this . instanceid ] ) {
description = description [ this . classid + '_' + this . instanceid ] ;
}
for ( thing in description ) {
if ( description . hasOwnProperty ( thing ) ) {
this [ thing ] = description [ thing ] ;
2015-09-07 12:00:19 +08:00
}
}
}
2016-12-13 13:45:23 +08:00
this . is _currency = isCurrency ;
2015-09-07 12:00:19 +08:00
this . tradable = ! ! this . tradable ;
this . marketable = ! ! this . marketable ;
this . commodity = ! ! this . commodity ;
this . market _tradable _restriction = ( this . market _tradable _restriction ? parseInt ( this . market _tradable _restriction , 10 ) : 0 ) ;
this . market _marketable _restriction = ( this . market _marketable _restriction ? parseInt ( this . market _marketable _restriction , 10 ) : 0 ) ;
2015-12-22 03:22:07 +08:00
this . fraudwarnings = this . fraudwarnings || [ ] ;
this . descriptions = this . descriptions || [ ] ;
2016-12-13 13:45:23 +08:00
if ( this . owner && JSON . stringify ( this . owner ) == '{}' ) {
2015-12-22 03:22:07 +08:00
this . owner = null ;
}
2016-12-13 14:53:30 +08:00
// Restore old property names of tags
if ( this . tags ) {
this . tags = this . tags . map ( function ( tag ) {
return {
"internal_name" : tag . internal _name ,
"name" : tag . localized _tag _name || tag . name ,
"category" : tag . category ,
"color" : tag . color || "" ,
"category_name" : tag . localized _category _name || tag . category _name
} ;
} ) ;
}
2016-12-15 13:53:26 +08:00
// Restore market_fee_app, if applicable
var match ;
if ( this . appid == 753 && this . contextid == 6 && this . market _hash _name && ( match = this . market _hash _name . match ( /^(\d+)\-/ ) ) ) {
this . market _fee _app = parseInt ( match [ 1 ] , 10 ) ;
}
2016-12-13 14:53:30 +08:00
if ( this . actions === "" ) {
this . actions = [ ] ;
}
delete this . currency ;
2015-09-07 12:00:19 +08:00
}
CEconItem . prototype . getImageURL = function ( ) {
return "https://steamcommunity-a.akamaihd.net/economy/image/" + this . icon _url + "/" ;
} ;
CEconItem . prototype . getLargeImageURL = function ( ) {
if ( ! this . icon _url _large ) {
return this . getImageURL ( ) ;
}
return "https://steamcommunity-a.akamaihd.net/economy/image/" + this . icon _url _large + "/" ;
} ;
CEconItem . prototype . getTag = function ( category ) {
2016-12-13 14:53:30 +08:00
if ( ! this . tags ) {
2015-09-07 12:00:19 +08:00
return null ;
}
2016-12-13 14:53:30 +08:00
for ( var i = 0 ; i < this . tags . length ; i ++ ) {
if ( this . tags [ i ] . category == category ) {
2015-09-07 12:00:19 +08:00
return this . tags [ i ] ;
}
}
return null ;
} ;