Skip to content

Commit

Permalink
Update rustlabs static files
Browse files Browse the repository at this point in the history
  • Loading branch information
alexemanuelol committed Jul 18, 2024
1 parent 8996b5a commit 0d2a720
Show file tree
Hide file tree
Showing 9 changed files with 33,623 additions and 3,192 deletions.
112 changes: 74 additions & 38 deletions src/external/process_rustlabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,42 @@ const Utils = require('../util/utils.js');

const SLEEP_TIMEOUT_MS = 2000;

const RUSTLABS_ALL_ITEMS_URL = 'https://rustlabs.com/group=itemlist';
const RUSTLABS_ITEM_URL = 'https://rustlabs.com/item/';
const RUSTLABS_ALL_ITEMS_URL = 'https://wiki.rustclash.com/group=itemlist';
const RUSTLABS_ITEM_URL = 'https://wiki.rustclash.com/item/';

const RUSTLABS_ALL_LOOT_CONTAINERS_URL = 'https://rustlabs.com/group=containers';
const RUSTLABS_ENTITY_URL = 'https://rustlabs.com/entity/';
const RUSTLABS_ALL_LOOT_CONTAINERS_URL = 'https://wiki.rustclash.com/group=containers';
const RUSTLABS_ENTITY_URL = 'https://wiki.rustclash.com/entity/';

const RUSTLABS_ALL_BUILDING_BLOCKS_URL = 'https://rustlabs.com/group=building-blocks';
const RUSTLABS_BUILDING_BLOCK_URL = 'https://rustlabs.com/building/';
const RUSTLABS_ALL_BUILDING_BLOCKS_URL = 'https://wiki.rustclash.com/group=building-blocks';
const RUSTLABS_BUILDING_BLOCK_URL = 'https://wiki.rustclash.com/building/';

const RUSTLABS_ALL_OTHER_URL = 'https://rustlabs.com/group=else';
const RUSTLABS_OTHER_URL = 'https://rustlabs.com/entity/';
const RUSTLABS_ALL_OTHER_URL = 'https://wiki.rustclash.com/group=else';
const RUSTLABS_OTHER_URL = 'https://wiki.rustclash.com/entity/';


const RUSTLABS_ALL_ITEMS_REGEX = /<a\shref="\/item\/(.*?)"\sclass.*?img\ssrc=.*?img\/.*?\/(.*?)\.png"\salt="(.*?)"/gm
const RUSTLABS_ITEM_RECYCLE_AREA_REGEX = /Recycler<\/a><\/td>\n^.*?$\n^.*?$\n<\/td>/gm
const RUSTLABS_ITEM_RECYCLE_REGEX = /<a\shref.*?img\/.*?\/(.*?)\.png.*?alt="(.*?)".*?text-in-icon">(.*?)<\/span><\/a>/gm
const RUSTLABS_ITEM_RECYCLE_AREA_REGEX = /Recycler<\/th>(\n|.)*?<\/table>/gm
const RUSTLABS_ITEM_RECYCLE_ROW_REGEX = /<td class="left">(\n|.)*?<\/tr>/gm
const RUSTLABS_ITEM_RECYCLE_ITEM_REGEX = /\/entity\/(.*?)"/gm
const RUSTLABS_ITEM_RECYCLE_ITEM_EFFICIENCY_REGEX = /<td\sdata-value="(.*?)">.*?%<\/td>/gm
const RUSTLABS_ITEM_RECYCLE_OUTPUT_ITEMS_REGEX = /<a\shref.*?img\/.*?\/(.*?)\.png.*?alt="(.*?)".*?text-in-icon">(.*?)<\/span><\/a>/gm

const RUSTLABS_ITEM_CRAFT_AREA_REGEX = /data-name="craft"\sclass="tab-page(\n|.)*?<\/thead(\n|.)*?<\/tr>/gm
const RUSTLABS_ITEM_CRAFT_INGREDIENTS_REGEX =
/<a\shref.*?img\/.*?\/(.*?)\.png.*?alt="(.*?)".*?text-in-icon">(.*?)<\/span><\/a>/gm
const RUSTLABS_ITEM_CRAFT_TIME_REGEX = /^<td\sdata-value="(.*?)">(.*?)<\/td>$/gm
const RUSTLABS_ITEM_CRAFT_TIME_REGEX = /^\s*<td\sdata-value="(.*?)">(.*?)<\/td>/gm

