|
|
@@ -1,43 +1,27 @@
|
|
|
import {cachedFetchJSON} from './cache';
|
|
|
import {setupPopover} from './popover';
|
|
|
|
|
|
-const BUY = new Set([
|
|
|
- // definitely buy
|
|
|
- 'C', 'FLX', 'H', 'H2O', 'HAL', 'HCP', 'HE', 'LST', 'MG', 'N', 'NA', 'NCS', 'NS', 'O', 'PE', 'PG', 'S', 'TCL', 'THF',
|
|
|
- // maybe buy
|
|
|
- 'AIR', 'AU', 'BE', 'BRM', 'BOR', 'BTS', 'CU', 'FAN', 'FC', 'FE', 'HCC', 'HD', 'LDI', 'LI', 'MFK', 'MWF',
|
|
|
- 'REA', 'RG', 'RGO', 'ROM', 'SFK', 'SI', 'STL', 'TCO', 'TPU',
|
|
|
- // import
|
|
|
- 'AAR', 'AWF', 'CAP', 'CF', 'RAD',
|
|
|
- // skip
|
|
|
- 'LFE', 'LHP', 'MFE', 'SFE', 'SSC',
|
|
|
-])
|
|
|
-
|
|
|
-const blueprint = {
|
|
|
- 'FFC': 1,
|
|
|
- 'FSE': 1,
|
|
|
- 'LFE': 2,
|
|
|
- 'MFE': 2,
|
|
|
- 'RCT': 1,
|
|
|
- 'SFE': 1,
|
|
|
- 'LCB': 1,
|
|
|
- 'MFL': 1,
|
|
|
- 'MSL': 1,
|
|
|
- 'LHP': 94,
|
|
|
- 'SSC': 128,
|
|
|
- 'BR1': 1,
|
|
|
- 'CQM': 1,
|
|
|
-}
|
|
|
-
|
|
|
+let blueprint: Record<string, number>;
|
|
|
+let BUY: Set<string>;
|
|
|
+let renderTarget: Element;
|
|
|
+let cx: string;
|
|
|
const apiKey = document.querySelector('#api-key') as HTMLInputElement;
|
|
|
-{
|
|
|
+
|
|
|
+export function setupProduction(bp: Record<string, number>, buy: Set<string>, cxCode: string, target: Element) {
|
|
|
+ blueprint = bp;
|
|
|
+ BUY = buy;
|
|
|
+ cx = cxCode;
|
|
|
+ renderTarget = target;
|
|
|
+
|
|
|
const storedApiKey = localStorage.getItem('punoted-api-key');
|
|
|
if (storedApiKey)
|
|
|
apiKey.value = storedApiKey;
|
|
|
+ document.querySelector('#fetch')!.addEventListener('click', render);
|
|
|
+
|
|
|
+ setupPopover();
|
|
|
+ render();
|
|
|
}
|
|
|
-document.querySelector('#fetch')!.addEventListener('click', render);
|
|
|
|
|
|
-const renderTarget = document.querySelector('div#shipbuilding')!;
|
|
|
async function render() {
|
|
|
const loader = document.querySelector('#loader') as HTMLElement;
|
|
|
loader.style.display = 'block';
|
|
|
@@ -50,8 +34,6 @@ async function render() {
|
|
|
}
|
|
|
loader.style.display = 'none';
|
|
|
}
|
|
|
-setupPopover();
|
|
|
-render();
|
|
|
|
|
|
async function _render() {
|
|
|
const [allPrices, recipes, buildingList, storage] = await Promise.all([
|
|
|
@@ -60,7 +42,7 @@ async function _render() {
|
|
|
cachedFetchJSON('https://api.prunplanner.org/data/buildings/') as Promise<Building[]>,
|
|
|
fetchStorage(),
|
|
|
]);
|
|
|
- const prices = Object.fromEntries(allPrices.filter((price) => price.ExchangeCode === 'IC1')
|
|
|
+ const prices = Object.fromEntries(allPrices.filter((price) => price.ExchangeCode === cx)
|
|
|
.map((price) => [price.MaterialTicker, price]));
|
|
|
const buildings = Object.fromEntries(buildingList.map((b) => [b.building_ticker, b]));
|
|
|
|