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>
2026-10-22 18:04:43 +00:00
|
|
|
// Placing parts from anywhere (the bottom bar, pinned parts, the circuits
|
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>
2026-10-22 18:17:41 +00:00
|
|
|
// list), and the parts pinned to the bottom bar. Pins are kept in this
|
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>
2026-10-22 18:04:43 +00:00
|
|
|
// 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')
|
BF library: no solutions inside, nothing into a campaign, marks only from the entry, a small listing, updates clear what they replace
A component with a challenge or puzzle solution anywhere inside stays
private, not only a challenge circuit itself, so wrapping a solution in a
part of its own no longer publishes it.
A campaign takes nothing from the library: Add and "Get version" are off
there, with a line saying why. A library part could be duplicated,
published again or taken apart into a solution, so a check on placing was
not enough.
Library marks come only from the entry being added. The server drops the
marks a publisher sends, and whether an entry is yours depends only on the
key this browser keeps for that project and component, so a part claiming
to be someone's entry can't be published over it.
The listing keeps pin counts and the first 16 pin names a side, short, and
a group of 40 characters at most, so it stays small whatever is sent.
"Get version" clears away what came along with the old version once
nothing else uses it, and the new parts take its names. Adding never
reuses another entry's component, so updating one entry leaves the others
as they were.
Wire corner points that aren't number pairs are dropped when a project,
link or library entry is read, so a circuit can always be drawn.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:44:13 +00:00
|
|
|
return ed.notify('That component cannot go in here (it is this circuit, contains it, or is not solved yet)', 'error')
|
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>
2026-10-22 18:04:43 +00:00
|
|
|
}
|
|
|
|
|
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 }
|
|
|
|
|
}
|