BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
|
import { compile } from '../app/lib/logic/compile'
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
import { faceCandidates, screenLayouts, shapeOf } from '../app/lib/logic/geometry'
|
|
|
|
|
import { matchScore } from '../app/lib/match'
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
import { createProject, lookup } from '../app/lib/logic/ops'
|
|
|
|
|
import { toProject } from '../app/lib/logic/project'
|
|
|
|
|
import { Simulator } from '../app/lib/logic/sim'
|
|
|
|
|
import type { ComponentDef } from '../app/lib/logic/types'
|
|
|
|
|
|
|
|
|
|
function shown(): { p: ReturnType<typeof createProject>; inner: ComponentDef } {
|
|
|
|
|
const p = createProject({ examples: false })
|
|
|
|
|
const inner: ComponentDef = {
|
|
|
|
|
id: 'inner',
|
|
|
|
|
name: 'Show',
|
|
|
|
|
symbol: 'box',
|
|
|
|
|
nodes: [
|
|
|
|
|
{ id: 'a', kind: 'input', x: 0, y: 0, label: 'A' },
|
|
|
|
|
{ id: 'b', kind: 'input', x: 0, y: 1, label: 'B' },
|
|
|
|
|
{ id: 'l', kind: 'lamp', x: 6, y: 0, label: 'L' },
|
|
|
|
|
{ id: 'h', kind: 'hex', x: 6, y: 4 },
|
|
|
|
|
{ id: 'q', kind: 'output', x: 12, y: 0, label: 'Q' },
|
|
|
|
|
],
|
|
|
|
|
wires: [{ id: 'w', from: { node: 'a', pin: 'q' }, to: { node: 'l', pin: 'a' } }],
|
|
|
|
|
}
|
|
|
|
|
p.components.push(inner)
|
|
|
|
|
return { p, inner }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe('hex display', () => {
|
|
|
|
|
it('passes its four bits on, so it can sit in the middle of a bus', () => {
|
|
|
|
|
const p = createProject({ examples: false })
|
|
|
|
|
const def: ComponentDef = {
|
|
|
|
|
id: 'root',
|
|
|
|
|
name: 'Root',
|
|
|
|
|
symbol: 'box',
|
|
|
|
|
nodes: [
|
|
|
|
|
{ id: 's', kind: 'input', x: 0, y: 0 },
|
|
|
|
|
{ id: 'h', kind: 'hex', x: 4, y: 0 },
|
|
|
|
|
{ id: 'l', kind: 'lamp', x: 10, y: 0 },
|
|
|
|
|
],
|
|
|
|
|
wires: [
|
|
|
|
|
{ id: 'a', from: { node: 's', pin: 'q' }, to: { node: 'h', pin: 'b0' } },
|
|
|
|
|
{ id: 'b', from: { node: 'h', pin: 'q0' }, to: { node: 'l', pin: 'a' } },
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
p.components.push(def)
|
|
|
|
|
expect(shapeOf(def.nodes[1]!, lookup(p)).outputs.map(o => o.key)).toEqual(['q0', 'q1', 'q2', 'q3'])
|
|
|
|
|
const sim = new Simulator(compile(lookup(p), 'root'))
|
|
|
|
|
sim.setSource('s', true)
|
|
|
|
|
sim.run()
|
|
|
|
|
expect(sim.pin('l', 'a')).toBe(1)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('a box drawn by hand', () => {
|
|
|
|
|
it('takes its size, places things where they were put, leaves hidden ones off, carries drawings', () => {
|
|
|
|
|
const { p, inner } = shown()
|
|
|
|
|
const chip = { id: 'c', kind: 'chip' as const, chip: 'inner', x: 0, y: 0 }
|
|
|
|
|
const auto = shapeOf(chip, lookup(p))
|
|
|
|
|
expect(auto.face?.map(f => f.id)).toEqual(['l', 'h'])
|
|
|
|
|
inner.design = {
|
|
|
|
|
w: 9,
|
|
|
|
|
h: 7,
|
|
|
|
|
place: { l: { x: 5, y: 1 }, name: { x: 3, y: 5 } },
|
|
|
|
|
hide: ['h'],
|
|
|
|
|
shapes: [{ id: 's1', kind: 'rect', x: 1, y: 1, w: 2, h: 2, ink: 'red' }],
|
|
|
|
|
}
|
|
|
|
|
const s = shapeOf(chip, lookup(p))
|
|
|
|
|
expect(s.body.w).toBe(9)
|
|
|
|
|
expect(s.body.h).toBe(7)
|
|
|
|
|
// Outputs move to the new right edge; inputs stay on the left.
|
|
|
|
|
expect(s.outputs.every(o => o.dx === 9)).toBe(true)
|
|
|
|
|
expect(s.face).toEqual([expect.objectContaining({ id: 'l', x: 5, y: s.body.y + 1 })])
|
|
|
|
|
expect(s.nameAt).toEqual({ x: 3, y: s.body.y + 5 })
|
|
|
|
|
expect(s.drawing?.[0]).toMatchObject({ id: 's1', y: s.body.y + 1 })
|
|
|
|
|
// Never shorter than its pins need.
|
|
|
|
|
inner.design.h = 1
|
|
|
|
|
expect(shapeOf(chip, lookup(p)).body.h).toBeGreaterThanOrEqual(2)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('a broken design from a file is dropped, a broken drawing too', () => {
|
|
|
|
|
const { p, inner } = shown()
|
|
|
|
|
inner.design = { w: 6, h: 4, shapes: [{ id: 'x', kind: 'rect', x: 0, y: 0, w: 1, h: 1 }, { id: 'y', kind: 'laser' as 'rect', x: 0, y: 0, w: 1, h: 1 }] }
|
|
|
|
|
const back = toProject(JSON.parse(JSON.stringify(p)))
|
|
|
|
|
expect(back.components.find(d => d.id === 'inner')!.design!.shapes!.map(s => s.id)).toEqual(['x'])
|
|
|
|
|
;(inner as { design: unknown }).design = { w: 'big' }
|
|
|
|
|
expect(toProject(JSON.parse(JSON.stringify(p))).components.find(d => d.id === 'inner')!.design).toBeUndefined()
|
|
|
|
|
})
|
|
|
|
|
})
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
|
|
|
|
|
describe('the box, finer', () => {
|
|
|
|
|
it('pixels make one screen per screen name', () => {
|
|
|
|
|
const def: ComponentDef = {
|
|
|
|
|
id: 'd',
|
|
|
|
|
name: 'D',
|
|
|
|
|
symbol: 'box',
|
|
|
|
|
nodes: [
|
|
|
|
|
{ id: 'p1', kind: 'pixel', x: 0, y: 0 },
|
|
|
|
|
{ id: 'p2', kind: 'pixel', x: 1, y: 0 },
|
|
|
|
|
{ id: 'q1', kind: 'pixel', x: 0, y: 5, screen: 'Status' },
|
|
|
|
|
],
|
|
|
|
|
wires: [],
|
|
|
|
|
}
|
|
|
|
|
expect(screenLayouts(def).map(s => [s.key, s.pixels!.length])).toEqual([
|
|
|
|
|
['screen', 2],
|
|
|
|
|
['screen:Status', 1],
|
|
|
|
|
])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('shows displays of components inside when asked, with their values, and spaces pins', () => {
|
|
|
|
|
const { p, inner } = shown()
|
|
|
|
|
const outer: ComponentDef = {
|
|
|
|
|
id: 'outer',
|
|
|
|
|
name: 'Outer',
|
|
|
|
|
symbol: 'box',
|
|
|
|
|
nodes: [
|
|
|
|
|
{ id: 'x', kind: 'input', x: 0, y: 0, label: 'X' },
|
|
|
|
|
{ id: 'y', kind: 'input', x: 0, y: 1, label: 'Y' },
|
|
|
|
|
{ id: 'u', kind: 'chip', chip: 'inner', x: 5, y: 0 },
|
|
|
|
|
],
|
|
|
|
|
wires: [{ id: 'w', from: { node: 'x', pin: 'q' }, to: { node: 'u', pin: 'a' } }],
|
|
|
|
|
}
|
|
|
|
|
const root: ComponentDef = {
|
|
|
|
|
id: 'root',
|
|
|
|
|
name: 'Root',
|
|
|
|
|
symbol: 'box',
|
|
|
|
|
nodes: [
|
|
|
|
|
{ id: 's', kind: 'input', x: -4, y: 0 },
|
|
|
|
|
{ id: 'o', kind: 'chip', chip: 'outer', x: 0, y: 0 },
|
|
|
|
|
],
|
|
|
|
|
wires: [{ id: 'v', from: { node: 's', pin: 'q' }, to: { node: 'o', pin: 'x' } }],
|
|
|
|
|
}
|
|
|
|
|
p.components.push(outer, root)
|
|
|
|
|
const get = lookup(p)
|
|
|
|
|
const cands = faceCandidates(outer, get)
|
|
|
|
|
expect(cands.filter(c => c.nested).map(c => c.key)).toEqual(['u/l', 'u/h'])
|
|
|
|
|
const chip = { id: 'o', kind: 'chip' as const, chip: 'outer', x: 0, y: 0 }
|
|
|
|
|
expect(shapeOf(chip, get).face ?? []).toEqual([])
|
|
|
|
|
outer.design = { w: 8, h: 6, show: ['u/l'], scale: { 'u/l': 2 }, rotate: { 'u/l': 90 }, pinAt: { y: 3 } }
|
|
|
|
|
const s = shapeOf(chip, get)
|
|
|
|
|
expect(s.face).toEqual([expect.objectContaining({ id: 'u/l', key: 'u/l', scale: 2, rotate: 90 })])
|
|
|
|
|
// Y was put three rows down, under X: a gap.
|
|
|
|
|
expect(s.inputs.map(i => i.dy)).toEqual([0, 3])
|
|
|
|
|
// The lamp deep inside lights on the outer box when its signal is on.
|
|
|
|
|
const sim = new Simulator(compile(get, 'root'))
|
|
|
|
|
sim.setSource('s', true)
|
|
|
|
|
sim.run()
|
|
|
|
|
expect(sim.face('o', 'u/l', 'a')).toBe(1)
|
|
|
|
|
void inner
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('finding parts', () => {
|
|
|
|
|
it('matches names by start, word, inside, and letters in order', () => {
|
|
|
|
|
expect(matchScore('Adder 4', 'adder 4')).toBeGreaterThan(matchScore('Adder 4', 'add'))
|
|
|
|
|
expect(matchScore('Adder 4', 'add')).toBeGreaterThan(matchScore('Full Adder', 'add'))
|
|
|
|
|
expect(matchScore('Full Adder', 'add')).toBeGreaterThan(matchScore('Ladder', 'add'))
|
|
|
|
|
expect(matchScore('Adder 4', 'adr4')).toBeGreaterThan(0)
|
|
|
|
|
expect(matchScore('Lamp', 'xyz')).toBe(0)
|
|
|
|
|
})
|
|
|
|
|
})
|