Skip to content

Commit 056d06a

Browse files
committed
fix(block): order imports by relevance
1 parent 62d7a49 commit 056d06a

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

app/src/server/block-compute.server.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,13 @@ export async function computeBlock(rawData: SolveInput) {
10581058
const negativeGoalNames = new Set(
10591059
data.goals.filter((goal) => goal.rate < 0).map((goal) => goal.name),
10601060
);
1061-
const displayImports = imports.filter((flow) => !negativeGoalNames.has(flow.name));
1061+
const displayImports = imports
1062+
.filter((flow) => !negativeGoalNames.has(flow.name))
1063+
.sort((a, b) => {
1064+
if (a.name === ELECTRICITY) return -1;
1065+
if (b.name === ELECTRICITY) return 1;
1066+
return b.rate - a.rate || byNameAsc(a, b);
1067+
});
10621068
const fuelItems = [...fuelTotals.keys()]; // for the 🔥 tag in the UI
10631069
const burntItems = [...burntTotals.keys()]; // ash / depleted cells from burning
10641070

app/src/server/block-compute.test.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,15 @@ describe("module suggestions outside the core solve", () => {
7171
fx = await makeTestDb();
7272
fx.db.exec(`
7373
INSERT INTO items (name, display) VALUES
74-
('ore','Ore'),('plate','Plate'),('prod-module','Productivity module');
74+
('ore','Ore'),('flux','Flux'),('plate','Plate'),('prod-module','Productivity module');
7575
INSERT INTO recipes
7676
(name, kind, category, energy_required, allow_productivity, enabled, hidden)
7777
VALUES
7878
('make-plate','real','crafting',1,1,1,0),
7979
('craft-prod-module','real','crafting',1,0,1,0);
80-
INSERT INTO recipe_ingredients (recipe, idx, kind, name, amount)
81-
VALUES ('make-plate',0,'item','ore',1);
80+
INSERT INTO recipe_ingredients (recipe, idx, kind, name, amount) VALUES
81+
('make-plate',0,'item','ore',1),
82+
('make-plate',1,'item','flux',2);
8283
INSERT INTO recipe_products (recipe, idx, kind, name, amount) VALUES
8384
('make-plate',0,'item','plate',1),
8485
('craft-prod-module',0,'item','prod-module',1);
@@ -113,6 +114,19 @@ describe("module suggestions outside the core solve", () => {
113114
]),
114115
).toEqual({ "make-plate": ["prod-module", "prod-module"] });
115116
});
117+
118+
it("displays electricity first, then imports by descending rate", async () => {
119+
const solved = await computeBlock({
120+
goals: [{ name: "plate", rate: 1 }],
121+
recipes: ["make-plate"],
122+
});
123+
124+
expect(solved.displayImports.map(({ name, rate }) => ({ name, rate }))).toEqual([
125+
{ name: "pyops-electricity", rate: 0.1 },
126+
{ name: "flux", rate: 2 },
127+
{ name: "ore", rate: 1 },
128+
]);
129+
});
116130
});
117131

118132
describe("incidental spoilage stays outside the nominal block solve", () => {

docs/guide/blocks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ production appears separately in Factory.
3232

3333
A negative goal is already the block's visible import contract, so Block balance does not
3434
repeat that good under **Imports**. Other ingredients the block needs still appear there.
35+
Electricity is listed first, followed by the remaining imports from highest to lowest rate.
3536

3637
## Add recipes
3738

0 commit comments

Comments
 (0)