diff --git a/README.md b/README.md index 6e3c8e6..179aae3 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Nuxt 4 (client-only editor, `ssr: false`), Tailwind CSS v4, Lucide icons via `@n ## What it does - Parts: NAND, input switch, output pin, lamp, push button, clock, constant 1, ground, hex display, pixel, cable bundle and split, input panel, note. +- Layout like Figma: a slim top bar (menu, project, circuit, clock, undo, share), a floating bar at the bottom of the canvas with one button per kind of part (Logic, Inputs, Outputs, Wiring, Notes, Connectors, Components) that opens its parts on pointing, and on the left your pinned parts (NAND, AND, OR, NOT, XOR, input, output, lamp, clock to start with; pin and unpin from the bottom bar, kept per browser, components by name) above the circuits list. - Lamps and output pins pass their signal on: the pin on their right carries the same value, so a lamp can sit in the middle of a wire. - Gates with more inputs: a placed AND, OR, XOR, NAND or NOR (built in, from the examples, or your own) has an "Inputs" setting from 2 to 16. The wide version is a component built as a balanced tree of the two-input gate (NAND and NOR as the plain gate plus a final inverted one), made once per gate and width in "Wide gates" and reused; transistors count honestly and changes to the two-input gate carry through. Which gates qualify is read off their truth table ([app/lib/logic/wide.ts](app/lib/logic/wide.ts)). - Campaign (Projects → New campaign): you start with NAND, inputs, outputs, lamps and notes, and no examples. Each challenge opens once the ones it builds on are solved (NOT → AND, OR, SR Latch → …), and your own solution becomes a part you can place. Other basic parts unlock on the way: constants with NOT, the input panel with AND, hex display and pixel with the decoder, cables with Adder 2, the button with the SR latch, the clock with the D latch. Rules in [app/lib/logic/progress.ts](app/lib/logic/progress.ts). Sandbox projects keep everything open. @@ -14,7 +15,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. +- 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, " 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 5adc359..af1522a 100644 --- a/app/assets/css/main.css +++ b/app/assets/css/main.css @@ -57,13 +57,13 @@ kbd { /* ── Layout ─────────────────────────────────────────────────────── */ .app { display: grid; - grid-template-rows: 48px 1fr; + grid-template-rows: 44px 1fr; height: 100dvh; } .workspace { - --left: 236px; - --right: 300px; + --left: 232px; + --right: 272px; display: grid; grid-template-columns: var(--left) 1fr var(--right); min-height: 0; @@ -4220,3 +4220,258 @@ table.board { .wire.port-cable:not([class*='c-']) .cable-sleeve { stroke: #8592a3; } + +/* ── Bottom bar: parts by kind, like Figma's toolbar ────────────── */ +.bottom-dock { + position: absolute; + left: 50%; + bottom: 14px; + z-index: 20; + transform: translateX(-50%); +} + +.bottom-bar { + display: flex; + align-items: center; + gap: 2px; + padding: 5px; + background: rgb(26 33 43 / 0.96); + border: 1px solid var(--border); + border-radius: 12px; + box-shadow: + 0 10px 30px rgb(0 0 0 / 0.45), + 0 1px 0 rgb(255 255 255 / 0.03) inset; + backdrop-filter: blur(8px); +} + +.bar-btn { + display: flex; + align-items: center; + gap: 6px; + height: 34px; + padding: 0 10px; + border-radius: 8px; + color: var(--muted); + font-size: 12px; + font-weight: 600; + white-space: nowrap; + transition: + background 0.12s, + color 0.12s; +} + +.bar-btn:hover, +.bar-btn.open { + background: var(--panel-2); + color: var(--text); +} + +.bar-btn.active { + background: rgb(76 194 255 / 0.16); + color: var(--accent); +} + +.bar-sep { + width: 1px; + height: 20px; + margin: 0 4px; + background: var(--border); +} + +@media (max-width: 1250px) { + .bar-label { + display: none; + } +} + +.flyout { + position: absolute; + bottom: calc(100% + 8px); + width: 250px; + max-height: min(60vh, 460px); + display: flex; + flex-direction: column; + padding: 6px; + transform: translateX(-50%); + background: rgb(26 33 43 / 0.98); + border: 1px solid var(--border); + border-radius: 12px; + box-shadow: 0 18px 50px rgb(0 0 0 / 0.5); +} + +.flyout-scroll { + overflow-y: auto; + min-height: 0; + scrollbar-width: thin; +} + +.flyout-head { + padding: 6px 8px 4px; + font-size: 10px; + font-weight: 700; + letter-spacing: 0.07em; + text-transform: uppercase; + color: var(--muted); +} + +.flyout-empty { + padding: 2px 8px 8px; + font-size: 12px; + color: var(--muted); + line-height: 1.45; +} + +.flyout-list li { + display: flex; + align-items: center; + gap: 2px; +} + +.flyout-item { + display: flex; + flex: 1; + min-width: 0; + align-items: center; + gap: 9px; + padding: 6px 8px; + border-radius: 7px; + font-size: 13px; + color: var(--text); + text-align: left; +} + +.flyout-item:not(.static):hover { + background: var(--panel-2); +} + +.flyout-item .iconify { + color: var(--muted); +} + +.flyout-item.active { + background: rgb(76 194 255 / 0.14); + color: var(--accent); +} + +.flyout-item.blocked { + opacity: 0.4; +} + +.flyout-note { + font-family: var(--font-mono); + font-size: 10px; + color: var(--muted); +} + +.pin-btn { + display: grid; + place-items: center; + width: 26px; + height: 26px; + flex-shrink: 0; + border-radius: 6px; + color: var(--muted); + opacity: 0; + transition: opacity 0.12s; +} + +.flyout-list li:hover .pin-btn, +.pin-btn.on { + opacity: 1; +} + +.pin-btn.on { + color: var(--accent); +} + +.pin-btn:hover { + background: var(--panel-2); + color: var(--text); +} + +.flyout-new { + display: flex; + align-items: center; + gap: 8px; + margin-top: 4px; + padding: 7px 8px; + border-top: 1px solid var(--border); + font-size: 12px; + font-weight: 600; + color: var(--muted); +} + +.flyout-new:hover:not(:disabled) { + color: var(--text); +} + +.flyout-enter-active, +.flyout-leave-active { + transition: + opacity 0.12s, + transform 0.12s; +} + +.flyout-enter-from, +.flyout-leave-to { + opacity: 0; + transform: translate(-50%, 4px); +} + +/* Pinned parts in the left panel */ +.pinned-head { + display: flex; + align-items: baseline; + justify-content: space-between; + padding: 10px 14px 4px; + font-size: 11px; + font-weight: 700; + letter-spacing: 0.06em; + text-transform: uppercase; + color: var(--muted); +} + +.pinned-head .hint { + margin: 0; + font-size: 10px; + font-weight: 500; + letter-spacing: 0; + text-transform: none; +} + +.pinned li { + position: relative; +} + +.pinned li .open { + position: absolute; + right: 6px; + top: 50%; + transform: translateY(-50%); + opacity: 0; +} + +.pinned li:hover .open { + opacity: 1; +} + +/* The bar sits at the bottom: notices go above it. */ +.toast { + bottom: 84px; +} + +.pinned li .open { + padding: 5px; + border-radius: 5px; + color: var(--muted); + background: var(--panel); +} + +.pinned li .open:hover { + background: var(--panel-2); + color: var(--text); +} + +.palette .tabs button { + white-space: nowrap; +} diff --git a/app/components/editor/App.vue b/app/components/editor/App.vue index 65b07a5..c6361e5 100644 --- a/app/components/editor/App.vue +++ b/app/components/editor/App.vue @@ -41,6 +41,7 @@ watch(
+
diff --git a/app/components/editor/BottomBar.vue b/app/components/editor/BottomBar.vue new file mode 100644 index 0000000..210963f --- /dev/null +++ b/app/components/editor/BottomBar.vue @@ -0,0 +1,205 @@ + + + diff --git a/app/components/editor/Help.vue b/app/components/editor/Help.vue index a21b036..a7a0634 100644 --- a/app/components/editor/Help.vue +++ b/app/components/editor/Help.vue @@ -23,7 +23,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'], - ['Connectors (parts list)', 'Make a cable type of your own (HDMI, RJ45): its lines; place its Out and In ports; one cable joins them'], + ['Bar at the bottom', 'Point at a kind of part to see them all; click to place, drag onto the canvas, pin the ones you use most to the left'], + ['Connectors (bottom bar)', '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/Palette.vue b/app/components/editor/Palette.vue index d0ac1ad..3e85c8f 100644 --- a/app/components/editor/Palette.vue +++ b/app/components/editor/Palette.vue @@ -3,14 +3,14 @@ import { shortCount } from '~/lib/logic/analyze' import { CHALLENGES } from '~/lib/logic/challenges' import { campaignProgress, challengeName, challengeOpen, defUsable, isCampaign, KIND_UNLOCK, NEEDS } from '~/lib/logic/progress' import { weekKey, weeklyId } from '~/lib/logic/puzzles' -import { BASIC_GROUPS } from '~/composables/useParts' import type { ComponentDef, NodeKind } from '~/lib/logic/types' const ed = useEditor() const tab = ed.paletteTab const query = ref('') -const { componentGroups, search, recentParts } = useParts() +const { componentGroups, search } = useParts() +const { place, dragStart, dragEnd, pinned, unpin } = usePlace() // ── Search: type to narrow everything down; arrows pick, Enter places ── const searchInput = ref() @@ -76,28 +76,6 @@ function pick(kind: NodeKind, chip?: string) { ed.placing.value = { kind, chip } } -// ── 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() @@ -184,87 +162,33 @@ const started = computed(() => new Map(ed.project.value.components.filter(d => d