Bläddra i källkod

shipbuilding: show where to ship each mat

raylu 5 dagar sedan
förälder
incheckning
76687078c3
2 ändrade filer med 22 tillägg och 5 borttagningar
  1. 19 1
      ts/shipbuilding.ts
  2. 3 4
      www/style.css

+ 19 - 1
ts/shipbuilding.ts

@@ -291,6 +291,7 @@ function renderProduction(expertiseGroups: Record<string, string[]>, production:
 	let totalConsumablesCost = 0;
 	for (const [expertise, productionBuildings] of Object.entries(expertiseGroups)) {
 		section.append(element('h3', {textContent: expertise.toLocaleLowerCase()}));
+		const shipTo: Record<string, Record<string, number>> = {};
 		for (const building of productionBuildings) {
 			const buildingMats = element('div');
 			const mats = Object.entries(production[building]);
@@ -300,10 +301,18 @@ function renderProduction(expertiseGroups: Record<string, string[]>, production:
 				const span = element('span', {textContent: `${formatAmount(amount)}x${mat}`});
 				span.style.color = traded > amount * 2 ? '#0cc' : '#c70';
 				const consumers = matConsumers[mat];
-				if (consumers)
+				if (consumers) {
 					span.dataset.tooltip = consumers
 						.map((c) => `${formatAmount(c.amount)}x${mat} → ${c.downstreamMat} (${c.expertise.toLocaleLowerCase()})`)
 						.join('\n');
+					for (const consumer of consumers) {
+						if (consumer.expertise == expertise) // we aren't shipping it anywhere
+							continue;
+						if (!shipTo[consumer.expertise])
+							shipTo[consumer.expertise] = {};
+						shipTo[consumer.expertise][mat] = (shipTo[consumer.expertise][mat] ?? 0) + consumer.amount;
+					}
+				}
 				buildingMats.append(span);
 				if (index < mats.length - 1)
 					buildingMats.append(document.createTextNode(' '));
@@ -320,6 +329,15 @@ function renderProduction(expertiseGroups: Record<string, string[]>, production:
 			buildingRow.append(buildingMats);
 			section.append(buildingRow);
 		}
+
+		const shipToDetails = element('details');
+		shipToDetails.append(element('summary', {textContent: 'ship to'}));
+		for (const [expertise, mats] of Object.entries(shipTo)) {
+			const shipToRow = element('div', {textContent: expertise.toLocaleLowerCase() + ': '});
+			shipToRow.textContent += Object.entries(mats).map(([mat, amount]) => `${amount}x${mat}`).join(' ');
+			shipToDetails.append(shipToRow);
+		}
+		section.append(shipToDetails);
 	}
 
 	section.append(element('h4', {textContent: `total consumables cost: ${formatWhole(totalConsumablesCost)}/day,

+ 3 - 4
www/style.css

@@ -158,12 +158,11 @@ main.ledger {
 }
 
 main.shipbuilding {
+	summary {
+		cursor: pointer;
+	}
 	.analysis-node {
 		padding-left: 40px;
-
-		summary {
-			cursor: pointer;
-		}
 	}
 	.analysis-node.root {
 		margin-top: 2em;