refactor: Beute-Frontend vereinfacht (findPart, subVec3, seededRandom)
Gemeinsame Helfer statt vier Kopien der Teilsuche, zwei Vektor- Subtraktionen und zwei Zufallsgeneratoren; hasPartSheet an einer Stelle; ungenutzte setOpacity und points-Ref entfernt. Verhalten unverändert (1050 Tests). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
0b0bc3c6dc
commit
9f6ab4ea3f
13 files changed
+85
-84
No files matched your search
@@ -0,0 +1,14 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { findPart } from "./find-part";
|
||||
import { part, templateState } from "./test-utils";
|
||||
|
||||
describe("findPart", () => {
|
||||
it("finds stack parts and inserts, and nothing for an unknown id", () => {
|
||||
const state = templateState();
|
||||
state.stack[1] = { ...state.stack[1], inserts: [part("e", "evaporator")] };
|
||||
|
||||
expect(findPart(state, "b")).toBe(state.stack[1]);
|
||||
expect(findPart(state, "e")).toBe(state.stack[1].inserts![0]);
|
||||
expect(findPart(state, "nope")).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { HivePart, HiveState } from "./types";
|
||||
|
||||
/** A stack part or an insert by id; undefined for an unknown id. */
|
||||
export function findPart(state: HiveState, id: string): HivePart | undefined {
|
||||
for (const part of state.stack) {
|
||||
if (part.id === id) return part;
|
||||
const insert = part.inserts?.find((candidate) => candidate.id === id);
|
||||
if (insert) return insert;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { FeedType } from "@/lib/feedings/types";
|
||||
import { findPart } from "./find-part";
|
||||
import type { CatalogPartType, HiveCatalog, HiveOp, HivePart, HiveState, LevelField } from "./types";
|
||||
|
||||
// Spec section 8: suggestions only. Nothing here books a feeding or treatment.
|
||||
@@ -15,15 +16,6 @@ const ACID_KEY = "acidMl";
|
||||
const isFeedKind = (kind: string | undefined): boolean => kind === "FEEDER" || kind === "FRAME_FEEDER";
|
||||
const ROUNDING = 1000;
|
||||
|
||||
function findPart(state: HiveState, id: string): HivePart | undefined {
|
||||
for (const part of state.stack) {
|
||||
if (part.id === id) return part;
|
||||
const insert = part.inserts?.find((candidate) => candidate.id === id);
|
||||
if (insert) return insert;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function typeOf(part: HivePart | undefined, catalog: HiveCatalog): CatalogPartType | undefined {
|
||||
return part ? catalog.partTypes.get(part.partTypeId) : undefined;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,11 @@ import type { CatalogPartType, FrameType, HiveCatalog, HivePart, HivePartKind, H
|
||||
|
||||
export type Vec3 = [number, number, number];
|
||||
|
||||
/** a − b, component by component. */
|
||||
export function subVec3(a: Vec3, b: Vec3): Vec3 {
|
||||
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
||||
}
|
||||
|
||||
export interface PartBox {
|
||||
id: string;
|
||||
partTypeId: string;
|
||||
|
||||
Reference in new issue
Block a user