raylu 2 tygodni temu
rodzic
commit
5e4b361fea
6 zmienionych plików z 92 dodań i 2 usunięć
  1. 1 0
      .gitignore
  2. 1 1
      package.json
  3. 57 0
      ts/corps.ts
  4. 0 1
      ts/ledger.ts
  5. 18 0
      www/corps.html
  6. 15 0
      www/style.css

+ 1 - 0
.gitignore

@@ -4,6 +4,7 @@ config.toml
 node_modules/
 uv.lock
 www/buy.js*
+www/corps.js*
 www/gov.js*
 www/ledger.js*
 www/mat.js*

+ 1 - 1
package.json

@@ -2,7 +2,7 @@
 	"name": "prun-calc",
 	"version": "0",
 	"scripts": {
-		"build": "bun build ts/buy.ts ts/gov.ts ts/ledger.ts ts/mat.ts ts/production.ts ts/roi.ts --outdir www --target browser --sourcemap=external",
+		"build": "bun build ts/buy.ts ts/corps.ts ts/gov.ts ts/ledger.ts ts/mat.ts ts/production.ts ts/roi.ts --outdir www --target browser --sourcemap=external",
 		"typecheck": "tsgo --noEmit",
 		"serve": "python3 -m http.server -d www 8000"
 	},

+ 57 - 0
ts/corps.ts

@@ -0,0 +1,57 @@
+const main = document.querySelector('main') as HTMLTextAreaElement;
+
+(async () => {
+	const loader = document.querySelector('#loader') as HTMLElement;
+	loader.style.display = 'block';
+	try {
+		await render();
+	} catch (e) {
+		main.textContent = e instanceof Error ? e.message : String(e);
+	}
+	loader.style.display = 'none';
+})();
+
+async function render(): Promise<void> {
+	const corps: Corporation[] = await fetch('corps.json').then((r) => r.json());
+	corps.sort((a, b) => (a.headquartersAddress?.lines.find((line) => line.type === 'SYSTEM')!.entity.naturalId ?? '\uffff')
+			.localeCompare(b.headquartersAddress?.lines.find((line) => line.type === 'SYSTEM')!.entity.naturalId ?? '\uffff'));
+	main.innerHTML = `<table>
+		<thead>
+			<tr>
+				<th>code</th>
+				<th>name</th>
+				<th>shareholders</th>
+				<th>HQ</th>
+			</tr>
+		</thead>
+		<tbody>
+			${corps.map(renderCorpRow).join('')}
+		</tbody>
+	</table>`;
+}
+
+function renderCorpRow(corp: Corporation): string {
+	let hq = '';
+	if (corp.headquartersAddress !== null) {
+		const planet = corp.headquartersAddress.lines.find((line) => line.type === 'PLANET')!.entity;
+		hq = planet.name;
+		if (planet.name !== planet.naturalId)
+			hq += ` (${planet.naturalId})`;
+		if (!corp.headquartersFinished)
+			hq += ' [unfinished]';
+	}
+	return `<tr>
+		<td>${corp.code}</td>
+		<td>${corp.name}</td>
+		<td>${corp.shareholders.length}</td>
+		<td>${hq}</td>
+	</tr>`;
+}
+
+interface Corporation {
+	name: string;
+	code: string;
+	headquartersAddress: {lines: {type: 'SYSTEM' | 'PLANET', entity: {name: string, naturalId: string}}[]} | null;
+	headquartersFinished: boolean;
+	shareholders: {}[];
+}

+ 0 - 1
ts/ledger.ts

@@ -22,7 +22,6 @@ async function getPrices(): Promise<Record<string, number | null>> {
 	for (const price of allPrices)
 		if (price.ExchangeCode === 'IC1')
 			priceMap[price.MaterialTicker] = price.VWAP30D;
-console.log(priceMap);
 	return priceMap;
 }
 const pricePromise = getPrices();

+ 18 - 0
www/corps.html

@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+	<meta charset="UTF-8">
+	<title>PrUn corporations</title>
+	<link rel="stylesheet" type="text/css" href="style.css">
+	<link rel="icon" href="https://www.raylu.net/hammer-man.svg" />
+	<meta name="viewport" content="width=device-width, initial-scale=1">
+	<meta name="theme-color" content="#222">
+</head>
+<body>
+	<a href="/">← back</a>
+	<main class="corps">
+		<section id="loader"></section>
+	</main>
+	<script src="corps.js"></script>
+</body>
+</html>

+ 15 - 0
www/style.css

@@ -105,6 +105,21 @@ main.buy {
 	}
 }
 
+main.corps {
+	table {
+		td:nth-child(1),
+		td:nth-child(2),
+		td:nth-child(4) {
+			padding: 0 16px;
+			text-align: inherit;
+		}
+		td:nth-child(2),
+		td:nth-child(4) {
+			font-family: inherit;
+		}
+	}
+}
+
 main.gov {
 	form input#planet {
 		margin-bottom: 1em;