Skip to content

Commit 8516f20

Browse files
committed
Add rustlabs smelting details functions
1 parent df3a149 commit 8516f20

File tree

1 file changed

+66
-3
lines changed

1 file changed

+66
-3
lines changed

src/structures/RustLabs.js

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const CraftData = require('../staticFiles/rustlabsCraftData.json');
2626
const ResearchData = require('../staticFiles/rustlabsResearchData.json');
2727
const RecycleData = require('../staticFiles/rustlabsRecycleData.json');
2828
const DurabilityData = require('../staticFiles/rustlabsDurabilityData.json');
29+
const SmeltingData = require('../staticFiles/rustlabsSmeltingData.json');
2930

3031
const IGNORED_RECYCLE_ITEMS = [
3132
'-946369541' /* Low Grade Fuel */
@@ -43,6 +44,7 @@ class RustLabs {
4344
this._researchData = ResearchData;
4445
this._recycleData = RecycleData;
4546
this._durabilityData = DurabilityData;
47+
this._smeltingData = SmeltingData;
4648

4749
this._items = new Items();
4850

@@ -88,6 +90,7 @@ class RustLabs {
8890
get researchData() { return this._researchData; }
8991
get recycleData() { return this._recycleData; }
9092
get durabilityData() { return this._durabilityData; }
93+
get smeltingData() { return this._smeltingData; }
9194
get items() { return this._items; }
9295
get durabilityGroups() { return this._durabilityGroups }
9396
get durabilityWhich() { return this._durabilityWhich; }
@@ -240,7 +243,7 @@ class RustLabs {
240243

241244
/**
242245
* Get craft details of an item.
243-
* @param {string} name The name of the item.
246+
* @param {string} id The id of the item.
244247
* @return {array|null} null if something went wrong, otherwise [id, itemDetails, craftDetails]
245248
*/
246249
getCraftDetailsById(id) {
@@ -276,7 +279,7 @@ class RustLabs {
276279

277280
/**
278281
* Get research details of an item.
279-
* @param {string} name The name of the item.
282+
* @param {string} id The id of the item.
280283
* @return {array|null} null if something went wrong, otherwise [id, itemDetails, researchDetails]
281284
*/
282285
getResearchDetailsById(id) {
@@ -312,7 +315,7 @@ class RustLabs {
312315

313316
/**
314317
* Get recycle details of an item.
315-
* @param {string} name The name of the item.
318+
* @param {string} id The id of the item.
316319
* @return {array|null} null if something went wrong, otherwise [id, itemDetails, recycleDetails]
317320
*/
318321
getRecycleDetailsById(id) {
@@ -485,6 +488,66 @@ class RustLabs {
485488

486489
return ['items', id, this.items.items[id], content];
487490
}
491+
492+
493+
/***********************************************************************************
494+
* Smelting functions
495+
**********************************************************************************/
496+
497+
/**
498+
* Check to see if itemId is part of smelting details data.
499+
* @param {string} itemId The itemId of the item.
500+
* @return {boolean} true if exist, otherwise false.
501+
*/
502+
hasSmeltingDetails(itemId) {
503+
return this.smeltingData.hasOwnProperty(itemId);
504+
}
505+
506+
/**
507+
* Get smelting details of an item.
508+
* @param {string} name The name of the item.
509+
* @return {array|null} null if something went wrong, otherwise [id, itemDetails, smeltingDetails]
510+
*/
511+
getSmeltingDetailsByName(name) {
512+
if (typeof (name) !== 'string') return null;
513+
const id = this.items.getClosestItemIdByName(name);
514+
if (!id) return null;
515+
return this.getSmeltingDetailsById(id);
516+
}
517+
518+
/**
519+
* Get smelting details of an item.
520+
* @param {string} id The id of the item.
521+
* @return {array|null} null if something went wrong, otherwise [id, itemDetails, smeltingDetails]
522+
*/
523+
getSmeltingDetailsById(id) {
524+
if (!this.hasSmeltingDetails(id)) return null;
525+
return [id, this.items.items[id], this.smeltingData[id]];
526+
}
527+
528+
/**
529+
* Get smelting details by the from parameter item.
530+
* @param {string} id The id of the from parameter item.
531+
* @return {array|null} null if something went wrong, otherwise Object of smelting details of the
532+
* from parameter item.
533+
*/
534+
getSmeltingDetailsFromParameterById(id) {
535+
if (!this.items.hasOwnProperty(id)) return null;
536+
const fromParameterSmeltingDetails = new Object();
537+
for (const [smeltingTool, smeltingDetails] of Object.entries(this.smeltingData)) {
538+
for (const details of smeltingDetails) {
539+
if (details.fromId === id) {
540+
if (!fromParameterSmeltingDetails.hasOwnProperty(smeltingTool)) {
541+
fromParameterSmeltingDetails[smeltingTool] = [];
542+
}
543+
544+
fromParameterSmeltingDetails[smeltingTool].push(details);
545+
}
546+
}
547+
}
548+
549+
return fromParameterSmeltingDetails;
550+
}
488551
}
489552

490553
module.exports = RustLabs;

0 commit comments

Comments
 (0)