const RUSTLABS_ITEM_RESEARCH_AREA_REGEX =
/data-name="blueprint"\sclass="tab-page(\n|.)*?<table\sclass(\n|.)*?<\/table>/gm
const RUSTLABS_ITEM_RESEARCH_ROW_REGEX = /<td\sclass="item-cell">(\n|.)*?<\/tr>/gm
const RUSTLABS_ITEM_RESEARCH_TYPE_REGEX =
/<td\sclass="item-cell">(\n|.)*?<img\sclass\ssrc="(\n|.)*?img\/(\n|.)*?\/(.*?)\.png/gm
/<td\sclass="item-cell">(\n|.)*?<img\sclass=""\ssrc="(\n|.)*?img\/(\n|.)*?\/(.*?)\.png/gm
const RUSTLABS_ITEM_RESEARCH_SCRAP_REGEX = /\/scrap\.png(\n|.)*?class="text-in-icon">(.*?)<\/span>/gm
const RUSTLABS_ITEM_RESEARCH_TOTAL_SCRAP_REGEX = /<td\sclass="no-padding"\sdata-value="(.*?)">/gm

const RUSTLABS_ITEM_DURABILITY_AREA_REGEX1 = /<tr\sdata-group="(.*?)"\sdata-group2="(.*?)">(\n|.)*?<\/tr>/gm
const RUSTLABS_ITEM_DURABILITY_AREA_REGEX2 = /<tr\sdata-group="(.*?)">(\n|.)*?<\/tr>/gm
const RUSTLABS_ITEM_DURABILITY_TOOL_REGEX = /<img\sclass\ssrc=".*?\/img\/.*?\/(.*?)\.png"\salt="(.*?)">/gm
const RUSTLABS_ITEM_DURABILITY_TOOL_REGEX = /<img\sclass=""\ssrc=".*?\/img\/.*?\/(.*?)\.png"\salt="(.*?)">/gm
const RUSTLABS_ITEM_DURABILITY_CAPTION_IN_TOOL_REGEX = /caption-in-item-name">(.*?)</gm
const RUSTLABS_ITEM_DURABILITY_QUANTITY_REGEX = /<td\sclass="no-padding"\sdata-value="(\d{1,7})">(.{1,10})<\/td>/gm
const RUSTLABS_ITEM_DURABILITY_QUANTITY_APPROX_REGEX = /Approximate\sQuantity">(.*?)</gm
Expand Down Expand Up @@ -469,39 +472,72 @@ function processItemRecycle(rustlabsName, shortname, name, data) {
}
data = data[0];

const matches = data.matchAll(RUSTLABS_ITEM_RECYCLE_REGEX);
const recycleItems = [];

