2015-09-07 12:00:19 +08:00
module . exports = CEconItem ;
2015-09-07 12:10:32 +08:00
function CEconItem ( item , descriptions , 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 13:45:23 +08:00
var isCurrency = ( typeof this . is _currency !== 'undefined' ) ? ( ! ! this . is _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
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 13:45:23 +08:00
if ( descriptions ) {
for ( thing in descriptions ) {
if ( descriptions . hasOwnProperty ( thing ) ) {
2016-12-13 13:23:02 +08:00
this [ thing ] = descriptions [ 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 ;
}
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 ) {
if ( ! this . tags ) {
return null ;
}
for ( var i = 0 ; i < this . tags . length ; i ++ ) {
if ( this . tags [ i ] . category == category ) {
return this . tags [ i ] ;
}
}
return null ;
} ;