Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 21 additions & 35 deletions lib/game_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ const LanguageHandler = {
}
};


class GameData {
constructor(update_interval, enable_update) {
this.items_game_url = 'https://raw.githubusercontent.com/SteamDatabase/GameTracking-CS2/master/game/csgo/pak01_dir/scripts/items/items_game.txt';
this.items_game_cdn_url = 'https://raw.githubusercontent.com/SteamDatabase/GameTracking-CS2/master/game/csgo/pak01_dir/scripts/items/items_game_cdn.txt';
this.items_game_to_images_url = 'https://api.steamapis.com/image/items/730';
this.csgo_english_url = 'https://raw.githubusercontent.com/SteamDatabase/GameTracking-CS2/master/game/csgo/pak01_dir/resource/csgo_english.txt';
this.schema_url = 'https://raw.githubusercontent.com/SteamDatabase/SteamTracking/b5cba7a22ab899d6d423380cff21cec707b7c947/ItemSchema/CounterStrikeGlobalOffensive.json';

this.items_game = false;
this.items_game_cdn = false;
this.items_to_images = false;
this.csgo_english = false;
this.schema = false;

Expand All @@ -62,7 +63,7 @@ class GameData {
}

/*
Loads items_game, csgo_english, and items_game_cdn from disk
Loads items_game, csgo_english, and items_to_images from disk
*/
loadFiles() {
if (fs.existsSync('game_files/items_game.txt')) {
Expand All @@ -75,9 +76,9 @@ class GameData {
this.csgo_english = new Proxy(this.csgo_english, LanguageHandler);
}

if (fs.existsSync('game_files/items_game_cdn.txt')) {
let data = fs.readFileSync('game_files/items_game_cdn.txt', 'utf8');
this.items_game_cdn = this.parseItemsCDN(data);
if (fs.existsSync('game_files/items_to_images.txt')) {
let data = fs.readFileSync('game_files/items_to_images.txt', 'utf8');
this.items_to_images = this.parseItemsImages(data);
}

if (fs.existsSync('game_files/schema.json')) {
Expand All @@ -87,22 +88,10 @@ class GameData {
}

/*
Parses the data of items_game_cdn
Parses the data of items_to_images
*/
parseItemsCDN(data) {
let lines = data.split('\n');

const result = {};

for (let line of lines) {
let kv = line.split('=');

if (kv[1]) {
result[kv[0]] = kv[1];
}
}

return result;
parseItemsImages(data) {
return JSON.parse(data);
}

/*
Expand All @@ -124,7 +113,7 @@ class GameData {
}

/*
Updates and saves the most recent versions of csgo_english, items_game, and items_game_cdn from the SteamDB Github
Updates and saves the most recent versions of csgo_english, items_game, and items_to_images from the SteamDB Github
*/
update() {
winston.info('Updating Game Files...');
Expand All @@ -149,13 +138,13 @@ class GameData {
else winston.error('Failed to fetch csgo_english.txt');
});

utils.downloadFile(this.items_game_cdn_url, (data) => {
utils.downloadFile(this.items_game_to_images_url, (data) => {
if (data) {
winston.debug('Fetched items_game_cdn.txt');
this.items_game_cdn = this.parseItemsCDN(data);
fs.writeFileSync('game_files/items_game_cdn.txt', data, 'utf8');
winston.debug('Fetched items_to_images.txt');
this.items_to_images = this.parseItemsImages(data);
fs.writeFileSync('game_files/items_to_images.json', data, 'utf8');
}
else winston.error('Failed to fetch items_game_cdn.txt');
else winston.error('Failed to fetch items_to_images.txt');
});

utils.downloadFile(this.schema_url, (data) => {
Expand All @@ -172,7 +161,7 @@ class GameData {
Given returned iteminfo, finds the item's min/max float, name, weapon type, and image url using CSGO game data
*/
addAdditionalItemProperties(iteminfo) {
if (!this.items_game || !this.items_game_cdn || !this.csgo_english) return;
if (!this.items_game || !this.items_to_images || !this.csgo_english) return;

// Get sticker codename/name
const stickerKits = this.items_game.sticker_kits;
Expand Down Expand Up @@ -222,13 +211,6 @@ class GameData {
weapon_name = this.items_game['items'][iteminfo.defindex]['name'];
}

// Get the image url
let image_name = weapon_name + skin_name;

if (image_name in this.items_game_cdn) {
iteminfo['imageurl'] = this.items_game_cdn[image_name];
}

// Get the paint data and code name
let code_name;
let paint_data;
Expand Down Expand Up @@ -314,6 +296,10 @@ class GameData {
if (itemName) {
iteminfo['full_item_name'] = itemName;
}

if (itemName in this.items_to_images) {
iteminfo['imageurl'] = this.items_to_images[itemName];
}
}

getWearName(float) {
Expand Down