for (const match of matches) {
if (match.length !== 4) exit();
const recycleData = new Object();
recycleData['recycler'] = new Object();
recycleData['recycler']['efficiency'] = null;
recycleData['recycler']['yield'] = [];
recycleData['shredder'] = new Object();
recycleData['shredder']['efficiency'] = null;
recycleData['shredder']['yield'] = [];
recycleData['safe-zone-recycler'] = new Object();
recycleData['safe-zone-recycler']['efficiency'] = null;
recycleData['safe-zone-recycler']['yield'] = [];

const rows = data.matchAll(RUSTLABS_ITEM_RECYCLE_ROW_REGEX);
for (const row of rows) {
if (row.length !== 2) exit();
const rowData = row[0];

const shortnameSub = match[1];
const nameSub = Utils.decodeHtml(match[2]);
let quantity = match[3];
const id = Object.keys(ITEMS).find(e => ITEMS[e].shortname === shortnameSub && ITEMS[e].name === nameSub);
if (id === undefined) exit();
let recyclerType = null;
const recyclerMatches = rowData.matchAll(RUSTLABS_ITEM_RECYCLE_ITEM_REGEX);
for (const match of recyclerMatches) {
if (match.length !== 2) exit();
recyclerType = match[1];
break;
}
if (recyclerType === null) exit();

let probability = 1;
if (quantity === '') {
quantity = 1;
let efficiency = null;
const efficiencyMatches = rowData.matchAll(RUSTLABS_ITEM_RECYCLE_ITEM_EFFICIENCY_REGEX);
for (const match of efficiencyMatches) {
if (match.length !== 2) exit();
efficiency = match[1];
break;
}
else {
quantity = quantity.replace('×', '').replace(/,/g, '');
recycleData[recyclerType]['efficiency'] = efficiency;

const matches = rowData.matchAll(RUSTLABS_ITEM_RECYCLE_OUTPUT_ITEMS_REGEX);
for (const match of matches) {
if (match.length !== 4) exit();

const shortnameSub = match[1];
const nameSub = Utils.decodeHtml(match[2]);
let quantity = match[3];
const id = Object.keys(ITEMS).find(e => ITEMS[e].shortname === shortnameSub && ITEMS[e].name === nameSub);
if (id === undefined) exit();

if (quantity.includes('%')) {
probability = `0.${quantity.replace('%', '')}`;
let probability = 1;
if (quantity === '') {
quantity = 1;
}
}
else {
quantity = quantity.replace('×', '').replace(/,/g, '');

recycleItems.push({
id: id,
probability: parseFloat(probability),
quantity: parseFloat(quantity)
});
if (quantity.includes('%')) {
probability = `0.${quantity.replace('%', '')}`;
quantity = 1;
}
}

recycleData[recyclerType]['yield'].push({
id: id,
probability: parseFloat(probability),
quantity: parseFloat(quantity)
});
}
}

rustlabsRecycleData[itemId] = recycleItems;
rustlabsRecycleData[itemId] = recycleData;
}

function processItemDurability(rustlabsName, shortname, name, data, type = 'items') {
Expand Down Expand Up @@ -606,14 +642,14 @@ function processItemDurability(rustlabsName, shortname, name, data, type = 'item
}
}
if (quantity === null) exit();

let quantityTypeId = null;
if (quantityTypeShortname !== null && quantityTypeName !== null) {
quantityTypeId = Object.keys(ITEMS).find(e =>
ITEMS[e].shortname === quantityTypeShortname && ITEMS[e].name === quantityTypeName);
if (!quantityTypeId) exit();
}


/* Time */
let timeString = null, time = null;
const timeMatches = [...dataMatch.matchAll(RUSTLABS_ITEM_DURABILITY_TIME_REGEX)];
Expand Down
57 changes: 47 additions & 10 deletions src/staticFiles/rustlabsCraftData.json
Original file line number Diff line number Diff line change
Expand Up @@ -1003,8 +1003,8 @@
}
],
"workbench": "-1607980696",
"time": 30,
"timeString": "30 sec"
"time": 15,
"timeString": "15 sec"
},
"674734128": {
"ingredients": [
Expand Down Expand Up @@ -4561,6 +4561,17 @@
"time": 1.25,
"timeString": "1–2 sec"
},
"-839576748": {
"ingredients": [
{
"id": "69511070",
"quantity": 70
}
],
"workbench": "-41896755",
"time": 11.25,
"timeString": "7–15 sec"
},
"-1252059217": {
"ingredients": [
{
Expand Down Expand Up @@ -5315,8 +5326,8 @@
}
],
"workbench": "1524187186",
"time": 18.75,
"timeString": "7–30 sec"
"time": 9.375,
"timeString": "3–15 sec"
},
"-1539025626": {
"ingredients": [
Expand Down Expand Up @@ -5617,6 +5628,17 @@
"time": 22.5,
"timeString": "15–30 sec"
},
"-892718768": {
"ingredients": [
{
"id": "-858312878",
"quantity": 20
}
],
"workbench": "1524187186",
"time": 9.375,
"timeString": "3–15 sec"
},
"-986782031": {
"ingredients": [
{
Expand Down Expand Up @@ -6024,6 +6046,21 @@
"time": 3.125,
"timeString": "1–5 sec"
},
"-948291630": {
"ingredients": [
{
"id": "317398316",
"quantity": 3
},
{
"id": "73681876",
"quantity": 1
}
],
"workbench": "-41896755",
"time": 22.5,
"timeString": "15–30 sec"
},
"-904863145": {
"ingredients": [
{
Expand Down Expand Up @@ -6504,8 +6541,8 @@
}
],
"workbench": "-41896755",
"time": 22.5,
"timeString": "15–30 sec"
"time": 11.25,
"timeString": "7–15 sec"
},
"-1785231475": {
"ingredients": [
Expand Down Expand Up @@ -6875,8 +6912,8 @@
}
],
"workbench": null,
"time": 18.75,
"timeString": "7–30 sec"
"time": 9.375,
"timeString": "3–15 sec"
},
"-180129657": {
"ingredients": [
Expand Down Expand Up @@ -6949,8 +6986,8 @@
}
],
"workbench": null,
"time": 18.75,
"timeString": "7–30 sec"
"time": 9.375,
"timeString": "3–15 sec"
},
"-41896755": {
"ingredients": [
Expand Down
Loading

0 comments on commit 0d2a720

Please sign in to comment.