From 8de4a81678bc42c2563e2b195235688237fe386a Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Thu, 22 Oct 2026 18:59:56 +0200 Subject: [PATCH] A connector types of your own: HDMI, RJ45 or any bus, with out and in ports and one cable that carries every line both ways - A project keeps connector types: a name, a colour and lines that run out -> in or back. Made, edited and deleted (once unused) from the parts list's new Connectors group and a connector dialog. - " out" and " in" ports: inside a component a pin per line on the inner side plus a cable pin to pass the whole cable on to a part inside; on the component's box one port, coloured like its type. - One cable joins an out port to an in port of the same type; the compiler joins line by line, forward and back, at every depth. Ports of different types never join; mismatched cables are pruned. - Pins can face the other way (the inner pins of ports); the router takes them out and in from the side they face. Co-Authored-By: Claude Opus 5.5 --- README.md | 1 + app/assets/css/main.css | 127 ++++++++++++++++++ app/components/editor/App.vue | 1 + app/components/editor/Canvas.vue | 101 +++++++++----- app/components/editor/ConnectorDialog.vue | 138 +++++++++++++++++++ app/components/editor/Help.vue | 1 + app/components/editor/NodeSettings.vue | 37 +++++- app/components/editor/NodeView.vue | 39 +++++- app/components/editor/Palette.vue | 63 ++++++++- app/composables/useEditor.ts | 85 ++++++++++-- app/lib/logic/compile.ts | 67 ++++++++-- app/lib/logic/fit.ts | 9 +- app/lib/logic/geometry.ts | 88 +++++++++++-- app/lib/logic/ops.ts | 21 ++- app/lib/logic/progress.ts | 4 + app/lib/logic/project.ts | 23 ++++ app/lib/logic/routing.ts | 12 +- app/lib/logic/types.ts | 25 ++++ tests/connectors.test.ts | 153 ++++++++++++++++++++++ 19 files changed, 915 insertions(+), 80 deletions(-) create mode 100644 app/components/editor/ConnectorDialog.vue create mode 100644 tests/connectors.test.ts diff --git a/README.md b/README.md index b4b8170..6e3c8e6 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Nuxt 4 (client-only editor, `ssr: false`), Tailwind CSS v4, Lucide icons via `@n - 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 parts list, "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, " out" and " 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, in ports on the left, out ports on the right, drawn as a socket in the type's colour. 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. diff --git a/app/assets/css/main.css b/app/assets/css/main.css index cc9e74c..5adc359 100644 --- a/app/assets/css/main.css +++ b/app/assets/css/main.css @@ -4093,3 +4093,130 @@ table.board { .fold-body { padding: 2px 14px 14px; } + +/* ── Connector ports and their cables ───────────────────────────── */ +.node .body.port { + fill: #141a22; +} + +.port-head { + opacity: 0.85; +} + +.port-title { + fill: #0e1116; + font-family: var(--font-mono); + font-size: 9px; + font-weight: 700; + pointer-events: none; +} + +.port-line { + fill: var(--text); +} + +.port-socket { + stroke: #0e1116; + stroke-width: 1.5; + pointer-events: none; +} + +.wire.port-cable .cable-sleeve { + stroke: var(--w-on, #8592a3); + opacity: 0.9; +} + +.wire.port-cable .cable-core { + stroke: #10151c; +} + +.port-mark text { + fill: var(--text); + font-family: var(--font-mono); + font-size: 9px; + font-weight: 700; +} + +/* Connectors in the parts list */ +.conn-row { + display: flex; + align-items: center; + gap: 6px; + padding: 2px 8px 2px 12px; + font-size: 13px; +} + +.conn-row.blocked { + opacity: 0.45; +} + +.conn-swatch { + flex: 0 0 auto; + width: 10px; + height: 10px; + border-radius: 3px; + background: var(--w-on, #8592a3); +} + +.conn-swatch.c-red { --w-on: #ff5c5c; } +.conn-swatch.c-orange { --w-on: #ff9f43; } +.conn-swatch.c-yellow { --w-on: #ffd93d; } +.conn-swatch.c-green { --w-on: #3ddc84; } +.conn-swatch.c-blue { --w-on: #4dabff; } +.conn-swatch.c-purple { --w-on: #b388ff; } +.conn-swatch.c-pink { --w-on: #ff7ac6; } + +.port-pick { + padding: 1px 7px; + font-size: 11px; +} + +.port-pick.active { + border-color: var(--accent); + color: var(--accent); +} + +/* Connector type dialog */ +.conn-modal { + width: min(560px, 100%); +} + +.conn-lines { + display: grid; + gap: 4px; + margin-bottom: 8px; +} + +.conn-lines li { + display: flex; + align-items: center; + gap: 4px; +} + +.conn-lines input { + flex: 1; + min-width: 0; +} + +.conn-index { + width: 20px; + text-align: right; + font-family: var(--font-mono); + font-size: 11px; + color: var(--muted); +} + +.conn-dir { + min-width: 78px; + font-family: var(--font-mono); + font-size: 11px; +} + +.conn-dir.back { + color: var(--lamp); + border-color: rgb(255 211 77 / 0.4); +} + +.wire.port-cable:not([class*='c-']) .cable-sleeve { + stroke: #8592a3; +} diff --git a/app/components/editor/App.vue b/app/components/editor/App.vue index 1e96437..65b07a5 100644 --- a/app/components/editor/App.vue +++ b/app/components/editor/App.vue @@ -70,6 +70,7 @@ watch( + diff --git a/app/components/editor/Canvas.vue b/app/components/editor/Canvas.vue index a5184bd..b4df8e4 100644 --- a/app/components/editor/Canvas.vue +++ b/app/components/editor/Canvas.vue @@ -1,7 +1,7 @@ + + diff --git a/app/components/editor/Help.vue b/app/components/editor/Help.vue index a62a87e..a21b036 100644 --- a/app/components/editor/Help.vue +++ b/app/components/editor/Help.vue @@ -23,6 +23,7 @@ const SHORTCUTS: [string, string][] = [ ['Right or middle drag, Space + drag', 'Move the view'], ['Mouse wheel', 'Zoom'], ['N, I, O, L, B, C, H, T, P, X', 'Place NAND, input, output, lamp, button, clock, hex display, note, input panel, pixel'], + ['Connectors (parts list)', 'Make a cable type of your own (HDMI, RJ45): its lines; place its Out and In ports; one cable joins them'], ['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'], ['Drag a part from the list onto pins', 'It lands on them and connects (green rings show where); Alt just places it'], diff --git a/app/components/editor/NodeSettings.vue b/app/components/editor/NodeSettings.vue index 9f7b795..f17bc7a 100644 --- a/app/components/editor/NodeSettings.vue +++ b/app/components/editor/NodeSettings.vue @@ -152,7 +152,7 @@ const cables = computed(() => ed.cableChoices(n.value)) const invertible = computed(() => { if (!INVERTIBLE.has(n.value.kind)) return [] const inv = new Set(n.value.invert ?? []) - return ed.shape(n.value).inputs.map((p, i) => ({ key: p.key, label: p.label || (n.value.kind === 'nand' ? 'AB'[i]! : 'In'), on: inv.has(p.key) })) + return ed.shape(n.value).inputs.filter(p => !p.bus).map((p, i) => ({ key: p.key, label: p.label || (n.value.kind === 'nand' ? 'AB'[i]! : 'In'), on: inv.has(p.key) })) }) const inverted = computed(() => invertible.value.filter(p => p.on).length) @@ -166,6 +166,19 @@ const transistorNote = computed(() => : 'No logic gate inside', ) +// Connector ports: which type, and which side of the box. +const connTypes = computed(() => ed.project.value.connectors ?? []) +function setConn(id: string) { + if (!id || id === n.value.conn) return + n.value.conn = id + ed.commit() +} +function setSide(kind: 'portin' | 'portout') { + if (kind === n.value.kind) return + n.value.kind = kind + ed.commit() +} + // The "more" button opens the same list as a right click on the part. const menu = useMenu() const more = ref<{ x: number; y: number; entries: MenuEntry[] } | null>(null) @@ -292,6 +305,28 @@ function setRowHz(row: PanelRow, e: Event) { @keydown.enter="($event.target as HTMLInputElement).blur()" /> + + diff --git a/app/components/editor/NodeView.vue b/app/components/editor/NodeView.vue index c1bda72..c0b3d26 100644 --- a/app/components/editor/NodeView.vue +++ b/app/components/editor/NodeView.vue @@ -2,7 +2,7 @@ import { gateDrawing, sevenSegment } from '~/lib/draw' import { LANE, nameTags, RIBBON_MAX } from '~/lib/logic/cables' import { baseOf, gateFamily, inputCount, MAX_GATE_INPUTS } from '~/lib/logic/wide' -import { faceTransform, GRID as G, noteLines, noteScale, PANEL_CONTROL_W, shapeTransform, type Shape } from '~/lib/logic/geometry' +import { faceTransform, GRID as G, noteLines, noteScale, PANEL_CONTROL_W, portLines, shapeTransform, type Shape } from '~/lib/logic/geometry' import type { CircuitNode } from '~/lib/logic/types' const props = defineProps<{ @@ -26,6 +26,16 @@ const style = computed(() => ed.project.value.settings.symbols) const gate = computed(() => (props.shape.gate ? gateDrawing(props.shape, style.value) : null)) const chipDef = computed(() => (props.node.chip ? ed.getDef.value(props.node.chip) : undefined)) const b = computed(() => props.shape.body) + +// Connector ports: their type, lines and colour. +const CONN_HEX: Record = { red: '#ff5c5c', orange: '#ff9f43', yellow: '#ffd93d', green: '#3ddc84', blue: '#4dabff', purple: '#b388ff', pink: '#ff7ac6' } +const connColor = (id?: string) => { + const c = id ? ed.getDef.value.conn?.(id)?.color : undefined + return c ? CONN_HEX[c] ?? '#8592a3' : '#8592a3' +} +const connType = computed(() => (props.node.conn ? ed.getDef.value.conn?.(props.node.conn) : undefined)) +const connName = computed(() => connType.value?.name ?? 'Port') +const lines = computed(() => (props.node.kind === 'portin' || props.node.kind === 'portout' ? portLines(props.node, ed.getDef.value) : [])) const rows = computed(() => props.node.rows ?? []) // A name typed by hand shows as is. Otherwise the name of the pin the part is // wired to, or its automatic name, shows dimmed. @@ -324,6 +334,27 @@ const title = computed(() => { + + + diff --git a/app/components/editor/Palette.vue b/app/components/editor/Palette.vue index 404d56f..d0ac1ad 100644 --- a/app/components/editor/Palette.vue +++ b/app/components/editor/Palette.vue @@ -76,14 +76,36 @@ function pick(kind: NodeKind, chip?: string) { ed.placing.value = { kind, chip } } -function onDragStart(e: DragEvent, kind: NodeKind, chip?: string) { +// ── Connector ports ── +const connectors = computed(() => ed.project.value.connectors ?? []) +const PORT_SIDES = [ + { kind: 'portout' as NodeKind, label: 'Out', hint: (n: string) => `${n} out: where a ${n} cable leaves this circuit. On its box it is one port on the right.` }, + { kind: 'portin' as NodeKind, label: 'In', hint: (n: string) => `${n} in: where a ${n} cable comes into this circuit. On its box it is one port on the left.` }, +] +/** In a campaign, ports come with cables. */ +const portsOk = computed(() => ed.canPlaceKind('portin')) + +function pickPort(kind: NodeKind, conn: string) { + if (!portsOk.value) { + ed.play('error') + return ed.notify(lockedHint(kind), 'error') + } + ed.placing.value = { kind, conn } +} + +function newConnector() { + if (!portsOk.value) return ed.notify(lockedHint('portin'), 'error') + ed.addConnector() +} + +function onDragStart(e: DragEvent, kind: NodeKind, chip?: string, conn?: string) { if (chip && !ed.canPlace(chip)) { e.preventDefault() return } - e.dataTransfer?.setData('application/x-logigate', JSON.stringify({ kind, chip })) + e.dataTransfer?.setData('application/x-logigate', JSON.stringify({ kind, chip, conn })) if (e.dataTransfer) e.dataTransfer.effectAllowed = 'copy' - ed.dragPart.value = { kind, chip } + ed.dragPart.value = { kind, chip, conn } } const solved = computed(() => new Set(ed.project.value.solved)) @@ -208,6 +230,41 @@ const started = computed(() => new Map(ed.project.value.components.filter(d => d + + +
    +
  • + + {{ c.name }} + + +
  • +
  • + +
  • +
+