Skip to content

Commit

Permalink
Merge pull request #23 from influenceth/resource-mapping
Browse files Browse the repository at this point in the history
Resource mapping
  • Loading branch information
clexmond authored Oct 4, 2022
2 parents 4d2a7ba + c113c90 commit cb39f01
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 41 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,31 @@ const CREW_TRAITS = [
}
];

const RESOURCES = {
1: { name: 'Ammonia' },
2: { name: 'Carbon Dioxide' },
3: { name: 'Carbon Monoxide' },
4: { name: 'Hydrogen' },
5: { name: 'Methane' },
6: { name: 'Nitrogen' },
7: { name: 'Sulfur Dioxide' },
8: { name: 'Water' },
9: { name: 'Feldspar' },
10: { name: 'Graphite' },
11: { name: 'Olivine' },
12: { name: 'Pyroxene' },
13: { name: 'Rhabdite' },
14: { name: 'Taenite' },
15: { name: 'Troilite' },
16: { name: 'Apatite' },
17: { name: 'Bitumen' },
18: { name: 'Calcite' },
19: { name: 'Merrillite' },
20: { name: 'Xenotime' },
21: { name: 'Coffinite' },
22: { name: 'Uraninite' }
};

/**
* Returns the bonus information based on its position in the bitpacked bonuses int
* @param num Position in the bitpacked bonuses int
Expand Down Expand Up @@ -432,6 +457,20 @@ const toRarity = (bonuses) => {
return RARITIES[5];
};

/**
* Converts array of relative resources into an object based on the RESOURCES list
* Result format: { RESOURCE_NAME: value }
* @param resources array of float values (asc order by resource type)
*/
const toResources = (resources) => {
return resources.reduce((acc, value, index) => {
const { name } = RESOURCES[index + 1] || {};
if (!name) throw new Error('Invalid index/key');
acc[name] = value;
return acc;
}, {});
}

/**
* Returns whether the asteroid has been scanned based on its bitpacked bonuses int
* @param packed The bitpacked bonuses int
Expand Down Expand Up @@ -633,6 +672,7 @@ module.exports = {
REGIONS,
SPECTRAL_TYPES,
RARITIES,
RESOURCES,
SIZES,
BONUS_MAPS,
CREW_COLLECTIONS,
Expand All @@ -650,6 +690,7 @@ module.exports = {
toBonus,
toBonuses,
toRarity,
toResources,
isScanned,
toSpectralType,
toSize,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "influence-utils",
"version": "1.10.1",
"version": "1.10.2",
"description": "Utilities to interact with Influence",
"main": "index.js",
"types": "index.d.ts",
Expand Down

0 comments on commit cb39f01

Please sign in to comment.