diff --git a/app/assets/css/main.css b/app/assets/css/main.css index fb076ae..9de87c7 100644 --- a/app/assets/css/main.css +++ b/app/assets/css/main.css @@ -800,6 +800,28 @@ kbd { stroke-width: 1.2; } +.node .body.cable-end.plugged { + fill: #253447; + stroke: #6fa3cf; +} + +.node .latch rect { + fill: #6fa3cf; + stroke: #1b2633; + stroke-width: 1; +} + +.node .latch .contact { + stroke: #9fd0f5; + stroke-width: 2.5; + stroke-linecap: round; +} + +.node .cable-name { + font-size: 9px; + fill: var(--text); +} + /* Pixel and pixel screens. */ .node .pixel { fill: #141a22; @@ -1070,6 +1092,16 @@ kbd { stroke: #ffb3b3; } +/* Panel rows in a colour of their own */ +.switch.on.l-yellow { fill: rgb(255 211 77 / 0.25); stroke: #ffd34d; } +.switch.on.l-red { fill: rgb(255 92 92 / 0.25); stroke: #ff5c5c; } +.switch.on.l-blue { fill: rgb(77 171 255 / 0.25); stroke: #4dabff; } +.switch.on.l-white { fill: rgb(244 246 250 / 0.22); stroke: #f4f6fa; } +.button.on.l-yellow { fill: #ffd34d; stroke: #fff0c2; } +.button.on.l-green { fill: #3ddc84; stroke: #b5f5d0; } +.button.on.l-blue { fill: #4dabff; stroke: #bfe0ff; } +.button.on.l-white { fill: #f4f6fa; stroke: #ffffff; } + .display { fill: #0a0d11; } @@ -1711,6 +1743,55 @@ kbd { flex: 0 0 56px; } +.panel-rows li { + flex-wrap: wrap; +} + +.panel-rows li.open { + padding-bottom: 4px; + border-bottom: 1px solid var(--border); +} + +.panel-rows .icon-btn.active { + color: var(--text); +} + +.panel-rows .row-more { + display: flex; + flex: 1 0 100%; + flex-wrap: wrap; + align-items: center; + gap: 6px 8px; + padding-left: 26px; + font-size: 11px; + color: var(--muted); +} + +.panel-rows .row-more label { + display: flex; + align-items: center; + gap: 4px; +} + +.panel-rows .row-more input { + flex: 0 0 40px; + width: 40px; + padding: 2px 4px; + text-align: center; +} + +.swatches.mini { + gap: 4px; +} + +.swatches.mini .swatch { + width: 16px; + height: 16px; +} + +.lamp-swatch.default-on { background: var(--on); } +.lamp-swatch.default-on.button { background: var(--danger); } + .challenge .score, .inspector .score { display: flex; diff --git a/app/components/editor/Canvas.vue b/app/components/editor/Canvas.vue index f7bec81..d40b625 100644 --- a/app/components/editor/Canvas.vue +++ b/app/components/editor/Canvas.vue @@ -384,7 +384,7 @@ function onPointerDown(e: PointerEvent) { if (node.kind === 'button') ed.press(node, true) if (row && !multi) ed.pressRow(node, row, true) - const ids = ed.withDocked(selected.value.has(id) ? ed.selection.value : [id]) + const ids = ed.withFollowers(selected.value.has(id) ? ed.selection.value : [id]) const orig = new Map() const lockY = new Set() for (const sid of ids) { @@ -607,8 +607,10 @@ function onPointerUp() { case 'move': if (d.node.kind === 'button') ed.press(d.node, false) if (d.row && !d.moved) ed.pressRow(d.node, d.row, false) - if (d.moved) ed.commit(false) - else if (d.toggle && d.row) ed.toggleRow(d.node, d.row) + if (d.moved) { + ed.unplugMoved(new Set(d.orig.keys())) + ed.commit(false) + } else if (d.toggle && d.row) ed.toggleRow(d.node, d.row) else if (d.toggle) ed.toggleInput(d.node) break case 'wire': { @@ -667,8 +669,9 @@ const ARROWS: Record = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], Arr /** Arrow keys: move the selected parts and wires one grid step (four with Shift). */ function nudge(dx: number, dy: number) { - const ids = ed.withDocked(ed.selection.value) + const ids = ed.withFollowers(ed.selection.value) if (!ids.size && !ed.wireSel.value.length) return + ed.unplugMoved(ids) for (const n of def.value.nodes) { if (!ids.has(n.id)) continue n.x += dx @@ -698,12 +701,15 @@ function onKey(e: KeyboardEvent) { } const mod = e.ctrlKey || e.metaKey const key = e.key.toLowerCase() - // Keys bound to switches and buttons win over the shortcuts below. + // Keys bound to switches, buttons and panel rows win over the shortcuts below. if (!mod && !e.altKey && e.key.length === 1) { const bound = def.value.nodes.filter(n => n.key === key && (n.kind === 'input' || n.kind === 'button')) - if (bound.length) { + const rows = boundRows(key) + if (bound.length || rows.length) { e.preventDefault() - if (!e.repeat) for (const n of bound) n.kind === 'input' ? ed.toggleInput(n) : ed.press(n, true) + if (e.repeat) return + for (const n of bound) n.kind === 'input' ? ed.toggleInput(n) : ed.press(n, true) + for (const [n, r] of rows) r.type === 'button' ? ed.pressRow(n, r, true) : ed.toggleRow(n, r) return } } @@ -760,6 +766,14 @@ function onKeyUp(e: KeyboardEvent) { if (e.key === ' ') spaceDown.value = false const key = e.key.toLowerCase() for (const n of def.value.nodes) if (n.kind === 'button' && n.key === key) ed.press(n, false) + for (const [n, r] of boundRows(key)) if (r.type === 'button') ed.pressRow(n, r, false) +} + +/** Panel rows bound to a key. */ +function boundRows(key: string): [CircuitNode, PanelRow][] { + const out: [CircuitNode, PanelRow][] = [] + for (const n of def.value.nodes) if (n.kind === 'panel') for (const r of n.rows ?? []) if (r.key === key) out.push([n, r]) + return out } // ── Overlays ──────────────────────────────────────────────────────── diff --git a/app/components/editor/Help.vue b/app/components/editor/Help.vue index 3451d53..e3de9ab 100644 --- a/app/components/editor/Help.vue +++ b/app/components/editor/Help.vue @@ -21,7 +21,8 @@ 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'], - ['Select wires, Bundle into cable', 'Run several wires as one thick cable; Remove cable undoes it'], + ['Select wires, Ctrl+G', 'Bundle them into one cable; an end whose wires all meet one part plugs straight into it'], + ['Drag a plugged cable end away', 'Pull it out; drop its pins on a part\'s pins to plug it in again'], ['Shift + click on canvas', 'Keep placing the same part'], ['Ctrl+C, Ctrl+V, Ctrl+D', 'Copy, paste, duplicate; names continue their series (D0 → D1)'], ['Delete', 'Remove the selection'], diff --git a/app/components/editor/NodeSettings.vue b/app/components/editor/NodeSettings.vue index 7f641ed..37cf3f4 100644 --- a/app/components/editor/NodeSettings.vue +++ b/app/components/editor/NodeSettings.vue @@ -2,7 +2,7 @@ import { stats } from '~/lib/logic/analyze' import { compile } from '~/lib/logic/compile' import { cableOf } from '~/lib/logic/cables' -import { cableBits, chipPins, MAX_BITS, rowLabel } from '~/lib/logic/geometry' +import { cableBits, cableOffsets, chipPins, MAX_BITS, panelOffsets, rowLabel } from '~/lib/logic/geometry' import { SINK_KINDS, SOURCE_KINDS } from '~/lib/logic/ops' import { KIND_NAMES } from '~/lib/logic/progress' import { baseOf, gateFamily, inputCount, MAX_GATE_INPUTS } from '~/lib/logic/wide' @@ -26,10 +26,10 @@ const HINTS: Record = { button: 'Gives 1 while held down with the mouse or its key.', lamp: 'Lights up at 1. Inside a component it also shows on the component box.', hex: 'Shows inputs 1, 2, 4, 8 as one hex digit. Inside a component it also shows on the component box.', - bundle: 'Wire 0 (top) to the last on the left go into the cable on the right. Run the cable to a split, which gives them back in the same order.', - split: 'Takes a cable from a bundle and gives its wires back in the same order, top to bottom.', + bundle: 'Wire 0 (top) to the last on the left go into the cable on the right. Run the cable to a split, which gives them back in the same order. The wires are named after what drives them, or else what they drive.', + split: 'Takes a cable from a bundle and gives its wires back in the same order, top to bottom, with their names.', pixel: 'Lights at 1. Inside a component, all its pixels show on the component box as one screen, without gaps: space them out inside to wire them, every column and row they sit on becomes a column and row of the screen.', - panel: 'Click a row on the canvas to flip its switch or hold its button. Rows without a name take the name of the pin they are wired to.', + panel: 'Click a row on the canvas to flip its switch or hold its button, or press its key. Rows without a name take the name of the pin they are wired to. Open a row (the arrow) for its key, colour, spacing and order.', } const n = computed(() => props.node) @@ -159,6 +159,49 @@ function setRowLabel(row: PanelRow, e: Event) { ed.commit() } +/** Rows showing their extra settings (key, colour, spacing, order). */ +const openRows = ref(new Set()) +function toggleRow(id: string) { + const s = new Set(openRows.value) + if (!s.delete(id)) s.add(id) + openRows.value = s +} +const rowGaps = computed(() => { + const at = panelOffsets(n.value.rows ?? []) + return at.map((y, i) => (i ? y - at[i - 1]! - 1 : 0)) +}) + +function setRowKey(row: PanelRow, e: KeyboardEvent) { + if (e.key === 'Tab') return + e.preventDefault() + if (e.key === 'Backspace' || e.key === 'Delete' || e.key === 'Escape') ed.setRowKey(row, undefined) + else if (e.key.length === 1 && e.key !== ' ') ed.setRowKey(row, e.key.toLowerCase()) + else return + ;(e.target as HTMLInputElement).blur() +} + +/** What a part is called in messages: its label, its component's name, or its kind. */ +function partName(id: string | undefined): string { + const p = id ? ed.def.value.nodes.find(x => x.id === id) : undefined + if (!p) return 'part' + if (p.label?.trim() && !p.autoLabel) return p.label.trim() + if (p.kind === 'chip') return (p.chip ? ed.getDef.value(p.chip)?.name : undefined) ?? 'component' + if (p.kind === 'panel') return 'the input panel' + return (KIND_NAMES[p.kind] ?? p.kind).toLowerCase() +} + +const isCableEnd = computed(() => n.value.kind === 'bundle' || n.value.kind === 'split') +const plugPart = computed(() => (isCableEnd.value && !n.value.plug ? ed.plugTarget(n.value) : undefined)) +const pitch = computed(() => { + const o = cableOffsets(n.value) + return o.every((v, i) => v === i * (o[1] ?? 1)) ? (o[1] ?? 1) : null +}) +const undriven = computed(() => { + if (n.value.kind !== 'bundle') return 0 + const fed = new Set(ed.def.value.wires.filter(w => w.to.node === n.value.id).map(w => w.to.pin)) + return cableBits(n.value) - fed.size +}) + function setRowHz(row: PanelRow, e: Event) { const v = Number((e.target as HTMLInputElement).value) if (v > 0 && v <= 1000) row.hz = v @@ -233,7 +276,15 @@ function setRowHz(row: PanelRow, e: Event) {
Rows
    -
  • +
  • + + + + + + + +
    +
    +
@@ -315,10 +391,47 @@ function setRowHz(row: PanelRow, e: Event) {