BF test bench docks when dragged onto a component, judged by its middle

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-28 13:19:09 +01:00
parent 45c37bef43
commit 5f5a4af59c
2 changed files with 19 additions and 4 deletions

View File

@ -1171,7 +1171,7 @@ function onPointerUp(e: PointerEvent) {
ed.commit(false)
} else if (d.moved) {
ed.unplugMoved(new Set(d.orig.nodes.keys()))
ed.commit(false)
if (d.node.kind !== 'bench' || !ed.dropBench(d.node)) ed.commit(false)
} else if (d.toggle && d.row) ed.toggleRow(d.node, d.row)
else if (d.toggle && d.node.kind === 'keyboard') ed.typeInto(d.node.id)
else if (d.toggle) ed.toggleInput(d.node)

View File

@ -913,7 +913,7 @@ function create() {
if (p.kind === 'bench') {
node.bench = { rows: [] }
// Dropped on (or next to) a component: docks below it.
const chip = benchSpot(x, y)
const chip = benchSpot(node)
if (chip) dockAt(node, chip)
}
// A new pixel is like the one placed last: building a colour screen, every pixel comes in colour.
@ -1450,8 +1450,11 @@ function create() {
const benchOpen = ref<string | null>(null)
let benchTimer: ReturnType<typeof setTimeout> | undefined
/** The component a bench at this spot docks to: one whose box is under it or within two squares. */
function benchSpot(x: number, y: number): CircuitNode | undefined {
/** The component a bench docks to: one whose box is under the bench's middle, or within two squares of it. */
function benchSpot(bench: CircuitNode): CircuitNode | undefined {
const own = shapeOf(bench, getDef.value).body
const x = bench.x + own.x + own.w / 2
const y = bench.y + own.y + own.h / 2
let best: CircuitNode | undefined
let bestD = 2.01
for (const n of def.value.nodes) {
@ -1476,6 +1479,17 @@ function create() {
bench.y = Math.ceil(chip.y + b.y + b.h + 1.5)
}
/** A bench let go after a drag: onto a component, it docks there (elsewhere it stays as it was). */
function dropBench(bench: CircuitNode) {
const chip = benchSpot(bench)
if (!chip || !bench.bench) return false
dockAt(bench, chip)
commit(false)
scheduleBenches()
notify(`Tests ${getDef.value(chip.chip ?? '')?.name ?? 'the component'}`)
return true
}
/** Docks a bench to a component of this circuit (or undocks it) and runs its tests. */
function dockBench(id: string, chipId: string | null) {
const n = def.value.nodes.find(x => x.id === id)
@ -3104,6 +3118,7 @@ function create() {
runBenchNow,
setBench,
dockBench,
dropBench,
screens,
keyQueues,
devVersion,