R Top bar like the parts bar, no left panel
The parts panel on the left is gone: pinned parts sit at the start of the bottom bar, components open from the pencil in its Components list (or a double-click), examples load from there too. The side panel moved to the left. The top bar floats across the whole width: menu with the project, Main and the way into the open component instead of the circuit selector, Challenges in a drop-down, clock, search, undo, settings, share and account. / and the bar's search open quick add. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
67e3d94d80
commit
6e3405ae0c
|
|
@ -7,7 +7,7 @@ Nuxt 4 (client-only editor, `ssr: false`), Tailwind CSS v4, Lucide icons via `@n
|
||||||
## What it does
|
## 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.
|
- 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.
|
- Layout like Figma: two floating rounded bars and one side panel. The top bar, across the whole width: menu (pause menu) with the project name, "Main" and the way into the open component (each name leads back; every other circuit is a component and opens with a double-click, or the pencil in the Components list), Challenges (campaign, puzzle of the week, puzzles, challenges in a drop-down), the clock, search, undo, sound, settings, help, share and account. The bottom bar: your pinned parts first (NAND, AND, OR, NOT, XOR, input, output, lamp, clock to start with; pin from the lists, right-click to unpin, kept per browser, components by name), then one button per kind of part (Logic, Inputs, Outputs, Wiring, Notes, Connectors, Components) that opens its parts on pointing, and a search that opens quick add. The side panel sits on the left.
|
||||||
- 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.
|
- 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)).
|
- 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.
|
- 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.
|
||||||
|
|
@ -21,13 +21,13 @@ Nuxt 4 (client-only editor, `ssr: false`), Tailwind CSS v4, Lucide icons via `@n
|
||||||
- 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.
|
- 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.
|
||||||
- Every circuit is a component. Its input and output nodes become its pins, ordered top to bottom. Double-click a component to open it.
|
- Every circuit is a component. Its input and output nodes become its pins, ordered top to bottom. Double-click a component to open it.
|
||||||
- Lamps and hex displays inside a component show on its box, with their labels, lit by that instance's state. They are laid out in rows the way they sit inside. A checkbox in the inspector turns this off per component.
|
- Lamps and hex displays inside a component show on its box, with their labels, lit by that instance's state. They are laid out in rows the way they sit inside. A checkbox in the inspector turns this off per component.
|
||||||
- The right panel has four tabs. **Selection**: settings of what you clicked (switches to it when you select something on an idle panel). **Circuit**: name, symbol, group, statistics, and where the transistors are (each kind of part with its count; click a line to select those parts). **Pins**: every input and output of the circuit in pin order, one line each, with its live value (click it to flip a switch, hold it for a button; panel rows are framed under their panel); rename in place (Enter goes to the next), "Number all" names a whole side from a pattern (D# → D0, D1, …), duplicate names are flagged, the target icon centres the canvas on a part. **Test**: the challenge or puzzle check and the truth table (opens by itself for a challenge). Display and sound preferences are in Settings (gear in the top bar). Both side panels fold away to a strip of icons (the panel icon in their tab row, or [ and ]).
|
- The side panel (left) has four tabs. **Selection**: settings of what you clicked (switches to it when you select something on an idle panel). **Circuit**: name, symbol, group, statistics, and where the transistors are (each kind of part with its count; click a line to select those parts). **Pins**: every input and output of the circuit in pin order, one line each, with its live value (click it to flip a switch, hold it for a button; panel rows are framed under their panel); rename in place (Enter goes to the next), "Number all" names a whole side from a pattern (D# → D0, D1, …), duplicate names are flagged, the target icon centres the canvas on a part. **Test**: the challenge or puzzle check and the truth table (opens by itself for a challenge). Display and sound preferences are in Settings (gear in the top bar). It folds away to a strip of icons (the panel icon in its tab row, or [).
|
||||||
- Box selection: a box that touches no parts selects every wire and cable it crosses (drag across the wires between parts to bundle them). Dragged right to left (green box) it selects everything it touches, parts and wires. Left to right over parts it takes those parts and only the wires lying fully inside, so Delete never catches unrelated wires passing through.
|
- Box selection: a box that touches no parts selects every wire and cable it crosses (drag across the wires between parts to bundle them). Dragged right to left (green box) it selects everything it touches, parts and wires. Left to right over parts it takes those parts and only the wires lying fully inside, so Delete never catches unrelated wires passing through.
|
||||||
- Wiring many at once: select several parts and drag one wire from one of them to a pin of another part; the others follow onto that part's next pins, in position order (or use "Wire them all to" in the panel).
|
- Wiring many at once: select several parts and drag one wire from one of them to a pin of another part; the others follow onto that part's next pins, in position order (or use "Wire them all to" in the panel).
|
||||||
- Zooming out goes at least far enough to see the whole circuit, further for bigger circuits.
|
- Zooming out goes at least far enough to see the whole circuit, further for bigger circuits.
|
||||||
- Several selected parts are edited together: chips to narrow the selection by type, swap them all for another part, rename all top to bottom from a pattern, set every switch to 0 or 1 or flip each, one colour, one clock frequency or note size for all, line them up or spread them evenly, plus make component, connect one by one, unlink, duplicate, delete.
|
- Several selected parts are edited together: chips to narrow the selection by type, swap them all for another part, rename all top to bottom from a pattern, set every switch to 0 or 1 or flip each, one colour, one clock frequency or note size for all, line them up or spread them evenly, plus make component, connect one by one, unlink, duplicate, delete.
|
||||||
- Transistors: every part shows its count (4 for a NAND, 0 for switches, lamps and cables, the whole inside for a component; the NAND in the palette shows 4T). The count is 4 per CMOS NAND gate the simulator builds, at every depth; a test checks this against the flattened circuit for every example and every wide gate.
|
- Transistors: every part shows its count (4 for a NAND, 0 for switches, lamps and cables, the whole inside for a component; the NAND in the palette shows 4T). The count is 4 per CMOS NAND gate the simulator builds, at every depth; a test checks this against the flattened circuit for every example and every wide gate.
|
||||||
- Clicking anything opens its settings on the right. Parts can be swapped in place (wires stay on the pins in the same position): NAND and components with each other, switch/button/clock/constants with each other, output/lamp/display with each other. Clocks have their own frequency or follow the top bar. Switches and buttons can get a keyboard key. Lamps and displays have colours, notes have sizes, components a name on the canvas. Components can be unpacked into their parts or given their own copy of the definition; any part can have all its wires unlinked.
|
- Clicking anything opens its settings in the side panel. Parts can be swapped in place (wires stay on the pins in the same position): NAND and components with each other, switch/button/clock/constants with each other, output/lamp/display with each other. Clocks have their own frequency or follow the top bar. Switches and buttons can get a keyboard key. Lamps and displays have colours, notes have sizes, components a name on the canvas. Components can be unpacked into their parts or given their own copy of the definition; any part can have all its wires unlinked.
|
||||||
- Select parts and press "Make component" to turn them into a new component; wires crossing the selection become pins.
|
- Select parts and press "Make component" to turn them into a new component; wires crossing the selection become pins.
|
||||||
- Gate symbols in IEC 60617 (DIN, default) or ANSI. A component with one output can be drawn as a gate symbol.
|
- Gate symbols in IEC 60617 (DIN, default) or ANSI. A component with one output can be drawn as a gate symbol.
|
||||||
- Wires of different signals never share a line: auto-routed wires pick a free column or a detour, and anything still clashing (hand-placed bends) is drawn on its own lane. Crossings are drawn as a bow, triangle, bridge, gap or plain crossing (Settings, the gear in the top bar). Clicking a junction dot selects its whole signal.
|
- Wires of different signals never share a line: auto-routed wires pick a free column or a detour, and anything still clashing (hand-placed bends) is drawn on its own lane. Crossings are drawn as a bow, triangle, bridge, gap or plain crossing (Settings, the gear in the top bar). Clicking a junction dot selects its whole signal.
|
||||||
|
|
|
||||||
|
|
@ -57,33 +57,27 @@ kbd {
|
||||||
/* ── Layout ─────────────────────────────────────────────────────── */
|
/* ── Layout ─────────────────────────────────────────────────────── */
|
||||||
.app {
|
.app {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-rows: 44px 1fr;
|
grid-template-rows: auto 1fr;
|
||||||
height: 100dvh;
|
height: 100dvh;
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace {
|
.workspace {
|
||||||
--left: 232px;
|
--left: 272px;
|
||||||
--right: 272px;
|
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: var(--left) 1fr var(--right);
|
grid-template-columns: var(--left) 1fr;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace.no-left {
|
.workspace.no-panel {
|
||||||
--left: 36px !important;
|
--left: 36px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace.no-right {
|
|
||||||
--right: 36px !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.stage {
|
.stage {
|
||||||
position: relative;
|
position: relative;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.palette,
|
|
||||||
.inspector {
|
.inspector {
|
||||||
background: var(--panel);
|
background: var(--panel);
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
|
|
@ -91,12 +85,8 @@ kbd {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
.palette {
|
|
||||||
border-right: 1px solid var(--border);
|
|
||||||
}
|
|
||||||
|
|
||||||
.inspector {
|
.inspector {
|
||||||
border-left: 1px solid var(--border);
|
border-right: 1px solid var(--border);
|
||||||
}
|
}
|
||||||
|
|
||||||
.scroll {
|
.scroll {
|
||||||
|
|
@ -109,8 +99,7 @@ kbd {
|
||||||
|
|
||||||
@media (max-width: 1100px) {
|
@media (max-width: 1100px) {
|
||||||
.workspace {
|
.workspace {
|
||||||
--left: 210px;
|
--left: 252px;
|
||||||
--right: 260px;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,11 +108,10 @@ kbd {
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
grid-template-rows: 1fr 40%;
|
grid-template-rows: 1fr 40%;
|
||||||
}
|
}
|
||||||
.palette {
|
.workspace > .inspector,
|
||||||
display: none;
|
.workspace > .rail {
|
||||||
}
|
order: 2;
|
||||||
.inspector {
|
border-right: 0;
|
||||||
border-left: 0;
|
|
||||||
border-top: 1px solid var(--border);
|
border-top: 1px solid var(--border);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -328,7 +316,7 @@ kbd {
|
||||||
color: var(--muted);
|
color: var(--muted);
|
||||||
}
|
}
|
||||||
|
|
||||||
.palette h3,
|
.challenges-panel h3,
|
||||||
.inspector h3 {
|
.inspector h3 {
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
|
|
@ -337,8 +325,8 @@ kbd {
|
||||||
color: var(--muted);
|
color: var(--muted);
|
||||||
}
|
}
|
||||||
|
|
||||||
.palette h3 {
|
.challenges-panel h3 {
|
||||||
padding: 14px 12px 6px;
|
padding: 14px 6px 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.items {
|
.items {
|
||||||
|
|
@ -380,7 +368,7 @@ kbd {
|
||||||
color: var(--accent);
|
color: var(--accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Transistor count next to a component in the palette. */
|
/* Transistor count next to a component in a parts list. */
|
||||||
.tcount {
|
.tcount {
|
||||||
font-family: var(--font-mono);
|
font-family: var(--font-mono);
|
||||||
font-size: 10px;
|
font-size: 10px;
|
||||||
|
|
@ -2198,7 +2186,7 @@ kbd {
|
||||||
color: var(--on);
|
color: var(--on);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── Campaign and puzzles (palette) ─────────────────────────────── */
|
/* ── Campaign and puzzles (challenges) ─────────────────────────────── */
|
||||||
.campaign,
|
.campaign,
|
||||||
.weekly {
|
.weekly {
|
||||||
margin: 12px 12px 4px;
|
margin: 12px 12px 4px;
|
||||||
|
|
@ -2657,14 +2645,10 @@ kbd {
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.rail.left {
|
.rail {
|
||||||
border-right: 1px solid var(--border);
|
border-right: 1px solid var(--border);
|
||||||
}
|
}
|
||||||
|
|
||||||
.rail.right {
|
|
||||||
border-left: 1px solid var(--border);
|
|
||||||
}
|
|
||||||
|
|
||||||
.rail-btn {
|
.rail-btn {
|
||||||
display: grid;
|
display: grid;
|
||||||
place-items: center;
|
place-items: center;
|
||||||
|
|
@ -4224,16 +4208,26 @@ table.board {
|
||||||
/* ── Bottom bar: parts by kind, like Figma's toolbar ────────────── */
|
/* ── Bottom bar: parts by kind, like Figma's toolbar ────────────── */
|
||||||
.bottom-dock {
|
.bottom-dock {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 50%;
|
left: 12px;
|
||||||
|
right: 12px;
|
||||||
bottom: 14px;
|
bottom: 14px;
|
||||||
z-index: 20;
|
z-index: 20;
|
||||||
transform: translateX(-50%);
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bottom-dock > * {
|
||||||
|
pointer-events: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bottom-bar {
|
.bottom-bar {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 2px;
|
gap: 2px;
|
||||||
|
max-width: 100%;
|
||||||
|
overflow-x: auto;
|
||||||
|
scrollbar-width: none;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
background: rgb(26 33 43 / 0.96);
|
background: rgb(26 33 43 / 0.96);
|
||||||
border: 1px solid var(--border);
|
border: 1px solid var(--border);
|
||||||
|
|
@ -4246,6 +4240,7 @@ table.board {
|
||||||
|
|
||||||
.bar-btn {
|
.bar-btn {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-shrink: 0;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 6px;
|
gap: 6px;
|
||||||
height: 34px;
|
height: 34px;
|
||||||
|
|
@ -4472,6 +4467,143 @@ table.board {
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
}
|
}
|
||||||
|
|
||||||
.palette .tabs button {
|
/* ── Top bar: floating like the parts bar, across the whole width ─ */
|
||||||
white-space: nowrap;
|
.top-dock {
|
||||||
|
position: relative;
|
||||||
|
z-index: 30;
|
||||||
|
padding: 8px 8px 6px;
|
||||||
|
background: var(--bg);
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-bar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 10px;
|
||||||
|
min-width: 0;
|
||||||
|
padding: 4px;
|
||||||
|
background: rgb(26 33 43 / 0.96);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 12px;
|
||||||
|
box-shadow:
|
||||||
|
0 6px 20px rgb(0 0 0 / 0.35),
|
||||||
|
0 1px 0 rgb(255 255 255 / 0.03) inset;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tb-group {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-bar .bar-btn {
|
||||||
|
height: 32px;
|
||||||
|
padding: 0 9px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-bar .bar-btn:disabled {
|
||||||
|
opacity: 0.35;
|
||||||
|
cursor: not-allowed;
|
||||||
|
background: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-bar .bar-btn.here:disabled {
|
||||||
|
opacity: 1;
|
||||||
|
color: var(--text);
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-bar .tb-select {
|
||||||
|
height: 30px;
|
||||||
|
font-size: 12px;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-btn {
|
||||||
|
color: var(--on) !important;
|
||||||
|
max-width: 260px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.project-name {
|
||||||
|
color: var(--text);
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.crumbs {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1px;
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.crumb {
|
||||||
|
min-width: 0;
|
||||||
|
max-width: 180px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.crumb-sep {
|
||||||
|
flex-shrink: 0;
|
||||||
|
color: var(--muted);
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bar-count {
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-pop {
|
||||||
|
position: absolute;
|
||||||
|
top: calc(100% + 10px);
|
||||||
|
left: 50%;
|
||||||
|
width: 340px;
|
||||||
|
max-height: min(72vh, 640px);
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 10px;
|
||||||
|
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);
|
||||||
|
scrollbar-width: thin;
|
||||||
|
scrollbar-color: var(--border) transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.drop-enter-active,
|
||||||
|
.drop-leave-active {
|
||||||
|
transition:
|
||||||
|
opacity 0.12s,
|
||||||
|
translate 0.12s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.drop-enter-from,
|
||||||
|
.drop-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
translate: 0 -4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1100px) {
|
||||||
|
.top-bar .status {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pinned parts at the start of the parts bar. */
|
||||||
|
.bar-btn.pinned-part {
|
||||||
|
padding: 0 8px;
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.bar-btn.blocked {
|
||||||
|
opacity: 0.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1600px) {
|
||||||
|
.bottom-bar:has(.pinned-part) .bar-label {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,15 +36,13 @@ watch(
|
||||||
<EditorMainMenu v-if="ed.screen.value === 'menu'" />
|
<EditorMainMenu v-if="ed.screen.value === 'menu'" />
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<EditorToolbar />
|
<EditorToolbar />
|
||||||
<div class="workspace" :class="{ 'no-left': !ed.sidebars.left, 'no-right': !ed.sidebars.right }">
|
<div class="workspace" :class="{ 'no-panel': !ed.sidebars.right }">
|
||||||
<EditorPalette v-if="ed.sidebars.left" />
|
<EditorInspector v-if="ed.sidebars.right" />
|
||||||
<EditorRail v-else side="left" />
|
<EditorRail v-else />
|
||||||
<main class="stage">
|
<main class="stage">
|
||||||
<EditorCanvas />
|
<EditorCanvas />
|
||||||
<EditorBottomBar />
|
<EditorBottomBar />
|
||||||
</main>
|
</main>
|
||||||
<EditorInspector v-if="ed.sidebars.right" />
|
|
||||||
<EditorRail v-else side="right" />
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<Transition name="fade">
|
<Transition name="fade">
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@
|
||||||
// The floating bar at the bottom of the canvas, like Figma's toolbar: one
|
// The floating bar at the bottom of the canvas, like Figma's toolbar: one
|
||||||
// button per kind of part. Pointing at one opens its parts above it; click
|
// button per kind of part. Pointing at one opens its parts above it; click
|
||||||
// a part to place it (or drag it onto the canvas), pin it to keep it on the
|
// a part to place it (or drag it onto the canvas), pin it to keep it on the
|
||||||
// left. Components and your connector types have their own buttons.
|
// bar itself. Components and your connector types have their own buttons.
|
||||||
import { shortCount } from '~/lib/logic/analyze'
|
import { shortCount } from '~/lib/logic/analyze'
|
||||||
import { BASIC_GROUPS } from '~/composables/useParts'
|
import { BASIC_GROUPS } from '~/composables/useParts'
|
||||||
import type { ComponentDef, NodeKind } from '~/lib/logic/types'
|
import type { ComponentDef, NodeKind } from '~/lib/logic/types'
|
||||||
|
|
||||||
const ed = useEditor()
|
const ed = useEditor()
|
||||||
const { place, dragStart, dragEnd, isPinned, togglePin } = usePlace()
|
const { place, dragStart, dragEnd, isPinned, togglePin, pinned, unpin } = usePlace()
|
||||||
const { componentGroups } = useParts()
|
const { componentGroups } = useParts()
|
||||||
|
|
||||||
const ICONS: Record<string, string> = {
|
const ICONS: Record<string, string> = {
|
||||||
|
|
@ -79,6 +79,9 @@ const activeCat = computed(() => {
|
||||||
const group = computed(() => BASIC_GROUPS.find(g => g.name === open.value))
|
const group = computed(() => BASIC_GROUPS.find(g => g.name === open.value))
|
||||||
const connectors = computed(() => ed.project.value.connectors ?? [])
|
const connectors = computed(() => ed.project.value.connectors ?? [])
|
||||||
const portsOk = computed(() => ed.canPlaceKind('portin'))
|
const portsOk = computed(() => ed.canPlaceKind('portin'))
|
||||||
|
// Pinned parts sit on the bar; a pinned component this project lacks is left out.
|
||||||
|
const shown = computed(() => pinned.value.filter(p => p.kind !== 'chip' || p.chip))
|
||||||
|
const named = (p: { kind: NodeKind }) => p.kind === 'chip' || p.kind === 'nand'
|
||||||
const placeable = (d: ComponentDef) => d.id !== ed.def.value.id && ed.canPlace(d.id)
|
const placeable = (d: ComponentDef) => d.id !== ed.def.value.id && ed.canPlace(d.id)
|
||||||
|
|
||||||
function onKey(e: KeyboardEvent) {
|
function onKey(e: KeyboardEvent) {
|
||||||
|
|
@ -114,7 +117,7 @@ onBeforeUnmount(() => window.removeEventListener('keydown', onKey, true))
|
||||||
<span class="grow truncate">{{ p.name }}</span>
|
<span class="grow truncate">{{ p.name }}</span>
|
||||||
<kbd v-if="p.key">{{ p.key }}</kbd>
|
<kbd v-if="p.key">{{ p.key }}</kbd>
|
||||||
</button>
|
</button>
|
||||||
<button class="pin-btn" :class="{ on: isPinned(p.kind) }" :title="isPinned(p.kind) ? 'Unpin from the left' : 'Pin to the left, to have it at hand'" @click="togglePin(p.kind)">
|
<button class="pin-btn" :class="{ on: isPinned(p.kind) }" :title="isPinned(p.kind) ? 'Unpin from the bar' : 'Pin to the bar, to have it at hand'" @click="togglePin(p.kind)">
|
||||||
<Icon :name="isPinned(p.kind) ? 'lucide:pin-off' : 'lucide:pin'" class="size-3.5" />
|
<Icon :name="isPinned(p.kind) ? 'lucide:pin-off' : 'lucide:pin'" class="size-3.5" />
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
|
|
@ -171,19 +174,45 @@ onBeforeUnmount(() => window.removeEventListener('keydown', onKey, true))
|
||||||
<span class="grow truncate">{{ d.name }}</span>
|
<span class="grow truncate">{{ d.name }}</span>
|
||||||
<span v-if="ed.transistors(d.id)" class="flyout-note">{{ shortCount(ed.transistors(d.id)) }}T</span>
|
<span v-if="ed.transistors(d.id)" class="flyout-note">{{ shortCount(ed.transistors(d.id)) }}T</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="pin-btn" :class="{ on: isPinned('chip', d) }" :title="isPinned('chip', d) ? 'Unpin from the left' : 'Pin to the left'" @click="togglePin('chip', d)">
|
<button v-if="d.id !== ed.def.value.id" class="pin-btn" title="Open it and edit inside (or double-click it on the canvas)" @click="ed.open(d.id), (open = null)">
|
||||||
|
<Icon name="lucide:pencil" class="size-3.5" />
|
||||||
|
</button>
|
||||||
|
<button class="pin-btn" :class="{ on: isPinned('chip', d) }" :title="isPinned('chip', d) ? 'Unpin from the bar' : 'Pin to the bar'" @click="togglePin('chip', d)">
|
||||||
<Icon :name="isPinned('chip', d) ? 'lucide:pin-off' : 'lucide:pin'" class="size-3.5" />
|
<Icon :name="isPinned('chip', d) ? 'lucide:pin-off' : 'lucide:pin'" class="size-3.5" />
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
<button class="flyout-new" @click="ed.createComponent(), (open = null)"><Icon name="lucide:plus" class="size-4" /> New component</button>
|
<div class="flex gap-1">
|
||||||
|
<button class="flyout-new grow" @click="ed.createComponent(), (open = null)"><Icon name="lucide:plus" class="size-4" /> New component</button>
|
||||||
|
<button class="flyout-new" title="NOT, AND, … up to a 4-bit counter, all built from NAND" @click="ed.loadExamples(), (open = null)"><Icon name="lucide:book-open" class="size-4" /> Examples</button>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</Transition>
|
</Transition>
|
||||||
|
|
||||||
<nav class="bottom-bar" aria-label="Parts" @pointerleave="leave">
|
<nav class="bottom-bar" aria-label="Parts" @pointerleave="leave">
|
||||||
|
<template v-if="shown.length">
|
||||||
|
<button
|
||||||
|
v-for="p in shown"
|
||||||
|
:key="p.pin"
|
||||||
|
class="bar-btn pinned-part"
|
||||||
|
:class="{ blocked: p.missing, active: ed.placing.value?.kind === p.kind && ed.placing.value?.chip === p.chip }"
|
||||||
|
:title="`${p.name}${p.key ? ` (${p.key})` : ''}: click to place, drag onto the canvas. Right-click to unpin`"
|
||||||
|
:draggable="!p.missing"
|
||||||
|
@pointerenter="leave"
|
||||||
|
@click="pick(p.kind, p.chip)"
|
||||||
|
@contextmenu.prevent="unpin(p.pin)"
|
||||||
|
@dragstart="dragStart($event, p.kind, p.chip)"
|
||||||
|
@dragend="dragEnd"
|
||||||
|
>
|
||||||
|
<!-- Gates and components by name, the rest (switch, lamp, clock) by icon. -->
|
||||||
|
<Icon v-if="!named(p)" :name="p.icon" class="size-[18px]" />
|
||||||
|
<span v-else>{{ p.name }}</span>
|
||||||
|
</button>
|
||||||
|
<span class="bar-sep" />
|
||||||
|
</template>
|
||||||
<button
|
<button
|
||||||
v-for="c in cats"
|
v-for="c in cats"
|
||||||
:key="c.id"
|
:key="c.id"
|
||||||
|
|
@ -197,7 +226,7 @@ onBeforeUnmount(() => window.removeEventListener('keydown', onKey, true))
|
||||||
<span class="bar-label">{{ c.label }}</span>
|
<span class="bar-label">{{ c.label }}</span>
|
||||||
</button>
|
</button>
|
||||||
<span class="bar-sep" />
|
<span class="bar-sep" />
|
||||||
<button class="bar-btn" title="Find a part (/)" @click="ed.toggleSidebar('left', true), ed.partSearch.value++">
|
<button class="bar-btn" title="Find a part (/)" @click="ed.partSearch.value++">
|
||||||
<Icon name="lucide:search" class="size-[18px]" />
|
<Icon name="lucide:search" class="size-[18px]" />
|
||||||
</button>
|
</button>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
|
||||||
|
|
@ -953,12 +953,10 @@ function onKey(e: KeyboardEvent) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
return openMenuForSelection()
|
return openMenuForSelection()
|
||||||
}
|
}
|
||||||
// Finding parts from the keyboard: / searches the parts list, Shift+A or Ctrl+K adds one at the mouse.
|
// Finding parts from the keyboard: /, Shift+A or Ctrl+K add one at the mouse.
|
||||||
if (e.key === '/' && !mod) {
|
if (e.key === '/' && !mod) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
ed.toggleSidebar('left', true)
|
return openQuickAdd()
|
||||||
ed.partSearch.value++
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if ((e.shiftKey && key === 'a' && !mod) || (mod && key === 'k')) {
|
if ((e.shiftKey && key === 'a' && !mod) || (mod && key === 'k')) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
@ -1031,8 +1029,7 @@ function onKey(e: KeyboardEvent) {
|
||||||
if (n?.kind === 'chip' && n.chip) ed.open(n.chip)
|
if (n?.kind === 'chip' && n.chip) ed.open(n.chip)
|
||||||
} else if (!mod && !e.altKey && key === 'w' && ed.selection.value.length) ed.startLinking(ed.selection.value, e.shiftKey ? 'in' : undefined)
|
} else if (!mod && !e.altKey && key === 'w' && ed.selection.value.length) ed.startLinking(ed.selection.value, e.shiftKey ? 'in' : undefined)
|
||||||
else if (!mod && !e.altKey && key === 'f') fit()
|
else if (!mod && !e.altKey && key === 'f') fit()
|
||||||
else if (!mod && !e.altKey && e.key === '[') ed.toggleSidebar('left')
|
else if (!mod && !e.altKey && (e.key === '[' || e.key === ']')) ed.toggleSidebar('right')
|
||||||
else if (!mod && !e.altKey && e.key === ']') ed.toggleSidebar('right')
|
|
||||||
else if (!mod && !e.altKey && e.key === '?') ed.showHelp.value = !ed.showHelp.value
|
else if (!mod && !e.altKey && e.key === '?') ed.showHelp.value = !ed.showHelp.value
|
||||||
else if (!mod && !e.altKey && QUICK[key] && ed.canPlaceKind(QUICK[key]!)) ed.placing.value = { kind: QUICK[key]! }
|
else if (!mod && !e.altKey && QUICK[key] && ed.canPlaceKind(QUICK[key]!)) ed.placing.value = { kind: QUICK[key]! }
|
||||||
}
|
}
|
||||||
|
|
@ -1237,14 +1234,17 @@ watch(
|
||||||
const quick = ref<{ x: number; y: number; at: Pt } | null>(null)
|
const quick = ref<{ x: number; y: number; at: Pt } | null>(null)
|
||||||
let lastClient = { x: 0, y: 0 }
|
let lastClient = { x: 0, y: 0 }
|
||||||
|
|
||||||
function openQuickAdd() {
|
function openQuickAdd(centre = false) {
|
||||||
const r = root.value!.getBoundingClientRect()
|
const r = root.value!.getBoundingClientRect()
|
||||||
const inside = lastClient.x >= r.left && lastClient.x <= r.right && lastClient.y >= r.top && lastClient.y <= r.bottom
|
const inside = !centre && lastClient.x >= r.left && lastClient.x <= r.right && lastClient.y >= r.top && lastClient.y <= r.bottom
|
||||||
const x = inside ? lastClient.x : r.left + r.width / 2
|
const x = inside ? lastClient.x : r.left + r.width / 2
|
||||||
const y = inside ? lastClient.y : r.top + r.height / 3
|
const y = inside ? lastClient.y : r.top + r.height / 3
|
||||||
quick.value = { x, y, at: toWorld({ clientX: x, clientY: y }) }
|
quick.value = { x, y, at: toWorld({ clientX: x, clientY: y }) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The search button in the parts bar opens it in the middle of the canvas.
|
||||||
|
watch(ed.partSearch, () => openQuickAdd(true))
|
||||||
|
|
||||||
function onQuickPick(p: { kind: CircuitNode['kind']; chip?: string }) {
|
function onQuickPick(p: { kind: CircuitNode['kind']; chip?: string }) {
|
||||||
const q = quick.value
|
const q = quick.value
|
||||||
quick.value = null
|
quick.value = null
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
// Challenges, puzzles and the puzzle of the week, opened from the top bar.
|
||||||
|
// Starting one opens its circuit; the Test tab then shows what to build.
|
||||||
|
import { CHALLENGES } from '~/lib/logic/challenges'
|
||||||
|
import { campaignProgress, challengeName, challengeOpen, isCampaign, NEEDS } from '~/lib/logic/progress'
|
||||||
|
import { weekKey, weeklyId } from '~/lib/logic/puzzles'
|
||||||
|
|
||||||
|
const ed = useEditor()
|
||||||
|
const emit = defineEmits<{ close: [] }>()
|
||||||
|
|
||||||
|
const solved = computed(() => new Set(ed.project.value.solved))
|
||||||
|
const best = computed(() => ed.project.value.best ?? {})
|
||||||
|
const solvedCount = computed(() => CHALLENGES.filter(c => solved.value.has(c.id)).length)
|
||||||
|
const campaign = computed(() => isCampaign(ed.project.value))
|
||||||
|
const progress = computed(() => campaignProgress(ed.project.value))
|
||||||
|
const open = (id: string) => challengeOpen(ed.project.value, id)
|
||||||
|
const needsText = (id: string) => `Solve ${(NEEDS[id] ?? []).filter(n => !solved.value.has(n)).map(challengeName).join(' and ')} first`
|
||||||
|
const puzzles = computed(() => (ed.project.value.puzzles ?? []).filter(p => !p.id.startsWith('week:') || p.id === weeklyId(weekKey())))
|
||||||
|
const weeklyStarted = computed(() => ed.project.value.components.some(d => d.challenge === weeklyId(weekKey())))
|
||||||
|
const started = computed(() => new Map(ed.project.value.components.filter(d => d.challenge).map(d => [d.challenge!, d])))
|
||||||
|
|
||||||
|
function openWeekly() {
|
||||||
|
const spec = ed.project.value.puzzles?.find(p => p.id === weeklyId(weekKey()))
|
||||||
|
if (spec) ed.beginPuzzle(spec)
|
||||||
|
else void ed.openPuzzle('weekly')
|
||||||
|
emit('close')
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ solvedCount })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="challenges-panel" @click="($event.target as HTMLElement).closest('.btn-sm:not(:disabled)') && emit('close')">
|
||||||
|
<div v-if="campaign" class="campaign">
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<span class="font-semibold">Campaign</span>
|
||||||
|
<span class="tabular-nums text-(--muted)">{{ solvedCount }} / {{ CHALLENGES.length }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="bar"><span :style="{ width: `${progress * 100}%` }" /></div>
|
||||||
|
<p>Every part you solve becomes yours to use. New parts and challenges open as you go.</p>
|
||||||
|
</div>
|
||||||
|
<p v-else class="intro">
|
||||||
|
Build each part from NAND and the parts you already made. Start a challenge, wire it up, then press
|
||||||
|
<strong>Check</strong> in the side panel.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="weekly">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<Icon name="lucide:calendar-days" class="size-4 shrink-0 text-(--accent)" />
|
||||||
|
<span class="grow font-medium">Puzzle of the week</span>
|
||||||
|
<button class="btn-sm" @click="openWeekly">{{ weeklyStarted ? 'Open' : 'Play' }}</button>
|
||||||
|
</div>
|
||||||
|
<p>A new logic puzzle every Monday, the same for everyone. Fewest transistors wins.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template v-if="puzzles.length">
|
||||||
|
<h3>Puzzles</h3>
|
||||||
|
<ul class="challenges">
|
||||||
|
<li v-for="p in puzzles" :key="p.id" :class="{ solved: solved.has(p.id) }">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<Icon :name="solved.has(p.id) ? 'lucide:circle-check' : 'lucide:puzzle'" class="size-4 shrink-0" :class="solved.has(p.id) ? 'text-(--on)' : 'text-(--muted)'" />
|
||||||
|
<span class="grow font-medium">{{ p.name }}</span>
|
||||||
|
<button class="btn-sm" @click="ed.beginPuzzle(p)">Open</button>
|
||||||
|
</div>
|
||||||
|
<p class="pins">
|
||||||
|
{{ p.inputs.join(', ') }} → {{ p.outputs.join(', ') }}
|
||||||
|
<span v-if="best[p.id] !== undefined" class="best"> · best {{ best[p.id]!.toLocaleString() }} transistors</span>
|
||||||
|
</p>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<h3>Challenges</h3>
|
||||||
|
<ul class="challenges">
|
||||||
|
<li v-for="c in CHALLENGES" :key="c.id" :class="{ solved: solved.has(c.id), locked: !open(c.id) }">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<Icon
|
||||||
|
:name="solved.has(c.id) ? 'lucide:circle-check' : open(c.id) ? 'lucide:circle' : 'lucide:lock'"
|
||||||
|
class="size-4 shrink-0"
|
||||||
|
:class="solved.has(c.id) ? 'text-(--on)' : 'text-(--muted)'"
|
||||||
|
/>
|
||||||
|
<span class="grow font-medium">{{ c.name }}</span>
|
||||||
|
<button class="btn-sm" :disabled="!open(c.id) && !started.has(c.id)" :title="open(c.id) ? '' : needsText(c.id)" @click="ed.beginChallenge(c)">
|
||||||
|
{{ started.has(c.id) ? 'Open' : 'Start' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p v-if="!open(c.id)" class="needs">{{ needsText(c.id) }}</p>
|
||||||
|
<p>{{ c.goal }}</p>
|
||||||
|
<p class="pins">
|
||||||
|
{{ c.inputs.join(', ') }} → {{ c.outputs.join(', ') }}
|
||||||
|
<span v-if="best[c.id] !== undefined" class="best" title="Fewest transistors in a passing solution so far">
|
||||||
|
· best {{ best[c.id]!.toLocaleString() }} transistors
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
@ -4,9 +4,9 @@ const ed = useEditor()
|
||||||
const SHORTCUTS: [string, string][] = [
|
const SHORTCUTS: [string, string][] = [
|
||||||
['Esc (nothing selected)', 'Pause menu: save, save as copy, load, settings, main menu'],
|
['Esc (nothing selected)', 'Pause menu: save, save as copy, load, settings, main menu'],
|
||||||
['Click switch', 'Flip an input between 0 and 1 (give it a keyboard key in its settings)'],
|
['Click switch', 'Flip an input between 0 and 1 (give it a keyboard key in its settings)'],
|
||||||
['Click anything', 'Its settings appear on the right: swap the part, clock speed, colours, keys, position'],
|
['Click anything', 'Its settings appear in the side panel on the left: swap the part, clock speed, colours, keys, position'],
|
||||||
['Select several', 'Change them all at once: swap, rename D0, D1, …, switch all to 0 or 1, line up'],
|
['Select several', 'Change them all at once: swap, rename D0, D1, …, switch all to 0 or 1, line up'],
|
||||||
['Pins tab (right)', 'Every input and output in one list: rename them one after another with Enter'],
|
['Pins tab (side panel)', 'Every input and output in one list: rename them one after another with Enter'],
|
||||||
['Drag from a pin', 'Draw a wire to another pin; dropping it on a part uses that part’s next free pin'],
|
['Drag from a pin', 'Draw a wire to another pin; dropping it on a part uses that part’s next free pin'],
|
||||||
['Click a pin, then another', 'The same without holding the mouse button'],
|
['Click a pin, then another', 'The same without holding the mouse button'],
|
||||||
['Select parts, then W', 'Connect one by one: click where each of their pins goes, in order (Shift+W: their inputs)'],
|
['Select parts, then W', 'Connect one by one: click where each of their pins goes, in order (Shift+W: their inputs)'],
|
||||||
|
|
@ -23,7 +23,9 @@ const SHORTCUTS: [string, string][] = [
|
||||||
['Right or middle drag, Space + drag', 'Move the view'],
|
['Right or middle drag, Space + drag', 'Move the view'],
|
||||||
['Mouse wheel', 'Zoom'],
|
['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'],
|
['N, I, O, L, B, C, H, T, P, X', 'Place NAND, input, output, lamp, button, clock, hex display, note, input panel, pixel'],
|
||||||
['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'],
|
['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 bar itself (right-click a pinned part to unpin it)'],
|
||||||
|
['Main (top bar)', 'Back to the main circuit; the names after it lead back to each component you entered'],
|
||||||
|
['[', 'Hide or show the side panel'],
|
||||||
['Connectors (bottom bar)', 'Make a cable type of your own (HDMI, RJ45): its lines; place its Out and In ports; one cable joins them'],
|
['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 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 cable plugged onto S0–S3 (or any group); drop its free end on the next part\'s pins'],
|
||||||
|
|
@ -36,7 +38,7 @@ const SHORTCUTS: [string, string][] = [
|
||||||
['Send signal / Use signal', 'Name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire'],
|
['Send signal / Use signal', 'Name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire'],
|
||||||
['Ctrl+F', 'Find a part, signal or component in every circuit, and where a component is used'],
|
['Ctrl+F', 'Find a part, signal or component in every circuit, and where a component is used'],
|
||||||
['Shift+A or Ctrl+K', 'Add a part at the mouse: type a few letters, arrows to choose, Enter to place'],
|
['Shift+A or Ctrl+K', 'Add a part at the mouse: type a few letters, arrows to choose, Enter to place'],
|
||||||
['/', 'Search the parts list; Enter starts placing the one chosen'],
|
['/', 'The same: find a part by name and place it'],
|
||||||
['Ctrl+P', 'Print the circuit as a sheet with a title block, or save it as PDF'],
|
['Ctrl+P', 'Print the circuit as a sheet with a title block, or save it as PDF'],
|
||||||
['Select switches or buttons, Combine', 'One input panel (all rows can become buttons); lamps or output pins combine into an output panel'],
|
['Select switches or buttons, Combine', 'One input panel (all rows can become buttons); lamps or output pins combine into an output panel'],
|
||||||
['Select panels, Merge', 'One panel with all their rows; inside a component input panel rows are inputs, output panel rows outputs'],
|
['Select panels, Merge', 'One panel with all their rows; inside a component input panel rows are inputs, output panel rows outputs'],
|
||||||
|
|
@ -46,7 +48,7 @@ const SHORTCUTS: [string, string][] = [
|
||||||
['Ctrl+C, Ctrl+V, Ctrl+D', 'Copy, paste, duplicate; names continue their series (D0 → D1)'],
|
['Ctrl+C, Ctrl+V, Ctrl+D', 'Copy, paste, duplicate; names continue their series (D0 → D1)'],
|
||||||
['Delete', 'Remove the selection'],
|
['Delete', 'Remove the selection'],
|
||||||
['Ctrl+Z, Ctrl+Shift+Z', 'Undo, redo'],
|
['Ctrl+Z, Ctrl+Shift+Z', 'Undo, redo'],
|
||||||
['Logo (top left)', 'Back to the main menu: free play, campaign, challenges, leaderboard. Your work is saved'],
|
['Logo (top left), Esc', 'Pause menu: save, load, settings, back to the main menu. Your work is saved'],
|
||||||
['F', 'Fit the circuit to the screen'],
|
['F', 'Fit the circuit to the screen'],
|
||||||
['Enter', 'Open the selected component'],
|
['Enter', 'Open the selected component'],
|
||||||
]
|
]
|
||||||
|
|
@ -77,10 +79,10 @@ function close() {
|
||||||
<strong>It runs while you draw.</strong> Green wires carry a 1, grey wires a 0. Flip switches, press buttons, or start the clock in the top bar.
|
<strong>It runs while you draw.</strong> Green wires carry a 1, grey wires a 0. Flip switches, press buttons, or start the clock in the top bar.
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<strong>Try the challenges</strong> on the left, or open the examples (NOT up to a 4-bit counter) to see how each step is made of the previous one.
|
<strong>Try the challenges</strong> (top bar), or open the examples (NOT up to a 4-bit counter) to see how each step is made of the previous one.
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<strong>Select parts and press "Make component"</strong> on the right to turn a piece of your drawing into a reusable block.
|
<strong>Select parts and press "Make component"</strong> in the side panel to turn a piece of your drawing into a reusable block.
|
||||||
</li>
|
</li>
|
||||||
</ol>
|
</ol>
|
||||||
<h3>Controls</h3>
|
<h3>Controls</h3>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
// The right panel: tabs for the selection, the circuit, its pins, and testing.
|
// The side panel: tabs for the selection, the circuit, its pins, and testing.
|
||||||
import { ioList } from '~/lib/logic/bulk'
|
import { ioList } from '~/lib/logic/bulk'
|
||||||
|
|
||||||
const ed = useEditor()
|
const ed = useEditor()
|
||||||
|
|
@ -54,8 +54,8 @@ watch(
|
||||||
<template>
|
<template>
|
||||||
<aside class="inspector">
|
<aside class="inspector">
|
||||||
<nav class="itabs" role="tablist">
|
<nav class="itabs" role="tablist">
|
||||||
<button class="collapse-btn" title="Hide this panel (])" @click="ed.toggleSidebar('right', false)">
|
<button class="collapse-btn" title="Hide this panel ([)" @click="ed.toggleSidebar('right', false)">
|
||||||
<Icon name="lucide:panel-right-close" class="size-4" />
|
<Icon name="lucide:panel-left-close" class="size-4" />
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
v-for="t in tabs"
|
v-for="t in tabs"
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ const parts = (id: string) =>
|
||||||
|
|
||||||
function fresh() {
|
function fresh() {
|
||||||
ed.newProject(false, true)
|
ed.newProject(false, true)
|
||||||
ed.paletteTab.value = 'challenges'
|
ed.challengesOpen.value = true
|
||||||
ed.enterGame()
|
ed.enterGame()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -1,298 +0,0 @@
|
||||||
<script setup lang="ts">
|
|
||||||
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 type { ComponentDef, NodeKind } from '~/lib/logic/types'
|
|
||||||
|
|
||||||
const ed = useEditor()
|
|
||||||
const tab = ed.paletteTab
|
|
||||||
const query = ref('')
|
|
||||||
|
|
||||||
const { componentGroups, search } = useParts()
|
|
||||||
const { place, dragStart, dragEnd, pinned, unpin } = usePlace()
|
|
||||||
|
|
||||||
// ── Search: type to narrow everything down; arrows pick, Enter places ──
|
|
||||||
const searchInput = ref<HTMLInputElement>()
|
|
||||||
const hits = computed(() => (query.value.trim() ? search(query.value, 30) : []))
|
|
||||||
const at = ref(0)
|
|
||||||
watch(query, () => (at.value = 0))
|
|
||||||
watch(
|
|
||||||
() => ed.partSearch.value,
|
|
||||||
() => {
|
|
||||||
tab.value = 'parts'
|
|
||||||
nextTick(() => {
|
|
||||||
searchInput.value?.focus()
|
|
||||||
searchInput.value?.select()
|
|
||||||
})
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
function onSearchKey(e: KeyboardEvent) {
|
|
||||||
const n = hits.value.length
|
|
||||||
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
||||||
e.preventDefault()
|
|
||||||
if (n) at.value = (at.value + (e.key === 'ArrowDown' ? 1 : -1) + n) % n
|
|
||||||
} else if (e.key === 'Enter') {
|
|
||||||
e.preventDefault()
|
|
||||||
const h = hits.value[at.value]
|
|
||||||
if (h) {
|
|
||||||
pick(h.kind, h.chip)
|
|
||||||
query.value = ''
|
|
||||||
searchInput.value?.blur()
|
|
||||||
}
|
|
||||||
} else if (e.key === 'Escape') {
|
|
||||||
query.value = ''
|
|
||||||
searchInput.value?.blur()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Groups that can be folded away; remembered in this browser ──
|
|
||||||
const FOLD_KEY = 'logigate:palette-folded'
|
|
||||||
const folded = ref<Set<string>>(
|
|
||||||
(() => {
|
|
||||||
try {
|
|
||||||
return new Set<string>(JSON.parse(localStorage.getItem(FOLD_KEY) ?? '[]'))
|
|
||||||
} catch {
|
|
||||||
return new Set<string>()
|
|
||||||
}
|
|
||||||
})(),
|
|
||||||
)
|
|
||||||
function fold(name: string) {
|
|
||||||
const next = new Set(folded.value)
|
|
||||||
if (!next.delete(name)) next.add(name)
|
|
||||||
folded.value = next
|
|
||||||
try {
|
|
||||||
localStorage.setItem(FOLD_KEY, JSON.stringify([...next]))
|
|
||||||
} catch {}
|
|
||||||
}
|
|
||||||
|
|
||||||
function pick(kind: NodeKind, chip?: string) {
|
|
||||||
if (chip && !ed.canPlace(chip)) return
|
|
||||||
if (!ed.canPlaceKind(kind)) {
|
|
||||||
ed.play('error')
|
|
||||||
return ed.notify(lockedHint(kind), 'error')
|
|
||||||
}
|
|
||||||
ed.placing.value = { kind, chip }
|
|
||||||
}
|
|
||||||
|
|
||||||
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, conn }))
|
|
||||||
if (e.dataTransfer) e.dataTransfer.effectAllowed = 'copy'
|
|
||||||
ed.dragPart.value = { kind, chip, conn }
|
|
||||||
}
|
|
||||||
|
|
||||||
const solved = computed(() => new Set(ed.project.value.solved))
|
|
||||||
const best = computed(() => ed.project.value.best ?? {})
|
|
||||||
const solvedCount = computed(() => CHALLENGES.filter(c => solved.value.has(c.id)).length)
|
|
||||||
const campaign = computed(() => isCampaign(ed.project.value))
|
|
||||||
const progress = computed(() => campaignProgress(ed.project.value))
|
|
||||||
const open = (id: string) => challengeOpen(ed.project.value, id)
|
|
||||||
const needsText = (id: string) => `Solve ${(NEEDS[id] ?? []).filter(n => !solved.value.has(n)).map(challengeName).join(' and ')} first`
|
|
||||||
const puzzles = computed(() => (ed.project.value.puzzles ?? []).filter(p => !p.id.startsWith('week:') || p.id === weeklyId(weekKey())))
|
|
||||||
const weeklyStarted = computed(() => ed.project.value.components.some(d => d.challenge === weeklyId(weekKey())))
|
|
||||||
|
|
||||||
function lockedHint(kind: NodeKind) {
|
|
||||||
const by = KIND_UNLOCK[kind]
|
|
||||||
return by ? `Solve the ${challengeName(by)} challenge to unlock this part` : ''
|
|
||||||
}
|
|
||||||
|
|
||||||
function openWeekly() {
|
|
||||||
const spec = ed.project.value.puzzles?.find(p => p.id === weeklyId(weekKey()))
|
|
||||||
if (spec) ed.beginPuzzle(spec)
|
|
||||||
else void ed.openPuzzle('weekly')
|
|
||||||
}
|
|
||||||
|
|
||||||
function compTitle(d: ComponentDef) {
|
|
||||||
if (d.id === ed.def.value.id) return 'You are editing this one'
|
|
||||||
if (!defUsable(ed.project.value, d)) return 'Solve this challenge to use it as a part'
|
|
||||||
if (!ed.canPlace(d.id)) return 'Contains the circuit you are editing'
|
|
||||||
return d.description || 'Click, then click on the canvas to place'
|
|
||||||
}
|
|
||||||
const started = computed(() => new Map(ed.project.value.components.filter(d => d.challenge).map(d => [d.challenge!, d])))
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<aside class="palette">
|
|
||||||
<div class="tabs">
|
|
||||||
<button :class="{ active: tab === 'parts' }" @click="tab = 'parts'">Parts</button>
|
|
||||||
<button :class="{ active: tab === 'challenges' }" @click="tab = 'challenges'">
|
|
||||||
Challenges
|
|
||||||
<span class="count">{{ solvedCount }}/{{ CHALLENGES.length }}</span>
|
|
||||||
</button>
|
|
||||||
<button class="collapse-btn" title="Hide this panel ([)" @click="ed.toggleSidebar('left', false)">
|
|
||||||
<Icon name="lucide:panel-left-close" class="size-4" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="tab === 'parts'" class="scroll">
|
|
||||||
<div class="search part-search">
|
|
||||||
<Icon name="lucide:search" class="size-3.5 text-(--muted)" />
|
|
||||||
<input ref="searchInput" v-model="query" placeholder="Find a part" @keydown="onSearchKey" />
|
|
||||||
<kbd v-if="!query" title="Press / on the canvas to search, Shift+A to add at the mouse">/</kbd>
|
|
||||||
<button v-else class="icon-btn" title="Clear (Esc)" @click="query = ''"><Icon name="lucide:x" class="size-3.5" /></button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Searching: one list of everything that matches -->
|
|
||||||
<template v-if="query.trim()">
|
|
||||||
<p v-if="!hits.length" class="hint px-3 pt-3">Nothing called "{{ query.trim() }}" fits here.</p>
|
|
||||||
<ul class="items mt-2">
|
|
||||||
<li v-for="(h, i) in hits" :key="h.chip ?? h.kind">
|
|
||||||
<button
|
|
||||||
class="item"
|
|
||||||
:class="{ active: i === at }"
|
|
||||||
:draggable="true"
|
|
||||||
@click="pick(h.kind, h.chip)"
|
|
||||||
@dragstart="onDragStart($event, h.kind, h.chip)"
|
|
||||||
@dragend="ed.dragPart.value = null"
|
|
||||||
@pointerenter="at = i"
|
|
||||||
>
|
|
||||||
<span v-if="h.kind === 'nand'" class="nand-badge">&</span>
|
|
||||||
<Icon v-else :name="h.icon" class="size-4 shrink-0 text-(--muted)" />
|
|
||||||
<span class="grow truncate">{{ h.name }}</span>
|
|
||||||
<span class="group-tag">{{ h.group }}</span>
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<p class="hint px-3 pt-2">↑ ↓ to choose, Enter to place, Esc to clear.</p>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template v-else>
|
|
||||||
<!-- Pinned: the parts you use most, always at hand (pin more from the bar below) -->
|
|
||||||
<div class="pinned-head">
|
|
||||||
<span>Pinned</span>
|
|
||||||
<span class="hint">pin more from the bar below</span>
|
|
||||||
</div>
|
|
||||||
<ul v-if="pinned.length" class="pinned">
|
|
||||||
<li v-for="p in pinned" :key="p.pin">
|
|
||||||
<button
|
|
||||||
class="item"
|
|
||||||
:class="{ blocked: p.missing, active: !p.missing && ed.placing.value?.kind === p.kind && ed.placing.value?.chip === p.chip }"
|
|
||||||
:title="p.missing ? `${p.name} is not in this project, or not usable here yet` : `Place ${p.name}`"
|
|
||||||
:draggable="!p.missing"
|
|
||||||
@click="!p.missing && place(p.kind, p.chip)"
|
|
||||||
@dragstart="dragStart($event, p.kind, p.chip)"
|
|
||||||
@dragend="dragEnd"
|
|
||||||
>
|
|
||||||
<span v-if="p.kind === 'nand'" class="nand-badge">&</span>
|
|
||||||
<Icon v-else :name="p.icon" class="size-4 shrink-0 text-(--muted)" />
|
|
||||||
<span class="grow truncate">{{ p.name }}</span>
|
|
||||||
<kbd v-if="p.key">{{ p.key }}</kbd>
|
|
||||||
</button>
|
|
||||||
<button class="open" title="Unpin" @click="unpin(p.pin)"><Icon name="lucide:pin-off" class="size-3.5" /></button>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<p v-else class="hint px-3 pb-2">Nothing pinned. Point at a group in the bar below and pin what you use most.</p>
|
|
||||||
|
|
||||||
<div class="pinned-head mt-2"><span>Circuits</span></div>
|
|
||||||
<template v-for="g in componentGroups" :key="g.name">
|
|
||||||
<button class="group-head" @click="fold(`c:${g.name}`)">
|
|
||||||
<Icon :name="folded.has(`c:${g.name}`) ? 'lucide:chevron-right' : 'lucide:chevron-down'" class="size-3.5" />
|
|
||||||
<span>{{ g.name }}</span>
|
|
||||||
<span class="group-count">{{ g.defs.length }}</span>
|
|
||||||
</button>
|
|
||||||
<ul v-if="!folded.has(`c:${g.name}`)" class="items">
|
|
||||||
<li v-for="d in g.defs" :key="d.id" class="comp-row">
|
|
||||||
<button
|
|
||||||
class="item"
|
|
||||||
:class="{ active: ed.placing.value?.chip === d.id, current: d.id === ed.def.value.id, blocked: !ed.canPlace(d.id) }"
|
|
||||||
:title="compTitle(d)"
|
|
||||||
:draggable="ed.canPlace(d.id)"
|
|
||||||
@click="pick('chip', d.id)"
|
|
||||||
@dragstart="onDragStart($event, 'chip', d.id)"
|
|
||||||
@dragend="ed.dragPart.value = null"
|
|
||||||
>
|
|
||||||
<Icon :name="d.challenge && solved.has(d.challenge) ? 'lucide:badge-check' : 'lucide:box'" class="size-4 shrink-0" :class="d.challenge && solved.has(d.challenge) ? 'text-(--on)' : 'text-(--muted)'" />
|
|
||||||
<span class="grow truncate">{{ d.name }}</span>
|
|
||||||
<span v-if="d.id === ed.def.value.id" class="editing">editing</span>
|
|
||||||
<span v-else-if="ed.transistors(d.id)" class="tcount" :title="`${ed.transistors(d.id).toLocaleString()} transistors`">{{ shortCount(ed.transistors(d.id)) }}T</span>
|
|
||||||
</button>
|
|
||||||
<button v-if="d.id !== ed.def.value.id" class="open" title="Open and edit" @click="ed.open(d.id)">
|
|
||||||
<Icon name="lucide:pencil" class="size-3.5" />
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<div class="grid gap-2 px-3 pt-3 pb-4">
|
|
||||||
<button class="btn w-full" @click="ed.createComponent()">
|
|
||||||
<Icon name="lucide:plus" class="size-4" /> New component
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-ghost w-full" title="NOT, AND, … up to a 4-bit counter, all built from NAND" @click="ed.loadExamples()">
|
|
||||||
<Icon name="lucide:library" class="size-4" /> Add example parts
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-else class="scroll">
|
|
||||||
<div v-if="campaign" class="campaign">
|
|
||||||
<div class="flex items-center justify-between">
|
|
||||||
<span class="font-semibold">Campaign</span>
|
|
||||||
<span class="tabular-nums text-(--muted)">{{ solvedCount }} / {{ CHALLENGES.length }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="bar"><span :style="{ width: `${progress * 100}%` }" /></div>
|
|
||||||
<p>Every part you solve becomes yours to use. New parts and challenges open as you go.</p>
|
|
||||||
</div>
|
|
||||||
<p v-else class="intro">
|
|
||||||
Build each part from NAND and the parts you already made. Start a challenge, wire it up, then press
|
|
||||||
<strong>Check</strong> on the right.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="weekly">
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<Icon name="lucide:calendar-days" class="size-4 shrink-0 text-(--accent)" />
|
|
||||||
<span class="grow font-medium">Puzzle of the week</span>
|
|
||||||
<button class="btn-sm" @click="openWeekly">{{ weeklyStarted ? 'Open' : 'Play' }}</button>
|
|
||||||
</div>
|
|
||||||
<p>A new logic puzzle every Monday, the same for everyone. Fewest transistors wins.</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<template v-if="puzzles.length">
|
|
||||||
<h3>Puzzles</h3>
|
|
||||||
<ul class="challenges">
|
|
||||||
<li v-for="p in puzzles" :key="p.id" :class="{ solved: solved.has(p.id) }">
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<Icon :name="solved.has(p.id) ? 'lucide:circle-check' : 'lucide:puzzle'" class="size-4 shrink-0" :class="solved.has(p.id) ? 'text-(--on)' : 'text-(--muted)'" />
|
|
||||||
<span class="grow font-medium">{{ p.name }}</span>
|
|
||||||
<button class="btn-sm" @click="ed.beginPuzzle(p)">Open</button>
|
|
||||||
</div>
|
|
||||||
<p class="pins">
|
|
||||||
{{ p.inputs.join(', ') }} → {{ p.outputs.join(', ') }}
|
|
||||||
<span v-if="best[p.id] !== undefined" class="best"> · best {{ best[p.id]!.toLocaleString() }} transistors</span>
|
|
||||||
</p>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<h3>Challenges</h3>
|
|
||||||
<ul class="challenges">
|
|
||||||
<li v-for="c in CHALLENGES" :key="c.id" :class="{ solved: solved.has(c.id), locked: !open(c.id) }">
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<Icon
|
|
||||||
:name="solved.has(c.id) ? 'lucide:circle-check' : open(c.id) ? 'lucide:circle' : 'lucide:lock'"
|
|
||||||
class="size-4 shrink-0"
|
|
||||||
:class="solved.has(c.id) ? 'text-(--on)' : 'text-(--muted)'"
|
|
||||||
/>
|
|
||||||
<span class="grow font-medium">{{ c.name }}</span>
|
|
||||||
<button class="btn-sm" :disabled="!open(c.id) && !started.has(c.id)" :title="open(c.id) ? '' : needsText(c.id)" @click="ed.beginChallenge(c)">
|
|
||||||
{{ started.has(c.id) ? 'Open' : 'Start' }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<p v-if="!open(c.id)" class="needs">{{ needsText(c.id) }}</p>
|
|
||||||
<p>{{ c.goal }}</p>
|
|
||||||
<p class="pins">
|
|
||||||
{{ c.inputs.join(', ') }} → {{ c.outputs.join(', ') }}
|
|
||||||
<span v-if="best[c.id] !== undefined" class="best" title="Fewest transistors in a passing solution so far">
|
|
||||||
· best {{ best[c.id]!.toLocaleString() }} transistors
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</aside>
|
|
||||||
</template>
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
// A hidden side panel shrinks to this strip; its buttons bring it back.
|
// The side panel, hidden, shrinks to this strip; its buttons bring it back.
|
||||||
const props = defineProps<{ side: 'left' | 'right' }>()
|
|
||||||
const ed = useEditor()
|
const ed = useEditor()
|
||||||
|
|
||||||
const TABS = [
|
const TABS = [
|
||||||
|
|
@ -17,18 +16,12 @@ function openTab(id: (typeof TABS)[number]['id']) {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<aside class="rail" :class="props.side">
|
<aside class="rail">
|
||||||
<button
|
<button class="rail-btn" title="Show the side panel ([)" @click="ed.toggleSidebar('right', true)">
|
||||||
class="rail-btn"
|
<Icon name="lucide:panel-left-open" class="size-4" />
|
||||||
:title="props.side === 'left' ? 'Show parts and challenges ([)' : 'Show the side panel (])'"
|
|
||||||
@click="ed.toggleSidebar(props.side, true)"
|
|
||||||
>
|
|
||||||
<Icon :name="props.side === 'left' ? 'lucide:panel-left-open' : 'lucide:panel-right-open'" class="size-4" />
|
|
||||||
</button>
|
</button>
|
||||||
<template v-if="props.side === 'right'">
|
|
||||||
<button v-for="t in TABS" :key="t.id" class="rail-btn" :title="t.label" @click="openTab(t.id)">
|
<button v-for="t in TABS" :key="t.id" class="rail-btn" :title="t.label" @click="openTab(t.id)">
|
||||||
<Icon :name="t.icon" class="size-4" />
|
<Icon :name="t.icon" class="size-4" />
|
||||||
</button>
|
</button>
|
||||||
</template>
|
|
||||||
</aside>
|
</aside>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
// The bar along the top, floating like the parts bar below: menu and where
|
||||||
|
// you are on the left, the clock in the middle, the rest on the right.
|
||||||
|
import { CHALLENGES } from '~/lib/logic/challenges'
|
||||||
|
|
||||||
const ed = useEditor()
|
const ed = useEditor()
|
||||||
|
|
||||||
const SPEEDS = [
|
const SPEEDS = [
|
||||||
|
|
@ -13,10 +17,23 @@ const SPEEDS = [
|
||||||
|
|
||||||
const hasClock = computed(() => (ed.sim.value?.nl.clocks.length ?? 0) > 0)
|
const hasClock = computed(() => (ed.sim.value?.nl.clocks.length ?? 0) > 0)
|
||||||
const statusText = computed(() => ({ stable: 'Stable', busy: 'Settling', oscillating: 'Oscillating' })[ed.status.value])
|
const statusText = computed(() => ({ stable: 'Stable', busy: 'Settling', oscillating: 'Oscillating' })[ed.status.value])
|
||||||
const backName = computed(() => {
|
// The way into the open circuit: Main, then each component entered on the way.
|
||||||
const id = ed.nav.value.at(-1)
|
const path = computed(() =>
|
||||||
return id ? ed.getDef.value(id)?.name : undefined
|
[...ed.nav.value.map((id, i) => ({ id, i })), { id: ed.def.value.id, i: -1 }]
|
||||||
})
|
.filter(p => p.id !== ed.mainId.value)
|
||||||
|
.map(p => ({ ...p, name: ed.getDef.value(p.id)?.name ?? '?' })),
|
||||||
|
)
|
||||||
|
const atMain = computed(() => ed.def.value.id === ed.mainId.value)
|
||||||
|
|
||||||
|
// Challenges and puzzles open below their button.
|
||||||
|
const showChallenges = ed.challengesOpen
|
||||||
|
const challengesEl = ref<HTMLElement>()
|
||||||
|
const solvedCount = computed(() => CHALLENGES.filter(c => ed.project.value.solved.includes(c.id)).length)
|
||||||
|
function outside(e: PointerEvent) {
|
||||||
|
if (showChallenges.value && !challengesEl.value?.contains(e.target as Node)) showChallenges.value = false
|
||||||
|
}
|
||||||
|
onMounted(() => window.addEventListener('pointerdown', outside, true))
|
||||||
|
onBeforeUnmount(() => window.removeEventListener('pointerdown', outside, true))
|
||||||
const cloudText = computed(() => ({ off: '', syncing: 'syncing', synced: 'all saved', offline: 'offline', error: 'sync failed' })[ed.cloudState.value])
|
const cloudText = computed(() => ({ off: '', syncing: 'syncing', synced: 'all saved', offline: 'offline', error: 'sync failed' })[ed.cloudState.value])
|
||||||
const linkIcon = computed(() => {
|
const linkIcon = computed(() => {
|
||||||
switch (ed.linkState.value) {
|
switch (ed.linkState.value) {
|
||||||
|
|
@ -34,41 +51,55 @@ const linkIcon = computed(() => {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<header class="toolbar">
|
<div class="top-dock">
|
||||||
<div class="flex min-w-0 items-center gap-2">
|
<header class="top-bar">
|
||||||
<button class="brand" title="Main menu (your work is saved)" @click="ed.showMenu()">
|
<div class="tb-group min-w-0">
|
||||||
<svg viewBox="0 0 32 32" class="size-6" aria-hidden="true">
|
<button class="bar-btn brand-btn" title="Menu: save, load, settings, main menu (Esc)" @click="ed.pause()">
|
||||||
|
<svg viewBox="0 0 32 32" class="size-5" aria-hidden="true">
|
||||||
<path d="M6 7h10a9 9 0 0 1 0 18H6Z" fill="none" stroke="currentColor" stroke-width="2.5" />
|
<path d="M6 7h10a9 9 0 0 1 0 18H6Z" fill="none" stroke="currentColor" stroke-width="2.5" />
|
||||||
<circle cx="27" cy="16" r="2.6" fill="none" stroke="currentColor" stroke-width="2.2" />
|
<circle cx="27" cy="16" r="2.6" fill="none" stroke="currentColor" stroke-width="2.2" />
|
||||||
</svg>
|
</svg>
|
||||||
<span class="hidden xl:inline">Menu</span>
|
<span class="project-name truncate">{{ ed.project.value.name }}</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="tb-btn project-btn" title="Menu: save, load, settings (Esc)" @click="ed.pause()">
|
<span class="bar-sep" />
|
||||||
<Icon name="lucide:menu" class="size-4 shrink-0" />
|
<nav class="crumbs" aria-label="Where you are">
|
||||||
<span class="truncate">{{ ed.project.value.name }}</span>
|
<button class="bar-btn" :class="{ here: atMain }" :disabled="atMain" title="Go to Main (components open with a double-click)" @click="ed.goMain()">
|
||||||
|
<Icon name="lucide:house" class="size-4" />
|
||||||
|
<span>Main</span>
|
||||||
</button>
|
</button>
|
||||||
<span class="text-(--border)">/</span>
|
<template v-for="p in path" :key="`${p.id}-${p.i}`">
|
||||||
<button v-if="backName" class="tb-btn" :title="`Back to ${backName}`" @click="ed.back()">
|
<Icon name="lucide:chevron-right" class="crumb-sep size-3.5" />
|
||||||
<Icon name="lucide:arrow-left" class="size-4" />
|
<button class="bar-btn crumb" :class="{ here: p.i < 0 }" :disabled="p.i < 0" :title="p.i < 0 ? 'Editing this one' : `Back to ${p.name}`" @click="ed.goTo(p.i)">
|
||||||
|
<span class="truncate">{{ p.name }}</span>
|
||||||
</button>
|
</button>
|
||||||
<label class="circuit-select" title="Circuit you are editing">
|
</template>
|
||||||
<select :value="ed.def.value.id" @change="ed.open(($event.target as HTMLSelectElement).value)">
|
</nav>
|
||||||
<option v-for="d in ed.project.value.components" :key="d.id" :value="d.id">{{ d.name }}</option>
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center gap-1.5">
|
<div class="tb-group">
|
||||||
|
<div ref="challengesEl" class="relative">
|
||||||
|
<button class="bar-btn" :class="{ open: showChallenges }" title="Challenges, puzzles and the puzzle of the week" @click="showChallenges = !showChallenges">
|
||||||
|
<Icon name="lucide:flag" class="size-4" />
|
||||||
|
<span class="hidden lg:inline">Challenges</span>
|
||||||
|
<span class="bar-count">{{ solvedCount }}/{{ CHALLENGES.length }}</span>
|
||||||
|
</button>
|
||||||
|
<Transition name="drop">
|
||||||
|
<div v-if="showChallenges" class="top-pop">
|
||||||
|
<EditorChallengesPanel @close="showChallenges = false" />
|
||||||
|
</div>
|
||||||
|
</Transition>
|
||||||
|
</div>
|
||||||
|
<span class="bar-sep" />
|
||||||
<button
|
<button
|
||||||
class="tb-btn"
|
class="bar-btn"
|
||||||
:class="{ active: ed.running.value }"
|
:class="{ active: ed.running.value && hasClock }"
|
||||||
:title="ed.running.value ? 'Pause the clock' : 'Run the clock'"
|
:title="ed.running.value ? 'Pause the clock' : 'Run the clock'"
|
||||||
:disabled="!hasClock"
|
:disabled="!hasClock"
|
||||||
@click="ed.running.value = !ed.running.value"
|
@click="ed.running.value = !ed.running.value"
|
||||||
>
|
>
|
||||||
<Icon :name="ed.running.value ? 'lucide:pause' : 'lucide:play'" class="size-4" />
|
<Icon :name="ed.running.value ? 'lucide:pause' : 'lucide:play'" class="size-4" />
|
||||||
</button>
|
</button>
|
||||||
<button class="tb-btn" title="One clock cycle" :disabled="!hasClock" @click="ed.running.value = false; ed.step()">
|
<button class="bar-btn" title="One clock cycle" :disabled="!hasClock" @click="ed.running.value = false; ed.step()">
|
||||||
<Icon name="lucide:step-forward" class="size-4" />
|
<Icon name="lucide:step-forward" class="size-4" />
|
||||||
</button>
|
</button>
|
||||||
<select v-model.number="ed.hz.value" class="tb-select" title="Clock speed" :disabled="!hasClock">
|
<select v-model.number="ed.hz.value" class="tb-select" title="Clock speed" :disabled="!hasClock">
|
||||||
|
|
@ -80,27 +111,24 @@ const linkIcon = computed(() => {
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center gap-1.5">
|
<div class="tb-group">
|
||||||
<button class="tb-btn" title="Find anything in the project (Ctrl+F)" @click="ed.dialog.value = 'search'"><Icon name="lucide:search" class="size-4" /></button>
|
<button class="bar-btn" title="Find anything in the project (Ctrl+F)" @click="ed.dialog.value = 'search'"><Icon name="lucide:search" class="size-4" /></button>
|
||||||
<button class="tb-btn" title="Undo (Ctrl+Z)" :disabled="!ed.canUndo.value" @click="ed.undo()"><Icon name="lucide:undo-2" class="size-4" /></button>
|
<button class="bar-btn" title="Undo (Ctrl+Z)" :disabled="!ed.canUndo.value" @click="ed.undo()"><Icon name="lucide:undo-2" class="size-4" /></button>
|
||||||
<button class="tb-btn" title="Redo (Ctrl+Shift+Z)" :disabled="!ed.canRedo.value" @click="ed.redo()"><Icon name="lucide:redo-2" class="size-4" /></button>
|
<button class="bar-btn" title="Redo (Ctrl+Shift+Z)" :disabled="!ed.canRedo.value" @click="ed.redo()"><Icon name="lucide:redo-2" class="size-4" /></button>
|
||||||
<button
|
<button class="bar-btn" :title="ed.sound.value.on ? 'Sound on (volume and clock ticks in Settings)' : 'Sound off'" @click="ed.setSound({ on: !ed.sound.value.on })">
|
||||||
class="tb-btn"
|
|
||||||
:title="ed.sound.value.on ? 'Sound on (volume and clock ticks in Settings)' : 'Sound off'"
|
|
||||||
@click="ed.setSound({ on: !ed.sound.value.on })"
|
|
||||||
>
|
|
||||||
<Icon :name="ed.sound.value.on ? 'lucide:volume-2' : 'lucide:volume-x'" class="size-4" />
|
<Icon :name="ed.sound.value.on ? 'lucide:volume-2' : 'lucide:volume-x'" class="size-4" />
|
||||||
</button>
|
</button>
|
||||||
<button class="tb-btn" title="Settings: gate symbols, wire crossings, current flow, tidy wiring, sound" @click="ed.dialog.value = 'settings'">
|
<button class="bar-btn" title="Settings: gate symbols, wire crossings, current flow, tidy wiring, sound" @click="ed.dialog.value = 'settings'">
|
||||||
<Icon name="lucide:settings" class="size-4" />
|
<Icon name="lucide:settings" class="size-4" />
|
||||||
</button>
|
</button>
|
||||||
<button class="tb-btn share-btn" :class="ed.linkState.value" title="Save online, share a link, export or import a file" @click="ed.dialog.value = 'share'">
|
<button class="bar-btn" title="Help (?)" @click="ed.showHelp.value = true"><Icon name="lucide:circle-help" class="size-4" /></button>
|
||||||
|
<span class="bar-sep" />
|
||||||
|
<button class="bar-btn share-btn" :class="ed.linkState.value" title="Save online, share a link, export or import a file" @click="ed.dialog.value = 'share'">
|
||||||
<Icon :name="linkIcon" class="size-4" />
|
<Icon :name="linkIcon" class="size-4" />
|
||||||
<span class="hidden md:inline">Share</span>
|
<span class="hidden md:inline">Share</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="tb-btn" title="Help (?)" @click="ed.showHelp.value = true"><Icon name="lucide:circle-help" class="size-4" /></button>
|
|
||||||
<button
|
<button
|
||||||
class="tb-btn account-btn"
|
class="bar-btn account-btn"
|
||||||
:class="ed.cloudState.value"
|
:class="ed.cloudState.value"
|
||||||
:title="ed.account.value ? `${ed.account.value.email}: ${cloudText}` : 'Sign in to keep your projects on every computer'"
|
:title="ed.account.value ? `${ed.account.value.email}: ${cloudText}` : 'Sign in to keep your projects on every computer'"
|
||||||
@click="ed.dialog.value = 'account'"
|
@click="ed.dialog.value = 'account'"
|
||||||
|
|
@ -116,4 +144,5 @@ const linkIcon = computed(() => {
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,7 @@ function create() {
|
||||||
faceFor.value = defId
|
faceFor.value = defId
|
||||||
dialog.value = 'face'
|
dialog.value = 'face'
|
||||||
}
|
}
|
||||||
/** Tab shown in the right panel. */
|
/** Tab shown in the side panel. */
|
||||||
const rightTab = ref<'selection' | 'circuit' | 'pins' | 'test'>('circuit')
|
const rightTab = ref<'selection' | 'circuit' | 'pins' | 'test'>('circuit')
|
||||||
/** Which side panels are open; remembered in this browser. */
|
/** Which side panels are open; remembered in this browser. */
|
||||||
const sidebars = reactive<{ left: boolean; right: boolean }>({ left: true, right: true })
|
const sidebars = reactive<{ left: boolean; right: boolean }>({ left: true, right: true })
|
||||||
|
|
@ -456,8 +456,30 @@ function create() {
|
||||||
if (id) open(id, false)
|
if (id) open(id, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The project's top circuit: "main", or else the first one no other circuit uses. */
|
||||||
|
const mainId = computed(() => {
|
||||||
|
const list = project.value.components
|
||||||
|
if (list.some(d => d.id === 'main')) return 'main'
|
||||||
|
const used = new Set(list.flatMap(d => d.nodes.filter(n => n.kind === 'chip' && n.chip).map(n => n.chip!)))
|
||||||
|
return (list.find(d => !used.has(d.id) && !d.challenge) ?? list[0]!).id
|
||||||
|
})
|
||||||
|
|
||||||
|
/** Back to the top circuit; the way back is forgotten. */
|
||||||
|
function goMain() {
|
||||||
|
nav.value = []
|
||||||
|
open(mainId.value, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Back to step `i` of the way here (0 is where it started). */
|
||||||
|
function goTo(i: number) {
|
||||||
|
const id = nav.value[i]
|
||||||
|
if (!id) return
|
||||||
|
nav.value = nav.value.slice(0, i)
|
||||||
|
open(id, false)
|
||||||
|
}
|
||||||
|
|
||||||
// ── Editing ───────────────────────────────────────────────────────
|
// ── Editing ───────────────────────────────────────────────────────
|
||||||
/** Asks the parts list to focus its search box ("/" on the canvas). */
|
/** Asks the canvas to open quick add in its middle (search in the parts bar). */
|
||||||
const partSearch = ref(0)
|
const partSearch = ref(0)
|
||||||
|
|
||||||
/** A part being dragged in from the parts list, so the canvas can show where it would connect. */
|
/** A part being dragged in from the parts list, so the canvas can show where it would connect. */
|
||||||
|
|
@ -825,8 +847,8 @@ function create() {
|
||||||
/** The title menu shows when the app opens at /; links open straight into the editor. */
|
/** The title menu shows when the app opens at /; links open straight into the editor. */
|
||||||
const screen = ref<'menu' | 'editor'>(location.pathname === '/' ? 'menu' : 'editor')
|
const screen = ref<'menu' | 'editor'>(location.pathname === '/' ? 'menu' : 'editor')
|
||||||
const menuPage = ref<MenuPage>('main')
|
const menuPage = ref<MenuPage>('main')
|
||||||
/** Tab of the parts panel on the left. */
|
/** The challenges list below its button in the top bar. */
|
||||||
const paletteTab = ref<'parts' | 'challenges'>('parts')
|
const challengesOpen = ref(false)
|
||||||
|
|
||||||
function enterGame() {
|
function enterGame() {
|
||||||
screen.value = 'editor'
|
screen.value = 'editor'
|
||||||
|
|
@ -884,7 +906,7 @@ function create() {
|
||||||
const m = newestOf('campaign')
|
const m = newestOf('campaign')
|
||||||
if (m) switchProject(m.id)
|
if (m) switchProject(m.id)
|
||||||
else newProject(false, true)
|
else newProject(false, true)
|
||||||
paletteTab.value = 'challenges'
|
challengesOpen.value = true
|
||||||
enterGame()
|
enterGame()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -898,7 +920,7 @@ function create() {
|
||||||
p.mode = 'challenges'
|
p.mode = 'challenges'
|
||||||
activate(addProject(p), p)
|
activate(addProject(p), p)
|
||||||
}
|
}
|
||||||
paletteTab.value = 'challenges'
|
challengesOpen.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
function playChallenge(c: Challenge) {
|
function playChallenge(c: Challenge) {
|
||||||
|
|
@ -2213,6 +2235,9 @@ function create() {
|
||||||
rebuild,
|
rebuild,
|
||||||
open,
|
open,
|
||||||
back,
|
back,
|
||||||
|
mainId,
|
||||||
|
goMain,
|
||||||
|
goTo,
|
||||||
addNode,
|
addNode,
|
||||||
canPlace,
|
canPlace,
|
||||||
connect,
|
connect,
|
||||||
|
|
@ -2232,7 +2257,7 @@ function create() {
|
||||||
setScreen,
|
setScreen,
|
||||||
screen,
|
screen,
|
||||||
menuPage,
|
menuPage,
|
||||||
paletteTab,
|
challengesOpen,
|
||||||
enterGame,
|
enterGame,
|
||||||
showMenu,
|
showMenu,
|
||||||
projectMode,
|
projectMode,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// Placing parts from anywhere (the bottom bar, pinned parts, the circuits
|
// Placing parts from anywhere (the bottom bar, pinned parts, the circuits
|
||||||
// list), and the parts pinned to the left panel. Pins are kept in this
|
// list), and the parts pinned to the bottom bar. Pins are kept in this
|
||||||
// browser: built-in parts by kind, components by name, so a pinned "AND"
|
// browser: built-in parts by kind, components by name, so a pinned "AND"
|
||||||
// stays pinned in every project, whether it is the example or your own.
|
// stays pinned in every project, whether it is the example or your own.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue