A buttons beside the selection, a plug without a cable, bounds on split ports
- Round buttons on the canvas next to what is selected: split a component's connector port into wires or join it (beside each socket), pull a cable out of a plug, plug a cable end in or out, split a cable into single wires, bundle selected wires. - The cable button on a component's pins puts just a plug there. Drag the cable out of its pin (or press Pull the cable out and click): the other end goes where it is let go, and on a part's pins its wires land on them. - A split port's wires on the box are marked off by a line above and below in the connector's colour. - A split plug with no cable yet is named after the pins it drives. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ab47235e38
commit
a29215162c
|
|
@ -17,8 +17,8 @@ Nuxt 4 (client-only editor, `ssr: false`), Tailwind CSS v4, Lucide icons via `@n
|
|||
- Library: everyone's published components in one public list (bottom bar → Components → Library, Space, or the main menu), searchable by name, description and author, each with its transistors, pins and what it uses. "Publish to the library…" in the menu on a circuit's name sends it with every component it uses and their connector types, under your leaderboard name; the server checks it like any project and counts transistors and pins itself. Publishing the same component again from the same browser and project makes the next version of the same entry; only that browser has the entry's edit key, so only it can update or remove it. "Add" brings an entry into the open project and starts placing it: what the project has in exactly that form already is used as it is, the rest comes with new ids (a name that is taken gets a number) and connector types join one with the same lines. The This panel says where a component came from and offers a newer version, which replaces it in place; what came along with the old version goes once nothing else uses it. Another entry's component is never reused, so updating one entry leaves the others as they were. Challenges and puzzles, and components with a solution anywhere inside, are never published. A campaign takes nothing from the library: it is built from your own work. Logic in [app/lib/logic/library.ts](app/lib/logic/library.ts).
|
||||
- Sound (speaker in the top bar; volume and clock ticks in Settings, the gear in the top bar): clicks for placing, wiring, switches and buttons, a tick per clock cycle up to 8 Hz (off by default), and jingles for a solve, a failed check, unlocks and new records. All synthesised with Web Audio, no sound files ([app/lib/audio.ts](app/lib/audio.ts)).
|
||||
- Transistors: every component shows how many it takes, counted as a CMOS NAND (4 transistors) per gate at every depth: in the palette, its settings and the circuit stats. Each challenge keeps your record, the fewest transistors of any passing solution, and says so when you beat it.
|
||||
- Cables: a bundle gathers 2 to 32 wires into one cable, a split fans it out again in the same order; one bundle can feed several splits. Select the wires (a box across them, or Shift + click) and press "Bundle into cable" or Ctrl+G: the cable starts right after the sources on their middle row and ends right before the targets on theirs, so the wires keep running as they did (backwards too); an end steps aside when another part is in the way. "Place the ends yourself…" (Ctrl+Shift+G) lets you click where it starts and ends, with a preview; Esc cancels. "Unlink all" on a bundle or split removes only the wires going in or out; the cable stays. Drag the bundle and split later to move the ends. Up to 16 wires, the cable is drawn as a ribbon: each wire is its own thin line inside, in its own colour, lit while it carries a 1. The sleeve starts neutral and gets its own colour (cable or bundle/split settings). "Remove cable" turns it back into single wires. A cable end only joins another cable end, and the cable shows its width.
|
||||
- Connectors (your own HDMI, RJ45, buses): in the bottom bar's Connectors, "New connector type" makes one: a name, a colour, and lines that each run out → in or back (acknowledge, hot-plug, a receive pair). Each type gives two parts, "<type> out" and "<type> in". Inside a component, a port shows its lines as pins on its inner side (lines coming in are outputs, lines going out inputs) and has a cable pin at the top to hand the whole cable on to a part inside; on the component's box it is one port at the very top of its side, in ports on the left, out ports on the right, drawn as a socket in the type's colour. "Split … into lines" (selection panel or right click on the component) gives that box a pin per line right below the socket, named after the line, to wire lines by hand without an adapter: lines going into the component are inputs, lines coming out outputs, and a cable still plugs into the socket. Dropping a single wire on a socket does the same and takes the first free line (with a cable in the socket, only a line coming out: the cable feeds the others). "Join … lines" takes the line pins and their wires away again. One cable joins an out port to an in port of the same type and carries every line, forward and back; it is drawn as a sleeve in the type's colour with its name. Ports of different types never join, and a cable whose ends stop matching (a port changed type) is removed. Editing a type changes every port and cable of it; lines are matched by their place in the list. A type can only be deleted once no port uses it.
|
||||
- Cables: a bundle gathers 2 to 32 wires into one cable, a split fans it out again in the same order; one bundle can feed several splits. Select the wires (a box across them, or Shift + click) and press "Bundle into cable" or Ctrl+G: the cable starts right after the sources on their middle row and ends right before the targets on theirs, so the wires keep running as they did (backwards too); an end steps aside when another part is in the way. "Place the ends yourself…" (Ctrl+Shift+G) lets you click where it starts and ends, with a preview; Esc cancels. "Unlink all" on a bundle or split removes only the wires going in or out; the cable stays. Drag the bundle and split later to move the ends. Up to 16 wires, the cable is drawn as a ribbon: each wire is its own thin line inside, in its own colour, lit while it carries a 1. The sleeve starts neutral and gets its own colour (cable or bundle/split settings). "Remove cable" turns it back into single wires. A cable end only joins another cable end, and the cable shows its width. The cable button beside a selected component's outputs or inputs puts just a plug on those pins (pick the group when there are several); drag the cable out of the plug's cable pin, or press its "Pull the cable out" button and click: its other end goes where you let go, and let go on a part's pins its wires land on them from that pin down. Round buttons beside the selection do the everyday things in place: split a port into wires and join them again, pull a cable out of a plug, plug a cable end in or out, split a selected cable into single wires, bundle selected wires.
|
||||
- Connectors (your own HDMI, RJ45, buses): in the bottom bar's Connectors, "New connector type" makes one: a name, a colour, and lines that each run out → in or back (acknowledge, hot-plug, a receive pair). Each type gives two parts, "<type> out" and "<type> in". Inside a component, a port shows its lines as pins on its inner side (lines coming in are outputs, lines going out inputs) and has a cable pin at the top to hand the whole cable on to a part inside; on the component's box it is one port at the very top of its side, in ports on the left, out ports on the right, drawn as a socket in the type's colour. "Split … into lines" (selection panel or right click on the component) gives that box a pin per line right below the socket, named after the line, to wire lines by hand without an adapter: lines going into the component are inputs, lines coming out outputs, and a cable still plugs into the socket. Dropping a single wire on a socket does the same and takes the first free line (with a cable in the socket, only a line coming out: the cable feeds the others). "Join … lines" takes the line pins and their wires away again. On the box a line in the type's colour runs above and below a split port's wires, so it is clear which pins belong to it; a round button beside each socket splits or joins it. One cable joins an out port to an in port of the same type and carries every line, forward and back; it is drawn as a sleeve in the type's colour with its name. Ports of different types never join, and a cable whose ends stop matching (a port changed type) is removed. Editing a type changes every port and cable of it; lines are matched by their place in the list. A type can only be deleted once no port uses it.
|
||||
- Pixels and screens: a pixel is a one-grid square that lights at 1, in five colours. Inside a component all pixels show on its box as one screen without gaps (every column and row they sit on becomes one of the screen), so you build your own LCD; see "Screen 4×4" and "Demo: Screen".
|
||||
- Input panel: one part with a column of controls; each row is a switch, button or clock. "Attach input panel" on a placed component docks one to its left with a row per free input, lined up with the pins and named after them. A docked panel moves with its component, gets a row when the component gains an input and loses it when the pin goes; inputs that are wired elsewhere, and rows you remove, are left alone. Inside a component a switch row keeps its position and a button row is 0.
|
||||
- Automatic names: copies continue a series (D0 copied gives D1, D2; A gives B), and so does placing a new input or output after a numbered one. A switch, button, lamp or output pin without a name of its own (or with an automatic one) takes the name of the component pin it gets wired to, made unique (Cin, Cin2); a name typed by hand is kept. On the canvas, a switch, button, clock, lamp or output pin without a name typed by hand shows the name of the component pin it is wired to, dimmed and in italics (or its automatic name, also dimmed); the name follows the wiring as it changes.
|
||||
|
|
|
|||
|
|
@ -1073,11 +1073,26 @@ kbd {
|
|||
.node .face-text.ink-green { fill: #3ddc84; }
|
||||
.node .face-text.ink-blue { fill: #4dabff; }
|
||||
|
||||
/* Cable buttons beside a selected part's pins. */
|
||||
/* Buttons beside the selection: cables onto pins, ports split, plugs in and out. */
|
||||
.cable-btn {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.cable-btn foreignObject {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.cable-btn-icon {
|
||||
display: block;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.cable-btn:hover .cable-btn-icon {
|
||||
color: #0e1116;
|
||||
}
|
||||
|
||||
.cable-btn circle {
|
||||
fill: var(--panel-2);
|
||||
stroke: var(--accent);
|
||||
|
|
@ -4531,6 +4546,15 @@ table.board {
|
|||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Above and below a split port's wires: which pins belong to it. */
|
||||
.port-bounds {
|
||||
fill: none;
|
||||
stroke-width: 1.5;
|
||||
stroke-linecap: round;
|
||||
opacity: 0.8;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.wire.port-cable .cable-sleeve {
|
||||
stroke: var(--w-on, #8592a3);
|
||||
opacity: 0.9;
|
||||
|
|
|
|||
|
|
@ -423,23 +423,111 @@ function onDragLeave(e: DragEvent) {
|
|||
if (!root.value?.contains(e.relatedTarget as Node | null)) cursor.value = null
|
||||
}
|
||||
|
||||
// ── Cable buttons on a selected part ────────────────────────────────
|
||||
// ── Buttons beside what is selected ─────────────────────────────────
|
||||
/** A round button on the canvas next to the selection, for what is done most with it. */
|
||||
interface ActionButton {
|
||||
key: string
|
||||
x: number
|
||||
y: number
|
||||
title: string
|
||||
/** A lucide icon, or else the cable mark (mirrored with `flip`). */
|
||||
icon?: string
|
||||
flip?: boolean
|
||||
run: (e: PointerEvent) => void
|
||||
}
|
||||
|
||||
/** The cable that a cable end belongs to, when it has one (a bundle with a split behind it). */
|
||||
function cableOfEnd(n: CircuitNode): CircuitNode | undefined {
|
||||
const w = def.value.wires.find(x => (n.kind === 'bundle' ? x.from.node === n.id : x.to.node === n.id && x.to.pin === 'a'))
|
||||
const bundle = w && nodeMap.value.get(w.from.node)
|
||||
if (bundle?.kind !== 'bundle') return undefined
|
||||
return def.value.wires.some(x => x.from.node === bundle.id && nodeMap.value.get(x.to.node)?.kind === 'split') ? bundle : undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* One selected component (or panel, or hex display) gets a cable button
|
||||
* beside its outputs and its inputs: a cable straight onto those pins.
|
||||
* Buttons beside the selection. A component (or panel, or hex display): a
|
||||
* cable onto its outputs and its inputs, and each connector port split into
|
||||
* its wires or joined again. A cable end: plug in or out, take the cable
|
||||
* apart. A cable: take it apart. Several wires: bundle them into a cable.
|
||||
*/
|
||||
const cableButtons = computed(() => {
|
||||
if (drag.value || ed.selection.value.length !== 1 || ed.linking.value || ed.placing.value) return []
|
||||
const n = nodeMap.value.get(ed.selection.value[0]!)
|
||||
if (!n) return []
|
||||
const choices = ed.cableChoices(n)
|
||||
const s = shapes.value.get(n.id)!
|
||||
const out: { side: 'out' | 'in'; x: number; y: number }[] = []
|
||||
const mid = (ps: { dy: number }[]) => (Math.min(...ps.map(p => p.dy)) + Math.max(...ps.map(p => p.dy))) / 2
|
||||
const outs = s.outputs.filter(p => !p.bus)
|
||||
const ins = s.inputs.filter(p => !p.bus)
|
||||
if (choices.out.length && outs.length) out.push({ side: 'out', x: n.x + Math.max(...outs.map(p => p.dx)) + 1.3, y: n.y + mid(outs) })
|
||||
if (choices.in.length && ins.length) out.push({ side: 'in', x: n.x + Math.min(...ins.map(p => p.dx)) - 1.3, y: n.y + mid(ins) })
|
||||
const actionButtons = computed<ActionButton[]>(() => {
|
||||
if (drag.value || ed.linking.value || ed.placing.value || ed.cabling.value) return []
|
||||
const out: ActionButton[] = []
|
||||
const sel = ed.selection.value
|
||||
const n = sel.length === 1 && !ed.wireSel.value.length ? nodeMap.value.get(sel[0]!) : undefined
|
||||
if (n) {
|
||||
const s = shapes.value.get(n.id)!
|
||||
// Connector ports: beside the socket, out of the box.
|
||||
for (const p of [...s.inputs, ...s.outputs]) {
|
||||
if (!p.conn || n.kind !== 'chip') continue
|
||||
const split = !!n.splitPorts?.includes(p.key)
|
||||
out.push({
|
||||
key: `port:${p.key}`,
|
||||
x: n.x + p.dx + (p.dx === 0 ? -1.3 : 1.3),
|
||||
y: n.y + p.dy,
|
||||
title: split ? `Join the ${p.label} wires back into its socket` : `Split ${p.label} into wires`,
|
||||
icon: split ? 'lucide:merge' : 'lucide:split',
|
||||
run: () => ed.toggleSplit(n, p.key),
|
||||
})
|
||||
}
|
||||
const choices = ed.cableChoices(n)
|
||||
const mid = (ps: { dy: number }[]) => (Math.min(...ps.map(p => p.dy)) + Math.max(...ps.map(p => p.dy))) / 2
|
||||
const outs = s.outputs.filter(p => !p.bus && p.face !== -1)
|
||||
const ins = s.inputs.filter(p => !p.bus && p.face !== 1)
|
||||
// Clear of a port's button on the same edge.
|
||||
const clear = (x: number, y: number) => {
|
||||
while (out.some(b => b.x === x && Math.abs(b.y - y) < 1.2)) y += 0.5
|
||||
return y
|
||||
}
|
||||
if (choices.out.length && outs.length) {
|
||||
const x = n.x + Math.max(...outs.map(p => p.dx)) + 1.3
|
||||
out.push({ key: 'cable:out', x, y: clear(x, n.y + mid(outs)), title: 'A cable plug on these outputs', run: e => onCableButton('out', e) })
|
||||
}
|
||||
if (choices.in.length && ins.length) {
|
||||
const x = n.x + Math.min(...ins.map(p => p.dx)) - 1.3
|
||||
out.push({ key: 'cable:in', x, y: clear(x, n.y + mid(ins)), title: 'A cable plug on these inputs', flip: true, run: e => onCableButton('in', e) })
|
||||
}
|
||||
if (n.kind === 'bundle' || n.kind === 'split') {
|
||||
// On the cable's side of the end, clear of its cable pin: pull a cable out, plug in or out, take the cable apart.
|
||||
const ends: Omit<ActionButton, 'x' | 'y'>[] = []
|
||||
const bus = n.kind === 'bundle' ? { pin: 'q', dir: 'out' as const } : { pin: 'a', dir: 'in' as const }
|
||||
if (pullable({ node: n.id, ...bus }) && !linked.value[bus.dir].has(`${n.id}:${bus.pin}`)) {
|
||||
ends.push({
|
||||
key: 'pull',
|
||||
title: 'Pull the cable out: click where its other end goes (or drag it out of its pin)',
|
||||
icon: 'lucide:cable',
|
||||
run: () => (ed.linking.value = { queue: [{ node: n.id, ...bus, label: '' }], at: 0 }),
|
||||
})
|
||||
}
|
||||
if (n.plug) ends.push({ key: 'unplug', title: 'Unplug: it steps aside and its wires show again', icon: 'lucide:unplug', run: () => ed.unplugEnd(n) })
|
||||
else if (ed.plugTarget(n)) ends.push({ key: 'plug', title: 'Plug straight onto the pins its wires run to', icon: 'lucide:plug', run: () => ed.plugEnd(n) })
|
||||
const cable = cableOfEnd(n)
|
||||
if (cable) ends.push({ key: 'apart', title: 'Split the cable into single wires', icon: 'lucide:split', run: () => ed.removeCable(cable.id) })
|
||||
const x = n.kind === 'bundle' ? n.x + s.body.x + s.body.w + 1 : n.x + s.body.x - 1
|
||||
const busY = n.y + (n.kind === 'bundle' ? s.outputs : s.inputs).find(p => p.bus)!.dy
|
||||
// From its top row down, stepping over the cable pin's row.
|
||||
let y = n.y + s.body.y + 0.5
|
||||
for (const b of ends) {
|
||||
if (Math.abs(y - busY) < 0.9) y = busY + 1
|
||||
out.push({ ...b, x, y })
|
||||
y += 1.2
|
||||
}
|
||||
}
|
||||
}
|
||||
// Wires: a cable can be taken apart, several single wires bundled.
|
||||
const wires = sel.length ? [] : routes.value.filter(r => wireSelected.value.has(r.wire.id))
|
||||
// Above the middle of the topmost one.
|
||||
const at = (rs: Route[]) => {
|
||||
const ps = rs.map(r => midOfLongest(r.pts)).filter(p => !!p)
|
||||
return ps.length ? { x: ps.reduce((a, p) => a + p[0], 0) / ps.length, y: Math.min(...ps.map(p => p[1])) - 1.2 } : null
|
||||
}
|
||||
const cable = wires.length === 1 && wires[0]!.bits ? nodeMap.value.get(wires[0]!.wire.from.node) : undefined
|
||||
const singles = wires.filter(r => !r.bits)
|
||||
const spot = at(wires)
|
||||
if (cable && spot) out.push({ key: 'apart', ...spot, title: 'Split the cable into single wires', icon: 'lucide:split', run: () => ed.removeCable(cable.id) })
|
||||
else if (singles.length >= 2 && singles.length === wires.length && spot) {
|
||||
out.push({ key: 'bundle', ...spot, title: `Bundle the ${singles.length} wires into a cable (Ctrl+G)`, run: () => ed.bundleSelected(singles.map(r => r.wire.id)) })
|
||||
}
|
||||
return out
|
||||
})
|
||||
|
||||
|
|
@ -454,7 +542,7 @@ function onCableButton(side: 'out' | 'in', e: PointerEvent) {
|
|||
x: e.clientX + 6,
|
||||
y: e.clientY + 6,
|
||||
entries: [
|
||||
{ head: side === 'out' ? 'Cable from outputs' : 'Cable into inputs' },
|
||||
{ head: side === 'out' ? 'Plug on outputs' : 'Plug on inputs' },
|
||||
...groups.map(g => ({ label: g.label, note: `${g.pins.length} wires`, icon: side === 'out' ? 'lucide:merge' : 'lucide:split', run: () => run(g.pins) })),
|
||||
],
|
||||
}
|
||||
|
|
@ -552,6 +640,12 @@ function onPointerDown(e: PointerEvent) {
|
|||
const socket = socketAt({ ...end, cur: w })
|
||||
const target = socket ? ed.lineAt(end.dir, socket.node, socket.port) : targetAt(w, end.dir === 'out' ? 'in' : 'out', ed.pinKind(end.node, end.pin, end.dir))
|
||||
if (target) return ed.linkTo(target, e.shiftKey)
|
||||
// A cable pulled out of a cable end: its other end goes where the click is.
|
||||
const pulled = link.queue.length === 1 ? pullEnd({ ...end, cur: w }) : null
|
||||
if (pulled) {
|
||||
ed.stopLinking()
|
||||
return ed.pullCable(end.node, pulled.x, pulled.y, pulled.links)
|
||||
}
|
||||
const pinEl = (e.target as Element).closest('[data-pin]')
|
||||
if (pinEl && link.queue.length === 1) {
|
||||
// Another pin of the same kind: start from that one instead.
|
||||
|
|
@ -581,8 +675,8 @@ function onPointerDown(e: PointerEvent) {
|
|||
}
|
||||
|
||||
const target = e.target as Element
|
||||
const cableEl = target.closest('[data-cable]')
|
||||
if (cableEl) return onCableButton(cableEl.getAttribute('data-cable') as 'out' | 'in', e)
|
||||
const actionEl = target.closest('[data-action]')
|
||||
if (actionEl) return actionButtons.value.find(b => b.key === actionEl.getAttribute('data-action'))?.run(e)
|
||||
const widenEl = target.closest('[data-inputs]')
|
||||
if (widenEl) {
|
||||
// + or − under a selected gate: one input more or less.
|
||||
|
|
@ -859,6 +953,38 @@ function nodeAt(at: Pt): CircuitNode | undefined {
|
|||
return undefined
|
||||
}
|
||||
|
||||
/** The cable pin of a cable end that a cable can be pulled out of: a bundle's always, a split's while it has no cable. */
|
||||
function pullable(d: { node: string; pin: string; dir: 'in' | 'out' }): CircuitNode | undefined {
|
||||
const n = nodeMap.value.get(d.node)
|
||||
if (!n || ed.pinKind(d.node, d.pin, d.dir) !== 'bus') return undefined
|
||||
if (n.kind === 'bundle' || (n.kind === 'split' && !linked.value.in.has(`${n.id}:a`))) return n
|
||||
return undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the other end of a cable pulled out of a cable end goes when let
|
||||
* go at `cur`: over a part's pins (or its body), its wires land on them
|
||||
* from the pin under the mouse on; elsewhere its cable pin is at the mouse.
|
||||
*/
|
||||
function pullEnd(d: { node: string; pin: string; dir: 'in' | 'out'; cur: Pt }): { x: number; y: number; links: Link[] } | null {
|
||||
const from = pullable(d)
|
||||
if (!from) return null
|
||||
const end: CircuitNode = { id: 'ghost', kind: from.kind === 'bundle' ? 'split' : 'bundle', bits: cableBits(from), x: 0, y: 0 }
|
||||
const s = ed.shape(end)
|
||||
const wires = end.kind === 'split' ? s.outputs : s.inputs
|
||||
const pin = targetAt(d.cur, end.kind === 'split' ? 'in' : 'out')
|
||||
const host = pin && nodeMap.value.get(pin.node)
|
||||
const at = host && pinPos(host, shapes.value.get(host.id)!, pin.pin, end.kind === 'split' ? 'in' : 'out')
|
||||
if (at) {
|
||||
end.x = at.x - wires[0]!.dx
|
||||
end.y = at.y - wires[0]!.dy
|
||||
const links = (dropLinks(dropPins(def.value, [end], () => s), allPins.value, 0)?.links ?? []).filter(l => [l.from, l.to].some(r => r.node === 'ghost' && r.pin !== 'a' && r.pin !== 'q'))
|
||||
if (links.length) return { x: end.x, y: end.y, links }
|
||||
}
|
||||
const bus = end.kind === 'split' ? s.inputs[0]! : s.outputs[0]!
|
||||
return { x: Math.round(d.cur[0]) - bus.dx, y: Math.round(d.cur[1]) - bus.dy, links: [] }
|
||||
}
|
||||
|
||||
/**
|
||||
* Where a wire would go: a pin of the wanted direction close to the point,
|
||||
* else, over a part, that part's first free pin (or its nearest one when
|
||||
|
|
@ -965,6 +1091,12 @@ function onPointerUp(e: PointerEvent) {
|
|||
}
|
||||
const onWire = wireDrop(d)
|
||||
const target = targetAt(d.cur, d.dir === 'out' ? 'in' : 'out', ed.pinKind(d.node, d.pin, d.dir)) ?? onWire?.pin
|
||||
if (!target && !d.replace && !d.branch) {
|
||||
// A cable pulled out of a cable end: its other end goes where it is let go.
|
||||
const end = pullEnd(d)
|
||||
if (end) ed.pullCable(d.node, end.x, end.y, end.links)
|
||||
break
|
||||
}
|
||||
if (!target) break
|
||||
if (d.replace) {
|
||||
ed.rewire(d.replace, d.dir === 'out' ? here : target, d.dir === 'out' ? target : here)
|
||||
|
|
@ -1265,6 +1397,15 @@ const targets = computed(() => {
|
|||
}
|
||||
// A single wire can go onto a port's socket too: the port splits into its lines.
|
||||
if (!bus) for (const s of openSockets.value[want]) out.push({ x: s.x, y: s.y, free: true })
|
||||
// A cable pulled out of a cable end can also be let go on free single pins: its other end lands on them.
|
||||
if (pullable(d)) {
|
||||
for (const n of def.value.nodes) {
|
||||
const s = shapes.value.get(n.id)!
|
||||
for (const p of want === 'in' ? s.inputs : s.outputs) {
|
||||
if (!pinKindOf(p) && (want === 'out' || !taken.has(`${n.id}:${p.key}`))) out.push({ x: n.x + p.dx, y: n.y + p.dy, free: true })
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
})
|
||||
|
||||
|
|
@ -1707,15 +1848,16 @@ defineExpose({ fit, zoomAt })
|
|||
</g>
|
||||
<circle v-for="(p, i) in dropRings" :key="`d${i}`" :cx="p.x * G" :cy="p.y * G" r="7" class="drop-ring" />
|
||||
<g
|
||||
v-for="c in cableButtons"
|
||||
:key="c.side"
|
||||
v-for="b in actionButtons"
|
||||
:key="b.key"
|
||||
class="cable-btn"
|
||||
:data-cable="c.side"
|
||||
:transform="`translate(${c.x * G} ${c.y * G})${c.side === 'in' ? ' scale(-1 1)' : ''}`"
|
||||
:data-action="b.key"
|
||||
:transform="`translate(${b.x * G} ${b.y * G})${b.flip ? ' scale(-1 1)' : ''}`"
|
||||
>
|
||||
<title>{{ c.side === 'out' ? 'Cable from these outputs' : 'Cable into these inputs' }}</title>
|
||||
<title>{{ b.title }}</title>
|
||||
<circle r="9" />
|
||||
<path d="M-4.5 -4.5L1.5 0M-4.5 0H1.5M-4.5 4.5L1.5 0M1.5 0H5" />
|
||||
<foreignObject v-if="b.icon" x="-6" y="-6" width="12" height="12"><Icon :name="b.icon" class="cable-btn-icon" /></foreignObject>
|
||||
<path v-else d="M-4.5 -4.5L1.5 0M-4.5 0H1.5M-4.5 4.5L1.5 0M1.5 0H5" />
|
||||
</g>
|
||||
|
||||
<g class="targets">
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ const SHORTCUTS: [string, string][] = [
|
|||
['Connectors (bottom bar)', 'Make a cable type of your own (HDMI, RJ45): its lines; place its Out and In ports; one cable joins them'],
|
||||
['Split into lines (right-click a component)', 'A pin per line below a port\'s socket, to wire lines by hand; dropping a wire on the socket does the same. Join lines takes them away'],
|
||||
['Select wires, Ctrl+G', 'Bundle them into one cable; an end whose wires all meet one part plugs straight into it'],
|
||||
['Select a component, cable button beside its pins', 'A cable plugged onto S0–S3 (or any group); drop its free end on the next part\'s pins'],
|
||||
['Select a component, cable button beside its pins', 'A plug on S0–S3 (or any group); drag the cable out of its pin and let go where it goes, or on the next part\'s pins'],
|
||||
['Round buttons beside the selection', 'Split a port into wires (or join them), pull a cable out of a plug, plug in or out, split a cable into wires, bundle selected wires'],
|
||||
['Drag a part from the list onto pins', 'It lands on them and connects (green rings show where); Alt just places it'],
|
||||
['Drag a part onto the pins it is wired to', 'When its pins line up with theirs one for one, it latches on (green rings): pins touching, no wires, and it moves with that part. Right-click: Latch onto / Unlatch'],
|
||||
['Drag a plugged cable end away', 'Pull it out; drop its pins on a part\'s pins to plug it in again'],
|
||||
|
|
|
|||
|
|
@ -190,14 +190,20 @@ function openMore(e: MouseEvent) {
|
|||
more.value = { x: r.right - 220, y: r.bottom + 4, entries: menu.build({ kind: 'selection' }, { fit: () => {}, place: () => {} }) }
|
||||
}
|
||||
|
||||
/** The bundle of the cable this bundle or split belongs to. */
|
||||
/** The bundle of the cable this bundle or split belongs to: none for a plug whose cable isn't pulled out yet. */
|
||||
const cableBundle = computed(() => {
|
||||
if (n.value.kind === 'bundle') return n.value
|
||||
if (n.value.kind !== 'split') return undefined
|
||||
const feed = ed.def.value.wires.find(w => w.to.node === n.value.id)
|
||||
return feed ? cableOf(ed.def.value, feed) : undefined
|
||||
const d = ed.def.value
|
||||
const bundle =
|
||||
n.value.kind === 'bundle' ? n.value : n.value.kind === 'split' ? (w => (w ? cableOf(d, w) : undefined))(d.wires.find(w => w.to.node === n.value.id)) : undefined
|
||||
return bundle && d.wires.some(w => w.from.node === bundle.id && w.from.pin === 'q') ? bundle : undefined
|
||||
})
|
||||
|
||||
/** Starts the cable out of a plug that has none: the next click puts its other end. */
|
||||
function pullOut() {
|
||||
const bus = n.value.kind === 'bundle' ? { pin: 'q', dir: 'out' as const } : { pin: 'a', dir: 'in' as const }
|
||||
ed.linking.value = { queue: [{ node: n.value.id, ...bus, label: '' }], at: 0 }
|
||||
}
|
||||
|
||||
const sleeveColor = computed(() => (cableBundle.value ? ed.def.value.wires.find(w => w.from.node === cableBundle.value!.id)?.color : undefined))
|
||||
|
||||
/** Connector ports on the component's box: each one can show its lines as pins on this box. */
|
||||
|
|
@ -628,6 +634,9 @@ function setRowHz(row: PanelRow, e: Event) {
|
|||
<button v-else-if="plugPart" class="btn mb-2 w-full" :title="`Sit straight on the pins of ${partName(plugPart.id)}, without wires in between`" @click="ed.plugEnd(n)">
|
||||
<Icon name="lucide:plug" class="size-4" /> Plug into {{ partName(plugPart.id) }}
|
||||
</button>
|
||||
<button v-if="!cableBundle" class="btn btn-primary mb-2 w-full" title="Click where its other end goes, or drag the cable out of its pin" @click="pullOut">
|
||||
<Icon name="lucide:cable" class="size-4" /> Pull the cable out
|
||||
</button>
|
||||
<div class="sel-row">
|
||||
<label class="field grow">
|
||||
<span>Wires</span>
|
||||
|
|
@ -716,11 +725,11 @@ function setRowHz(row: PanelRow, e: Event) {
|
|||
<span>Plug a cable onto its pins</span>
|
||||
<div v-if="cables.out.length" class="cable-row">
|
||||
<span class="hint">From outputs</span>
|
||||
<button v-for="g in cables.out" :key="g.label" class="btn-sm" :title="`A cable with ${g.pins.length} wires out of these pins`" @click="ed.cableOut(n.id, g.pins)">{{ g.label }}</button>
|
||||
<button v-for="g in cables.out" :key="g.label" class="btn-sm" :title="`A plug for a cable with ${g.pins.length} wires on these pins`" @click="ed.cableOut(n.id, g.pins)">{{ g.label }}</button>
|
||||
</div>
|
||||
<div v-if="cables.in.length" class="cable-row">
|
||||
<span class="hint">Into inputs</span>
|
||||
<button v-for="g in cables.in" :key="g.label" class="btn-sm" :title="`A cable with ${g.pins.length} wires into these pins`" @click="ed.cableIn(n.id, g.pins)">{{ g.label }}</button>
|
||||
<button v-for="g in cables.in" :key="g.label" class="btn-sm" :title="`A plug for a cable with ${g.pins.length} wires on these pins`" @click="ed.cableIn(n.id, g.pins)">{{ g.label }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="chipInputs || chipOutputs" class="field mb-0">
|
||||
|
|
|
|||
|
|
@ -133,16 +133,31 @@ const boxLabels = computed(() =>
|
|||
}),
|
||||
)
|
||||
|
||||
/** Split ports on a component's box: a bar in the type's colour from the socket down along its lines. */
|
||||
/**
|
||||
* Split ports on a component's box, in the type's colour: a bar from the
|
||||
* socket down along its lines, and a line above and below them that marks
|
||||
* off which pins are its wires, from the pin tips to past their names.
|
||||
*/
|
||||
const portBars = computed(() => {
|
||||
const pins = [...props.shape.inputs, ...props.shape.outputs]
|
||||
return pins.flatMap(p => {
|
||||
const lines = p.conn ? pins.filter(l => l.port === p.key) : []
|
||||
if (!lines.length) return []
|
||||
// From the socket's inner corner, down between the line pins and their names.
|
||||
const inward = p.dx === 0 ? 1 : -1
|
||||
const x = p.dx * G
|
||||
return [{ key: p.key, conn: p.conn, d: `M${x + inward * 4} ${p.dy * G + 5}H${x + inward * 7}V${Math.max(...lines.map(l => l.dy)) * G + 3}` }]
|
||||
const top = (Math.min(...lines.map(l => l.dy)) - 0.5) * G
|
||||
const bottom = (Math.max(...lines.map(l => l.dy)) + 0.5) * G
|
||||
const outer = x - inward * 9
|
||||
const inner = x + inward * Math.min(15 + Math.max(...lines.map(l => l.label.length)) * 5.6, (props.shape.body.w * G) / 2)
|
||||
return [
|
||||
{
|
||||
key: p.key,
|
||||
conn: p.conn,
|
||||
// From the socket's inner corner, down between the line pins and their names.
|
||||
bar: `M${x + inward * 4} ${p.dy * G + 5}H${x + inward * 7}V${bottom}`,
|
||||
bounds: `M${outer} ${top}H${inner}M${outer} ${bottom}H${inner}`,
|
||||
},
|
||||
]
|
||||
})
|
||||
})
|
||||
|
||||
|
|
@ -249,7 +264,10 @@ const title = computed(() => {
|
|||
</template>
|
||||
<text v-if="f.label" :x="(f.x + f.w / 2) * G" :y="(f.y + f.h - 0.15) * G" text-anchor="middle" class="face-label">{{ f.label }}</text>
|
||||
</g>
|
||||
<path v-for="g in portBars" :key="`bar-${g.key}`" :d="g.d" class="port-bar" :style="{ stroke: connColor(g.conn) }" />
|
||||
<template v-for="g in portBars" :key="`bar-${g.key}`">
|
||||
<path :d="g.bar" class="port-bar" :style="{ stroke: connColor(g.conn) }" />
|
||||
<path :d="g.bounds" class="port-bounds" :style="{ stroke: connColor(g.conn) }" />
|
||||
</template>
|
||||
<text v-for="p in boxLabels" :key="p.key" :x="p.x" :y="p.y" :text-anchor="p.anchor" class="pin-label">{{ p.label }}</text>
|
||||
</template>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
import { nandCounts, runSteps, stats, tableCsv, TRANSISTORS_PER_NAND, truthTable, type Stats, type TestResult, type TruthTable } from '~/lib/logic/analyze'
|
||||
import {
|
||||
bundleWires,
|
||||
cableEnd,
|
||||
cableFromPins,
|
||||
cableIntoPins,
|
||||
cablePanel,
|
||||
|
|
@ -1233,7 +1234,7 @@ function create() {
|
|||
/**
|
||||
* A cable from some of a part's outputs. When each of them already has
|
||||
* one wire, those wires go into the cable (both ends plug in where they
|
||||
* can); otherwise a new cable starts there with a free end.
|
||||
* can); otherwise just a plug goes on the pins, its cable pulled out by hand.
|
||||
*/
|
||||
function cableOut(nodeId: string, pins: string[]) {
|
||||
const wires = def.value.wires.filter(w => w.from.node === nodeId && pins.includes(w.from.pin))
|
||||
|
|
@ -1242,22 +1243,37 @@ function create() {
|
|||
if (wires.length >= 2 && pins.every(p => per.get(p) === 1)) return bundleSelected(wires.map(w => w.id))
|
||||
const res = cableFromPins(def.value, nodeId, pins, getDef.value)
|
||||
if (!res.ok) return notify(res.error, 'error')
|
||||
selection.value = [res.split.id]
|
||||
selection.value = [res.bundle.id]
|
||||
wireSel.value = []
|
||||
commit()
|
||||
notify(`Cable with ${res.split.bits} wires: drag its free end onto the pins where they go`)
|
||||
notify(`Plug with ${res.bundle.bits} wires: drag the cable out of its pin to where they go`)
|
||||
}
|
||||
|
||||
/** A cable into some of a part's inputs: their wires go into it when they all have one, else a new cable into the free ones. */
|
||||
/** A cable into some of a part's inputs: their wires go into it when they all have one, else a plug on the free ones. */
|
||||
function cableIn(nodeId: string, pins: string[]) {
|
||||
const wires = def.value.wires.filter(w => w.to.node === nodeId && pins.includes(w.to.pin))
|
||||
if (wires.length >= 2 && wires.length === pins.length) return bundleSelected(wires.map(w => w.id))
|
||||
const res = cableIntoPins(def.value, nodeId, pins, getDef.value)
|
||||
if (!res.ok) return notify(res.error, 'error')
|
||||
selection.value = [res.bundle.id]
|
||||
selection.value = [res.split.id]
|
||||
wireSel.value = []
|
||||
commit()
|
||||
notify(`Cable with ${res.bundle.bits} wires: drag its free end next to what drives them, or attach an input panel`)
|
||||
notify(`Plug with ${res.split.bits} wires: drag the cable out of its pin to what drives them`)
|
||||
}
|
||||
|
||||
/**
|
||||
* A cable pulled out of a cable end and dropped at `x`, `y`: its other end
|
||||
* goes there, wired to the pins it was dropped on (`links`, from 'ghost').
|
||||
*/
|
||||
function pullCable(endId: string, x: number, y: number, links: Link[] = []) {
|
||||
const end = cableEnd(def.value, endId, x, y)
|
||||
if (!end) return
|
||||
const swap = (r: PinRef) => (r.node === 'ghost' ? { node: end.id, pin: r.pin } : r)
|
||||
const made = links.filter(l => addWire(swap(l.from), swap(l.to))).length
|
||||
selection.value = [end.id]
|
||||
wireSel.value = []
|
||||
commit()
|
||||
play(made ? 'connect' : 'place')
|
||||
}
|
||||
|
||||
function addCablePanel(bundleId: string) {
|
||||
|
|
@ -2611,6 +2627,7 @@ function create() {
|
|||
cableChoices,
|
||||
cableOut,
|
||||
cableIn,
|
||||
pullCable,
|
||||
linking,
|
||||
startLinking,
|
||||
linkTo,
|
||||
|
|
|
|||
|
|
@ -244,14 +244,14 @@ export function useMenu() {
|
|||
if (cables.out.length || cables.in.length) out.push('sep')
|
||||
if (cables.out.length) {
|
||||
out.push({
|
||||
label: 'Cable from outputs',
|
||||
label: 'Cable plug on outputs',
|
||||
icon: 'lucide:merge',
|
||||
children: cables.out.map(g => ({ label: g.label, note: `${g.pins.length} wires`, run: () => ed.cableOut(n.id, g.pins) })),
|
||||
})
|
||||
}
|
||||
if (cables.in.length) {
|
||||
out.push({
|
||||
label: 'Cable into inputs',
|
||||
label: 'Cable plug on inputs',
|
||||
icon: 'lucide:split',
|
||||
children: cables.in.map(g => ({ label: g.label, note: `${g.pins.length} wires`, run: () => ed.cableIn(n.id, g.pins) })),
|
||||
})
|
||||
|
|
|
|||
|
|
@ -248,7 +248,20 @@ function syncNames(def: ComponentDef, nodes: Map<string, CircuitNode>, get: DefL
|
|||
}
|
||||
}
|
||||
}
|
||||
for (const n of def.nodes) if (n.kind === 'split' && !named.has(n.id)) delete n.names
|
||||
// A split with no bundle behind it (a plug waiting for its cable) is named after what its wires drive.
|
||||
for (const n of def.nodes) {
|
||||
if (n.kind !== 'split' || named.has(n.id)) continue
|
||||
const names = Array.from({ length: cableBits(n) }, (_, i) => {
|
||||
for (const w of def.wires) {
|
||||
if (w.from.node !== n.id || w.from.pin !== `b${i}`) continue
|
||||
const t = nodes.get(w.to.node)
|
||||
const name = t ? targetName(t, w.to.pin, get) : ''
|
||||
if (name) return name
|
||||
}
|
||||
return ''
|
||||
})
|
||||
setNames(n, names)
|
||||
}
|
||||
// Rows of a free panel that feed a cable show the wire's name until they get their own.
|
||||
for (const w of def.wires) {
|
||||
const b = nodes.get(w.to.node)
|
||||
|
|
@ -478,25 +491,12 @@ export function pinGroups(pins: { key: string; label: string }[], usable: (key:
|
|||
return out.filter(g => g.pins.length <= MAX_BITS)
|
||||
}
|
||||
|
||||
/** The first spot along the row from `x` (by `step`) where a cable end of `h` rows fits. */
|
||||
function clearSpot(def: ComponentDef, get: DefLookup, x: number, y: number, h: number, step: 1 | -1): number {
|
||||
const boxes = def.nodes.map(n => {
|
||||
const b = shapeOf(n, get).body
|
||||
return { x: n.x + b.x, y: n.y + b.y, w: b.w, h: b.h }
|
||||
})
|
||||
for (let i = 0; i < 20; i++) {
|
||||
const cx = x + i * step
|
||||
if (!boxes.some(b => cx - 0.5 < b.x + b.w && cx + 1.5 > b.x && y - 1 < b.y + b.h && y + h > b.y)) return cx
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
/**
|
||||
* A new cable plugged onto some of a part's outputs (wire 0 the top one):
|
||||
* its bundle sits on the pins, the cable runs a few squares on to a free
|
||||
* split carrying their names, ready to be dragged to where they go.
|
||||
* A plug on some of a part's outputs (wire 0 the top one): a bundle sitting
|
||||
* on the pins, without a cable yet. Pulling the cable out of its pin gives
|
||||
* it the other end, where it is dropped.
|
||||
*/
|
||||
export function cableFromPins(def: ComponentDef, partId: string, pins: string[], get: DefLookup): { ok: true; bundle: CircuitNode; split: CircuitNode } | { ok: false; error: string } {
|
||||
export function cableFromPins(def: ComponentDef, partId: string, pins: string[], get: DefLookup): { ok: true; bundle: CircuitNode } | { ok: false; error: string } {
|
||||
const part = def.nodes.find(n => n.id === partId)
|
||||
if (!part) return { ok: false, error: 'Part not found' }
|
||||
// Outputs on the right edge only: a cable end on the left would sit inside the box.
|
||||
|
|
@ -507,21 +507,15 @@ export function cableFromPins(def: ComponentDef, partId: string, pins: string[],
|
|||
def.nodes.push(bundle)
|
||||
outs.forEach((p, i) => def.wires.push({ id: uid('w'), from: { node: part.id, pin: p.key }, to: { node: bundle.id, pin: `b${i}` } }))
|
||||
plugInto(def, bundle, part.id, get)
|
||||
const mid = Math.floor((outs.length - 1) / 2)
|
||||
const busY = bundle.y + cableOffsets(bundle)[mid]!
|
||||
const split: CircuitNode = { id: uid('n'), kind: 'split', bits: outs.length, x: 0, y: busY - mid }
|
||||
split.x = clearSpot(def, get, bundle.x + 7, split.y, outs.length, 1)
|
||||
def.nodes.push(split)
|
||||
def.wires.push({ id: uid('w'), from: { node: bundle.id, pin: 'q' }, to: { node: split.id, pin: 'a' } })
|
||||
return { ok: true, bundle, split }
|
||||
return { ok: true, bundle }
|
||||
}
|
||||
|
||||
/**
|
||||
* A new cable plugged into some of a part's free inputs: its split sits on
|
||||
* the pins, the cable comes from a free bundle a few squares back, ready
|
||||
* to be fed (drag it next to what drives them, or attach a panel to it).
|
||||
* A plug on some of a part's free inputs: a split sitting on the pins,
|
||||
* without a cable yet. Pulling the cable out of its pin gives it the
|
||||
* other end, where it is dropped (or attach an input panel to it).
|
||||
*/
|
||||
export function cableIntoPins(def: ComponentDef, partId: string, pins: string[], get: DefLookup): { ok: true; bundle: CircuitNode; split: CircuitNode } | { ok: false; error: string } {
|
||||
export function cableIntoPins(def: ComponentDef, partId: string, pins: string[], get: DefLookup): { ok: true; split: CircuitNode } | { ok: false; error: string } {
|
||||
const part = def.nodes.find(n => n.id === partId)
|
||||
if (!part) return { ok: false, error: 'Part not found' }
|
||||
const fed = new Set(def.wires.filter(w => w.to.node === part.id).map(w => w.to.pin))
|
||||
|
|
@ -533,11 +527,21 @@ export function cableIntoPins(def: ComponentDef, partId: string, pins: string[],
|
|||
def.nodes.push(split)
|
||||
ins.forEach((p, i) => def.wires.push({ id: uid('w'), from: { node: split.id, pin: `b${i}` }, to: { node: part.id, pin: p.key } }))
|
||||
plugInto(def, split, part.id, get)
|
||||
const mid = Math.floor((ins.length - 1) / 2)
|
||||
const busY = split.y + cableOffsets(split)[mid]!
|
||||
const bundle: CircuitNode = { id: uid('n'), kind: 'bundle', bits: ins.length, x: 0, y: busY - mid }
|
||||
bundle.x = clearSpot(def, get, split.x - 8, bundle.y, ins.length, -1)
|
||||
def.nodes.push(bundle)
|
||||
def.wires.push({ id: uid('w'), from: { node: bundle.id, pin: 'q' }, to: { node: split.id, pin: 'a' } })
|
||||
return { ok: true, bundle, split }
|
||||
return { ok: true, split }
|
||||
}
|
||||
|
||||
/**
|
||||
* The other end of a cable pulled out of a cable end, placed at `x`, `y`:
|
||||
* out of a bundle a split, out of a split a bundle, with as many wires.
|
||||
* Null when it isn't a cable end, or a split that already has its cable.
|
||||
*/
|
||||
export function cableEnd(def: ComponentDef, endId: string, x: number, y: number): CircuitNode | null {
|
||||
const from = def.nodes.find(n => n.id === endId)
|
||||
if (!from || !CABLE_ENDS.has(from.kind)) return null
|
||||
if (from.kind === 'split' && def.wires.some(w => w.to.node === from.id)) return null
|
||||
const end: CircuitNode = { id: uid('n'), kind: from.kind === 'bundle' ? 'split' : 'bundle', bits: cableBits(from), x, y }
|
||||
def.nodes.push(end)
|
||||
const [bundle, split] = end.kind === 'split' ? [from, end] : [end, from]
|
||||
def.wires.push({ id: uid('w'), from: { node: bundle.id, pin: 'q' }, to: { node: split.id, pin: 'a' } })
|
||||
return end
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
import { bundleWires, cableFromPins, cableIntoPins, cablePanel, nameTags, pinGroups, plugInto, plugLayout, syncCables } from '../app/lib/logic/cables'
|
||||
import { bundleWires, cableEnd, cableFromPins, cableIntoPins, cablePanel, nameTags, pinGroups, plugInto, plugLayout, syncCables } from '../app/lib/logic/cables'
|
||||
import { dropLinks, dropPins } from '../app/lib/logic/fit'
|
||||
import { compile, rowSource } from '../app/lib/logic/compile'
|
||||
import { chipPins, panelOffsets, pinPos, shapeOf } from '../app/lib/logic/geometry'
|
||||
|
|
@ -303,7 +303,7 @@ describe('a cable straight off a part', () => {
|
|||
expect(outs.map(g => g.label)).toEqual(['S0–S1', 'all 4 (S0–Cout)'])
|
||||
})
|
||||
|
||||
it('from outputs: a bundle plugged on the pins, a free split with their names, then dropped onto the next part', () => {
|
||||
it('from outputs: only a plug on the pins; the cable pulled out of it gets a free split with their names, then dropped onto the next part', () => {
|
||||
const { p, def, outs } = adder()
|
||||
const get = lookup(p)
|
||||
// Take the lamps away: the outputs are free.
|
||||
|
|
@ -312,24 +312,33 @@ describe('a cable straight off a part', () => {
|
|||
if (!res.ok) throw new Error(res.error)
|
||||
expect(res.bundle.plug).toBe('add')
|
||||
expect(touches(p, def, res.bundle)).toBe(true)
|
||||
// Just the plug: no split, no cable yet.
|
||||
expect(def.nodes.filter(n => n.kind === 'split')).toHaveLength(0)
|
||||
expect(def.wires.some(w => w.from.node === res.bundle.id)).toBe(false)
|
||||
syncCables(p)
|
||||
expect(res.split.names).toEqual(['S0', 'S1', 'S2', 'S3'])
|
||||
expect(res.split.x).toBeGreaterThan(res.bundle.x)
|
||||
expect(res.bundle.names).toEqual(['S0', 'S1', 'S2', 'S3'])
|
||||
// The cable pulled out and let go a few squares on.
|
||||
const split = cableEnd(def, res.bundle.id, res.bundle.x + 7, res.bundle.y)!
|
||||
expect(split.kind).toBe('split')
|
||||
expect(split.bits).toBe(4)
|
||||
expect(def.wires.filter(w => w.from.node === res.bundle.id && w.to.node === split.id).map(w => [w.from.pin, w.to.pin])).toEqual([['q', 'a']])
|
||||
syncCables(p)
|
||||
expect(split.names).toEqual(['S0', 'S1', 'S2', 'S3'])
|
||||
// A second adder: drop the split right onto its A inputs.
|
||||
def.nodes.push({ id: 'add2', kind: 'chip', chip: 'ex-add4', x: 60, y: 0 })
|
||||
const lay = (() => {
|
||||
const s = shapeOf(node(def, 'add2'), get).inputs[0]!
|
||||
return { x: 60 + s.dx - 1, y: s.dy }
|
||||
})()
|
||||
res.split.x = lay.x
|
||||
res.split.y = lay.y
|
||||
const moved = dropPins(def, [res.split], n => shapeOf(n, get))
|
||||
const still = dropPins(def, def.nodes.filter(n => n !== res.split), n => shapeOf(n, get))
|
||||
split.x = lay.x
|
||||
split.y = lay.y
|
||||
const moved = dropPins(def, [split], n => shapeOf(n, get))
|
||||
const still = dropPins(def, def.nodes.filter(n => n !== split), n => shapeOf(n, get))
|
||||
const drop = dropLinks(moved, still, 0)!
|
||||
expect(drop.links).toHaveLength(4)
|
||||
def.wires.push(...drop.links.map((l, i) => ({ id: `d${i}`, ...l })))
|
||||
syncCables(p)
|
||||
expect(res.split.plug).toBe('add2')
|
||||
expect(split.plug).toBe('add2')
|
||||
// A0 of the first adder set: S0 = 1 arrives at A0 of the second, whose S0 shows it.
|
||||
def.nodes.push({ id: 'out', kind: 'lamp', x: 80, y: 0 })
|
||||
def.wires.push({ id: 'o', from: { node: 'add2', pin: outs[0]! }, to: { node: 'out', pin: 'a' } })
|
||||
|
|
@ -339,17 +348,35 @@ describe('a cable straight off a part', () => {
|
|||
expect(s.pin('out', 'a')).toBe(1)
|
||||
})
|
||||
|
||||
it('into inputs: a split plugged on the free pins, a free bundle behind it', () => {
|
||||
it('into inputs: only a plug on the free pins, named after them; a bundle comes behind it when the cable is pulled out', () => {
|
||||
const { p, def, ins } = adder()
|
||||
def.wires = def.wires.filter(w => w.to.node !== 'add')
|
||||
const res = cableIntoPins(def, 'add', ins.slice(4, 8), lookup(p))
|
||||
if (!res.ok) throw new Error(res.error)
|
||||
expect(res.split.plug).toBe('add')
|
||||
expect(touches(p, def, res.split)).toBe(true)
|
||||
expect(res.bundle.x).toBeLessThan(res.split.x)
|
||||
expect(def.nodes.filter(n => n.kind === 'bundle')).toHaveLength(0)
|
||||
syncCables(p)
|
||||
expect(res.bundle.names).toEqual(['B0', 'B1', 'B2', 'B3'])
|
||||
// Those inputs are taken now: no second cable into them.
|
||||
expect(res.split.names).toEqual(['B0', 'B1', 'B2', 'B3'])
|
||||
// Those inputs are taken now: no second plug on them.
|
||||
expect(cableIntoPins(def, 'add', ins.slice(4, 8), lookup(p)).ok).toBe(false)
|
||||
const bundle = cableEnd(def, res.split.id, res.split.x - 8, res.split.y)!
|
||||
expect(bundle.kind).toBe('bundle')
|
||||
expect(bundle.x).toBeLessThan(res.split.x)
|
||||
syncCables(p)
|
||||
expect(bundle.names).toEqual(['B0', 'B1', 'B2', 'B3'])
|
||||
// A split has one cable: none more out of it.
|
||||
expect(cableEnd(def, res.split.id, 0, 0)).toBeNull()
|
||||
})
|
||||
|
||||
it('a bundle can have more cables pulled out of it, each to its own split', () => {
|
||||
const { p, def, outs } = adder()
|
||||
def.wires = def.wires.filter(w => w.from.node !== 'add')
|
||||
const res = cableFromPins(def, 'add', outs.slice(0, 4), lookup(p))
|
||||
if (!res.ok) throw new Error(res.error)
|
||||
const a = cableEnd(def, res.bundle.id, 40, 0)!
|
||||
const b = cableEnd(def, res.bundle.id, 40, 10)!
|
||||
expect(def.wires.filter(w => w.from.node === res.bundle.id).map(w => w.to.node).sort()).toEqual([a.id, b.id].sort())
|
||||
expect(cableEnd(def, 'add', 0, 0)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue