R a Figma-like workspace: a floating bottom bar of part kinds with flyouts, pinned parts on the left
- Bottom bar over the canvas: Logic, Inputs, Outputs, Wiring, Notes, Connectors, Components (and search). Pointing at one opens its parts above it: click to place, drag onto the canvas, pin to the left. Connectors offer Out/In, edit and new type; components come grouped with their transistor counts. - Left panel: pinned parts first (NAND, AND, OR, NOT, XOR, input, output, lamp, clock to start with; kept per browser, components by name so they follow you into every project), then the circuits list. The long list of built-in parts and the connector list moved to the bar. - Slimmer top bar and side panels; notices sit above the bar. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8de4a81678
commit
67e3d94d80
|
|
@ -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, "<type> out" and "<type> in". Inside a component, a port shows its lines as pins on its inner side (lines coming in are outputs, lines going out inputs) and has a cable pin at the top to hand the whole cable on to a part inside; on the component's box it is one port, 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, "<type> out" and "<type> in". Inside a component, a port shows its lines as pins on its inner side (lines coming in are outputs, lines going out inputs) and has a cable pin at the top to hand the whole cable on to a part inside; on the component's box it is one port, 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.
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ watch(
|
|||
<EditorRail v-else side="left" />
|
||||
<main class="stage">
|
||||
<EditorCanvas />
|
||||
<EditorBottomBar />
|
||||
</main>
|
||||
<EditorInspector v-if="ed.sidebars.right" />
|
||||
<EditorRail v-else side="right" />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,205 @@
|
|||
<script setup lang="ts">
|
||||
// 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
|
||||
// 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.
|
||||
import { shortCount } from '~/lib/logic/analyze'
|
||||
import { BASIC_GROUPS } from '~/composables/useParts'
|
||||
import type { ComponentDef, NodeKind } from '~/lib/logic/types'
|
||||
|
||||
const ed = useEditor()
|
||||
const { place, dragStart, dragEnd, isPinned, togglePin } = usePlace()
|
||||
const { componentGroups } = useParts()
|
||||
|
||||
const ICONS: Record<string, string> = {
|
||||
Logic: 'lucide:square-function',
|
||||
Inputs: 'lucide:toggle-left',
|
||||
Outputs: 'lucide:lightbulb',
|
||||
Wiring: 'lucide:spline',
|
||||
Notes: 'lucide:sticky-note',
|
||||
}
|
||||
|
||||
type Cat = { id: string; label: string; icon: string }
|
||||
const cats = computed<Cat[]>(() => [
|
||||
...BASIC_GROUPS.map(g => ({ id: g.name, label: g.name, icon: ICONS[g.name] ?? 'lucide:shapes' })),
|
||||
{ id: 'connectors', label: 'Connectors', icon: 'lucide:plug' },
|
||||
{ id: 'components', label: 'Components', icon: 'lucide:boxes' },
|
||||
])
|
||||
|
||||
// ── Flyout: opens on pointing, stays while the pointer is over it ──
|
||||
const open = ref<string | null>(null)
|
||||
const anchor = ref(0)
|
||||
let timer: ReturnType<typeof setTimeout> | undefined
|
||||
|
||||
function show(id: string, e: Event) {
|
||||
clearTimeout(timer)
|
||||
const el = e.currentTarget as HTMLElement
|
||||
const go = () => {
|
||||
open.value = id
|
||||
anchor.value = el.offsetLeft + el.offsetWidth / 2
|
||||
}
|
||||
// Moving along the bar switches at once; the first one waits a moment.
|
||||
if (open.value) go()
|
||||
else timer = setTimeout(go, 110)
|
||||
}
|
||||
|
||||
function leave() {
|
||||
clearTimeout(timer)
|
||||
timer = setTimeout(() => (open.value = null), 220)
|
||||
}
|
||||
|
||||
function stay() {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
|
||||
function toggle(id: string, e: Event) {
|
||||
if (open.value === id) open.value = null
|
||||
else {
|
||||
clearTimeout(timer)
|
||||
const el = e.currentTarget as HTMLElement
|
||||
open.value = id
|
||||
anchor.value = el.offsetLeft + el.offsetWidth / 2
|
||||
}
|
||||
}
|
||||
|
||||
function pick(kind: NodeKind, chip?: string, conn?: string) {
|
||||
place(kind, chip, conn)
|
||||
open.value = null
|
||||
}
|
||||
|
||||
/** Which button the part being placed belongs to, to show it as active. */
|
||||
const activeCat = computed(() => {
|
||||
const p = ed.placing.value
|
||||
if (!p) return null
|
||||
if (p.kind === 'chip') return 'components'
|
||||
if (p.kind === 'portin' || p.kind === 'portout') return 'connectors'
|
||||
return BASIC_GROUPS.find(g => g.parts.some(x => x.kind === p.kind))?.name ?? null
|
||||
})
|
||||
|
||||
const group = computed(() => BASIC_GROUPS.find(g => g.name === open.value))
|
||||
const connectors = computed(() => ed.project.value.connectors ?? [])
|
||||
const portsOk = computed(() => ed.canPlaceKind('portin'))
|
||||
const placeable = (d: ComponentDef) => d.id !== ed.def.value.id && ed.canPlace(d.id)
|
||||
|
||||
function onKey(e: KeyboardEvent) {
|
||||
if (e.key === 'Escape' && open.value) {
|
||||
open.value = null
|
||||
e.stopPropagation()
|
||||
}
|
||||
}
|
||||
onMounted(() => window.addEventListener('keydown', onKey, true))
|
||||
onBeforeUnmount(() => window.removeEventListener('keydown', onKey, true))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="bottom-dock" @pointerdown.stop>
|
||||
<Transition name="flyout">
|
||||
<div v-if="open" class="flyout" :style="{ left: `${anchor}px` }" @pointerenter="stay" @pointerleave="leave">
|
||||
<!-- Built-in parts -->
|
||||
<template v-if="group">
|
||||
<p class="flyout-head">{{ group.name }}</p>
|
||||
<ul class="flyout-list">
|
||||
<li v-for="p in group.parts" :key="p.kind">
|
||||
<button
|
||||
class="flyout-item"
|
||||
:class="{ blocked: !ed.canPlaceKind(p.kind), active: ed.placing.value?.kind === p.kind && !ed.placing.value?.chip }"
|
||||
:title="p.hint"
|
||||
draggable="true"
|
||||
@click="pick(p.kind)"
|
||||
@dragstart="dragStart($event, p.kind)"
|
||||
@dragend="dragEnd"
|
||||
>
|
||||
<span v-if="p.kind === 'nand'" class="nand-badge">&</span>
|
||||
<Icon v-else :name="p.icon" class="size-4 shrink-0" />
|
||||
<span class="grow truncate">{{ p.name }}</span>
|
||||
<kbd v-if="p.key">{{ p.key }}</kbd>
|
||||
</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)">
|
||||
<Icon :name="isPinned(p.kind) ? 'lucide:pin-off' : 'lucide:pin'" class="size-3.5" />
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
|
||||
<!-- Connector types -->
|
||||
<template v-else-if="open === 'connectors'">
|
||||
<p class="flyout-head">Connectors</p>
|
||||
<p v-if="!connectors.length" class="flyout-empty">Make a cable type of your own: HDMI, RJ45, a bus. It gets an Out and an In port.</p>
|
||||
<ul class="flyout-list">
|
||||
<li v-for="c in connectors" :key="c.id">
|
||||
<span class="flyout-item static">
|
||||
<span class="conn-swatch" :class="c.color ? `c-${c.color}` : ''" />
|
||||
<span class="grow truncate">{{ c.name }}</span>
|
||||
<span class="flyout-note">{{ c.lines.length }} lines</span>
|
||||
</span>
|
||||
<button
|
||||
v-for="side in ['portout', 'portin'] as const"
|
||||
:key="side"
|
||||
class="btn-sm"
|
||||
:disabled="!portsOk"
|
||||
draggable="true"
|
||||
:title="side === 'portout' ? `Where a ${c.name} cable leaves this circuit` : `Where a ${c.name} cable comes in`"
|
||||
@click="pick(side, undefined, c.id)"
|
||||
@dragstart="dragStart($event, side, undefined, c.id)"
|
||||
@dragend="dragEnd"
|
||||
>
|
||||
{{ side === 'portout' ? 'Out' : 'In' }}
|
||||
</button>
|
||||
<button class="pin-btn" title="Edit its name, colour and lines" @click="ed.editConnector(c.id), (open = null)"><Icon name="lucide:pencil" class="size-3.5" /></button>
|
||||
</li>
|
||||
</ul>
|
||||
<button class="flyout-new" :disabled="!portsOk" @click="ed.addConnector(), (open = null)"><Icon name="lucide:plus" class="size-4" /> New connector type</button>
|
||||
</template>
|
||||
|
||||
<!-- Components, by group -->
|
||||
<template v-else-if="open === 'components'">
|
||||
<div class="flyout-scroll">
|
||||
<template v-for="g in componentGroups" :key="g.name">
|
||||
<p class="flyout-head">{{ g.name }}</p>
|
||||
<ul class="flyout-list">
|
||||
<li v-for="d in g.defs" :key="d.id">
|
||||
<button
|
||||
class="flyout-item"
|
||||
:class="{ blocked: !placeable(d), active: ed.placing.value?.chip === d.id }"
|
||||
:title="d.id === ed.def.value.id ? 'You are editing this one' : d.description || ''"
|
||||
:draggable="placeable(d)"
|
||||
@click="pick('chip', d.id)"
|
||||
@dragstart="dragStart($event, 'chip', d.id)"
|
||||
@dragend="dragEnd"
|
||||
>
|
||||
<Icon name="lucide:box" class="size-4 shrink-0" />
|
||||
<span class="grow truncate">{{ d.name }}</span>
|
||||
<span v-if="ed.transistors(d.id)" class="flyout-note">{{ shortCount(ed.transistors(d.id)) }}T</span>
|
||||
</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)">
|
||||
<Icon :name="isPinned('chip', d) ? 'lucide:pin-off' : 'lucide:pin'" class="size-3.5" />
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
</div>
|
||||
<button class="flyout-new" @click="ed.createComponent(), (open = null)"><Icon name="lucide:plus" class="size-4" /> New component</button>
|
||||
</template>
|
||||
</div>
|
||||
</Transition>
|
||||
|
||||
<nav class="bottom-bar" aria-label="Parts" @pointerleave="leave">
|
||||
<button
|
||||
v-for="c in cats"
|
||||
:key="c.id"
|
||||
class="bar-btn"
|
||||
:class="{ open: open === c.id, active: activeCat === c.id }"
|
||||
:title="c.label"
|
||||
@pointerenter="show(c.id, $event)"
|
||||
@click="toggle(c.id, $event)"
|
||||
>
|
||||
<Icon :name="c.icon" class="size-[18px]" />
|
||||
<span class="bar-label">{{ c.label }}</span>
|
||||
</button>
|
||||
<span class="bar-sep" />
|
||||
<button class="bar-btn" title="Find a part (/)" @click="ed.toggleSidebar('left', true), ed.partSearch.value++">
|
||||
<Icon name="lucide:search" class="size-[18px]" />
|
||||
</button>
|
||||
</nav>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -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'],
|
||||
|
|
|
|||
|
|
@ -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<HTMLInputElement>()
|
||||
|
|
@ -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
|
|||
</template>
|
||||
|
||||
<template v-else>
|
||||
<template v-if="recentParts.length">
|
||||
<h3>Recent</h3>
|
||||
<div class="recent-parts">
|
||||
<button
|
||||
v-for="r in recentParts"
|
||||
:key="r.chip ?? r.kind"
|
||||
class="recent-chip"
|
||||
:title="`Place ${r.name}`"
|
||||
draggable="true"
|
||||
@click="pick(r.kind, r.chip)"
|
||||
@dragstart="onDragStart($event, r.kind, r.chip)"
|
||||
@dragend="ed.dragPart.value = null"
|
||||
>
|
||||
<Icon :name="r.icon" class="size-3.5 shrink-0" />
|
||||
<span class="truncate">{{ r.name }}</span>
|
||||
</button>
|
||||
<!-- 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>
|
||||
</template>
|
||||
|
||||
<template v-for="g in BASIC_GROUPS" :key="g.name">
|
||||
<button class="group-head" @click="fold(g.name)">
|
||||
<Icon :name="folded.has(g.name) ? 'lucide:chevron-right' : 'lucide:chevron-down'" class="size-3.5" />
|
||||
<span>{{ g.name }}</span>
|
||||
</button>
|
||||
<ul v-if="!folded.has(g.name)" class="items">
|
||||
<li v-for="item in g.parts" :key="item.kind">
|
||||
<ul v-if="pinned.length" class="pinned">
|
||||
<li v-for="p in pinned" :key="p.pin">
|
||||
<button
|
||||
class="item"
|
||||
:class="{ active: ed.placing.value?.kind === item.kind && !ed.placing.value?.chip, blocked: !ed.canPlaceKind(item.kind) }"
|
||||
:title="ed.canPlaceKind(item.kind) ? item.hint : lockedHint(item.kind)"
|
||||
:draggable="ed.canPlaceKind(item.kind)"
|
||||
@click="pick(item.kind)"
|
||||
@dragstart="onDragStart($event, item.kind)"
|
||||
@dragend="ed.dragPart.value = null"
|
||||
: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="item.kind === 'nand'" class="nand-badge">&</span>
|
||||
<Icon v-else :name="item.icon" class="size-4 shrink-0 text-(--muted)" />
|
||||
<span class="grow truncate">{{ item.name }}</span>
|
||||
<span v-if="item.kind === 'nand'" class="tcount" title="4 transistors: a CMOS NAND gate">4T</span>
|
||||
<Icon v-if="!ed.canPlaceKind(item.kind)" name="lucide:lock" class="size-3.5 shrink-0 text-(--muted)" />
|
||||
<kbd v-else-if="item.key">{{ item.key }}</kbd>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
|
||||
<!-- Connector types you made: place their ports, edit them, add new ones -->
|
||||
<button class="group-head" @click="fold('connectors')">
|
||||
<Icon :name="folded.has('connectors') ? 'lucide:chevron-right' : 'lucide:chevron-down'" class="size-3.5" />
|
||||
<span>Connectors</span>
|
||||
<span v-if="connectors.length" class="group-count">{{ connectors.length }}</span>
|
||||
</button>
|
||||
<ul v-if="!folded.has('connectors')" class="items">
|
||||
<li v-for="c in connectors" :key="c.id" class="comp-row conn-row" :class="{ blocked: !portsOk }">
|
||||
<span class="conn-swatch" :class="c.color ? `c-${c.color}` : ''" />
|
||||
<span class="grow truncate" :title="`${c.lines.length} lines: ${c.lines.map(l => (l.back ? `${l.name} (back)` : l.name)).join(', ')}`">{{ c.name }}</span>
|
||||
<button
|
||||
v-for="side in PORT_SIDES"
|
||||
:key="side.kind"
|
||||
class="btn-sm port-pick"
|
||||
:class="{ active: ed.placing.value?.kind === side.kind && ed.placing.value?.conn === c.id }"
|
||||
:title="side.hint(c.name)"
|
||||
:draggable="portsOk"
|
||||
@click="pickPort(side.kind, c.id)"
|
||||
@dragstart="onDragStart($event, side.kind, undefined, c.id)"
|
||||
@dragend="ed.dragPart.value = null"
|
||||
>
|
||||
{{ side.label }}
|
||||
</button>
|
||||
<button class="open" title="Edit this connector type: name, colour, lines" @click="ed.editConnector(c.id)">
|
||||
<Icon name="lucide:pencil" class="size-3.5" />
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<button class="item" :class="{ blocked: !portsOk }" title="Make a connector type of your own, like HDMI or RJ45: a name, a colour and its lines" @click="newConnector">
|
||||
<Icon name="lucide:plus" class="size-4 shrink-0 text-(--muted)" />
|
||||
<span class="grow truncate">New connector type</span>
|
||||
<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" />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,103 @@
|
|||
// 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
|
||||
// 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.
|
||||
|
||||
import { BASIC_PARTS } from '~/composables/useParts'
|
||||
import { challengeName, defUsable, KIND_UNLOCK } from '~/lib/logic/progress'
|
||||
import type { ComponentDef, NodeKind } from '~/lib/logic/types'
|
||||
|
||||
const PIN_KEY = 'logigate:pinned'
|
||||
const DEFAULT_PINS = ['nand', 'name:AND', 'name:OR', 'name:NOT', 'name:XOR', 'input', 'output', 'lamp', 'clock']
|
||||
|
||||
function loadPins(): string[] {
|
||||
try {
|
||||
const raw = JSON.parse(localStorage.getItem(PIN_KEY) ?? 'null')
|
||||
if (Array.isArray(raw)) return raw.filter((k): k is string => typeof k === 'string').slice(0, 40)
|
||||
} catch {}
|
||||
return [...DEFAULT_PINS]
|
||||
}
|
||||
|
||||
const pins = ref<string[]>(import.meta.client ? loadPins() : [...DEFAULT_PINS])
|
||||
|
||||
export interface PinnedPart {
|
||||
pin: string
|
||||
kind: NodeKind
|
||||
chip?: string
|
||||
name: string
|
||||
icon: string
|
||||
key?: string
|
||||
/** Pinned, but not here: the component is not in this project, or not usable yet. */
|
||||
missing?: boolean
|
||||
}
|
||||
|
||||
export function usePlace() {
|
||||
const ed = useEditor()
|
||||
|
||||
function lockedHint(kind: NodeKind) {
|
||||
const by = KIND_UNLOCK[kind]
|
||||
return by ? `Solve the ${challengeName(by)} challenge to unlock this part` : ''
|
||||
}
|
||||
|
||||
/** Start placing a part: click on the canvas puts it there. */
|
||||
function place(kind: NodeKind, chip?: string, conn?: string) {
|
||||
if (chip && !ed.canPlace(chip)) {
|
||||
ed.play('error')
|
||||
return ed.notify('That component cannot go in here (it is this circuit, contains it, or is not solved yet)', 'error')
|
||||
}
|
||||
if (!ed.canPlaceKind(kind)) {
|
||||
ed.play('error')
|
||||
return ed.notify(lockedHint(kind), 'error')
|
||||
}
|
||||
ed.placing.value = { kind, chip, ...(conn ? { conn } : {}) }
|
||||
}
|
||||
|
||||
/** Dragging a part onto the canvas places it where it is dropped. */
|
||||
function dragStart(e: DragEvent, kind: NodeKind, chip?: string, conn?: string) {
|
||||
if ((chip && !ed.canPlace(chip)) || !ed.canPlaceKind(kind)) {
|
||||
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 ? { conn } : {}) }
|
||||
}
|
||||
|
||||
function dragEnd() {
|
||||
ed.dragPart.value = null
|
||||
}
|
||||
|
||||
const pinOf = (kind: NodeKind, def?: ComponentDef) => (def ? `name:${def.name}` : kind)
|
||||
const isPinned = (kind: NodeKind, def?: ComponentDef) => pins.value.includes(pinOf(kind, def))
|
||||
|
||||
function togglePin(kind: NodeKind, def?: ComponentDef) {
|
||||
const key = pinOf(kind, def)
|
||||
pins.value = pins.value.includes(key) ? pins.value.filter(k => k !== key) : [...pins.value, key]
|
||||
try {
|
||||
localStorage.setItem(PIN_KEY, JSON.stringify(pins.value))
|
||||
} catch {}
|
||||
}
|
||||
|
||||
function unpin(key: string) {
|
||||
pins.value = pins.value.filter(k => k !== key)
|
||||
try {
|
||||
localStorage.setItem(PIN_KEY, JSON.stringify(pins.value))
|
||||
} catch {}
|
||||
}
|
||||
|
||||
/** The pinned parts as they stand in this project. */
|
||||
const pinned = computed<PinnedPart[]>(() =>
|
||||
pins.value.flatMap((pin): PinnedPart[] => {
|
||||
if (pin.startsWith('name:')) {
|
||||
const name = pin.slice(5)
|
||||
const d = ed.project.value.components.find(c => c.name === name && c.id !== ed.def.value.id) ?? ed.project.value.components.find(c => c.name === name)
|
||||
const usable = !!d && d.id !== ed.def.value.id && ed.canPlace(d.id) && defUsable(ed.project.value, d)
|
||||
return [{ pin, kind: 'chip' as NodeKind, chip: d?.id, name, icon: 'lucide:box', missing: !usable }]
|
||||
}
|
||||
const p = BASIC_PARTS.find(b => b.kind === pin)
|
||||
return p ? [{ pin, kind: p.kind, name: p.name, icon: p.icon, key: p.key, missing: !ed.canPlaceKind(p.kind) }] : []
|
||||
}),
|
||||
)
|
||||
|
||||
return { place, dragStart, dragEnd, lockedHint, pinned, isPinned, togglePin, unpin }
|
||||
}
|
||||
Loading…
Reference in New Issue