638 lines
31 KiB
Vue
638 lines
31 KiB
Vue
<script setup lang="ts">
|
||
import { stats } from '~/lib/logic/analyze'
|
||
import { compile } from '~/lib/logic/compile'
|
||
import { cableOf } from '~/lib/logic/cables'
|
||
import { INVERTIBLE } from '~/lib/logic/compile'
|
||
import { cableBits, cableOffsets, chipPins, MAX_BITS, panelOffsets, rowLabel } from '~/lib/logic/geometry'
|
||
import { SINK_KINDS, SOURCE_KINDS } from '~/lib/logic/ops'
|
||
import { KIND_NAMES } from '~/lib/logic/progress'
|
||
import { baseOf, gateFamily, inputCount, MAX_GATE_INPUTS } from '~/lib/logic/wide'
|
||
import { LAMP_COLORS, WIRE_COLORS, type CircuitNode, type NodeKind, type PanelControl, type PanelRow } from '~/lib/logic/types'
|
||
|
||
const props = defineProps<{ node: CircuitNode }>()
|
||
const ed = useEditor()
|
||
|
||
const CONTROLS: { value: PanelControl; label: string }[] = [
|
||
{ value: 'switch', label: 'Switch' },
|
||
{ value: 'button', label: 'Button' },
|
||
{ value: 'clock', label: 'Clock' },
|
||
]
|
||
|
||
const HINTS: Record<string, string> = {
|
||
input: 'Click it on the canvas to flip it. Inside a component it becomes an input pin; pins are ordered top to bottom.',
|
||
output: 'Inside a component it becomes an output pin; pins are ordered top to bottom.',
|
||
nand: 'Output is 0 only when both inputs are 1. Every other part can be built from this one.',
|
||
high: 'Always 1, like the supply rail.',
|
||
low: 'Always 0, like ground.',
|
||
button: 'Gives 1 while held down with the mouse or its key.',
|
||
lamp: 'Lights up at 1. Inside a component it also shows on the component box.',
|
||
hex: 'Shows inputs 1, 2, 4, 8 as one hex digit. Inside a component it also shows on the component box.',
|
||
bundle: 'Wire 0 (top) to the last on the left go into the cable on the right. Run the cable to a split, which gives them back in the same order. The wires are named after what drives them, or else what they drive.',
|
||
split: 'Takes a cable from a bundle and gives its wires back in the same order, top to bottom, with their names.',
|
||
pixel: 'Lights at 1. Inside a component, all its pixels show on the component box as one screen, without gaps: space them out inside to wire them, every column and row they sit on becomes a column and row of the screen.',
|
||
tag: 'Wire a signal into it and give it a name. Every "Use signal" with that name in this circuit carries the same signal, without a wire. Names stay inside this circuit.',
|
||
ref: 'Carries the signal of the "Send signal" with the same name in this circuit. Select it to see all places that signal goes.',
|
||
outpanel: 'A lamp per row, named after what it shows. Inside a component its rows are output pins, top to bottom with the other outputs. Each row passes its signal on to the right.',
|
||
panel: 'Click a row on the canvas to flip its switch or hold its button, or press its key. Rows without a name take the name of the pin they are wired to. Open a row (the arrow) for its key, colour, spacing and order.',
|
||
}
|
||
|
||
const n = computed(() => props.node)
|
||
const chipDef = computed(() => (n.value.chip ? ed.getDef.value(n.value.chip) : undefined))
|
||
const chipStats = computed(() => (chipDef.value ? stats(compile(ed.getDef.value, chipDef.value.id)) : null))
|
||
const title = computed(() => (n.value.kind === 'chip' ? chipDef.value?.name ?? 'Missing component' : KIND_NAMES[n.value.kind]))
|
||
const logic = computed(() => n.value.kind === 'nand' || n.value.kind === 'chip')
|
||
const family = computed<NodeKind[]>(() => (SOURCE_KINDS.includes(n.value.kind) ? SOURCE_KINDS : SINK_KINDS.includes(n.value.kind) ? SINK_KINDS : []))
|
||
const currentType = computed(() => (n.value.kind === 'chip' ? `chip:${n.value.chip}` : n.value.kind))
|
||
const wired = computed(() => ed.def.value.wires.some(w => w.from.node === n.value.id || w.to.node === n.value.id))
|
||
|
||
/** Components grouped like the palette, with their pin counts. */
|
||
const swapGroups = computed(() => {
|
||
const groups = new Map<string, { id: string; label: string; ok: boolean }[]>()
|
||
for (const d of ed.project.value.components) {
|
||
const p = chipPins(d)
|
||
const g = d.group?.trim() || 'My components'
|
||
if (!groups.has(g)) groups.set(g, [])
|
||
groups.get(g)!.push({ id: d.id, label: `${d.name} (${p.inputs.length} → ${p.outputs.length})`, ok: ed.canPlace(d.id) })
|
||
}
|
||
return [...groups.entries()]
|
||
})
|
||
|
||
function onSwap(e: Event) {
|
||
const v = (e.target as HTMLSelectElement).value
|
||
if (v === currentType.value) return
|
||
if (v.startsWith('chip:')) ed.swap(n.value.id, { kind: 'chip', chip: v.slice(5) })
|
||
else ed.swap(n.value.id, { kind: v as NodeKind })
|
||
}
|
||
|
||
const labelInput = ref<HTMLInputElement | HTMLTextAreaElement>()
|
||
watch(
|
||
() => ed.labelFocus.value,
|
||
() =>
|
||
nextTick(() => {
|
||
labelInput.value?.focus()
|
||
labelInput.value?.select()
|
||
}),
|
||
)
|
||
|
||
const hasLabel = computed(() => !['high', 'low', 'nand', 'bundle', 'split', 'pixel'].includes(n.value.kind))
|
||
|
||
function setHz(e: Event) {
|
||
const v = Number((e.target as HTMLInputElement).value)
|
||
if (v > 0 && v <= 1000) n.value.hz = v
|
||
else delete n.value.hz
|
||
ed.commit()
|
||
}
|
||
|
||
function followTopBar(e: Event) {
|
||
if ((e.target as HTMLInputElement).checked) delete n.value.hz
|
||
else n.value.hz = ed.hz.value > 0 ? ed.hz.value : 2
|
||
ed.commit()
|
||
}
|
||
|
||
function setKey(e: KeyboardEvent) {
|
||
if (e.key === 'Tab') return
|
||
e.preventDefault()
|
||
if (e.key === 'Backspace' || e.key === 'Delete' || e.key === 'Escape') delete n.value.key
|
||
else if (e.key.length === 1 && e.key !== ' ') n.value.key = e.key.toLowerCase()
|
||
else return
|
||
ed.commit(false)
|
||
;(e.target as HTMLInputElement).blur()
|
||
}
|
||
|
||
function setColor(c: (typeof LAMP_COLORS)[number] | undefined) {
|
||
if (c) n.value.color = c
|
||
else delete n.value.color
|
||
ed.commit(false)
|
||
}
|
||
|
||
function setPos(axis: 'x' | 'y', e: Event) {
|
||
const v = Math.round(Number((e.target as HTMLInputElement).value))
|
||
if (Number.isFinite(v)) {
|
||
n.value[axis] = v
|
||
ed.commit(false)
|
||
}
|
||
}
|
||
|
||
function setSize(size: 'sm' | 'md' | 'lg') {
|
||
if (size === 'md') delete n.value.size
|
||
else n.value.size = size
|
||
ed.commit(false)
|
||
}
|
||
|
||
function setOn(on: boolean) {
|
||
if (!!n.value.on !== on) ed.toggleInput(n.value)
|
||
}
|
||
|
||
/** A name typed by hand is kept from then on; clearing it lets connections name the part again. */
|
||
function onLabel() {
|
||
delete n.value.autoLabel
|
||
// A signal's name decides what it connects to.
|
||
ed.commit(n.value.kind === 'tag' || n.value.kind === 'ref')
|
||
}
|
||
|
||
// ── Signals ─────────────────────────────────────────────────────────
|
||
const signal = computed(() => n.value.label?.trim() ?? '')
|
||
const signalNames = computed(() => [...new Set(ed.def.value.nodes.filter(x => x.kind === 'tag' && x.label?.trim()).map(x => x.label!.trim()))].sort())
|
||
const senders = computed(() => ed.def.value.nodes.filter(x => x.kind === 'tag' && !!signal.value && x.label?.trim() === signal.value))
|
||
const uses = computed(() => ed.def.value.nodes.filter(x => x.kind === 'ref' && !!signal.value && x.label?.trim() === signal.value))
|
||
|
||
const dock = computed(() => {
|
||
const id = n.value.attach
|
||
const chip = id ? ed.def.value.nodes.find(x => x.id === id) : undefined
|
||
return chip ? chip.label?.trim() || (chip.chip ? ed.getDef.value(chip.chip)?.name : undefined) || 'component' : null
|
||
})
|
||
|
||
/** Gates that can take more inputs (AND, OR, XOR, NAND, NOR and their wide versions). */
|
||
const widens = computed(() => {
|
||
const base = baseOf(n.value, ed.getDef.value)
|
||
return !!base && !!gateFamily(ed.getDef.value, base)
|
||
})
|
||
const inputs = computed(() => inputCount(n.value, ed.getDef.value))
|
||
|
||
/** Screen names used by the pixels of this circuit. */
|
||
const screenNames = computed(() => [...new Set(ed.def.value.nodes.filter(x => x.kind === 'pixel' && x.screen).map(x => x.screen!))].sort())
|
||
|
||
/** Groups of pins a new cable can plug onto. */
|
||
const cables = computed(() => ed.cableChoices(n.value))
|
||
|
||
/** Inputs that can carry a bubble, with their names. */
|
||
const invertible = computed(() => {
|
||
if (!INVERTIBLE.has(n.value.kind)) return []
|
||
const inv = new Set(n.value.invert ?? [])
|
||
return ed.shape(n.value).inputs.map((p, i) => ({ key: p.key, label: p.label || (n.value.kind === 'nand' ? 'AB'[i]! : 'In'), on: inv.has(p.key) }))
|
||
})
|
||
|
||
/** The bundle of the cable this bundle or split belongs to. */
|
||
const cableBundle = computed(() => {
|
||
if (n.value.kind === 'bundle') return n.value
|
||
if (n.value.kind !== 'split') return undefined
|
||
const feed = ed.def.value.wires.find(w => w.to.node === n.value.id)
|
||
return feed ? cableOf(ed.def.value, feed) : undefined
|
||
})
|
||
|
||
const sleeveColor = computed(() => (cableBundle.value ? ed.def.value.wires.find(w => w.from.node === cableBundle.value!.id)?.color : undefined))
|
||
|
||
const chipInputs = computed(() => (chipDef.value ? chipPins(chipDef.value).inputs.length : 0))
|
||
const chipOutputs = computed(() => (chipDef.value ? chipPins(chipDef.value).outputs.length : 0))
|
||
const hasPanel = computed(() => ed.def.value.nodes.some(x => x.kind === 'panel' && x.attach === n.value.id))
|
||
const hasOutPanel = computed(() => ed.def.value.nodes.some(x => x.kind === 'outpanel' && x.attach === n.value.id))
|
||
const outPanel = computed(() => n.value.kind === 'outpanel')
|
||
|
||
function setRowLabel(row: PanelRow, e: Event) {
|
||
const v = (e.target as HTMLInputElement).value.trim()
|
||
if (v) row.label = v
|
||
else delete row.label
|
||
ed.commit()
|
||
}
|
||
|
||
/** Rows showing their extra settings (key, colour, spacing, order). */
|
||
const openRows = ref(new Set<string>())
|
||
function toggleRow(id: string) {
|
||
const s = new Set(openRows.value)
|
||
if (!s.delete(id)) s.add(id)
|
||
openRows.value = s
|
||
}
|
||
const rowGaps = computed(() => {
|
||
const at = panelOffsets(n.value.rows ?? [])
|
||
return at.map((y, i) => (i ? y - at[i - 1]! - 1 : 0))
|
||
})
|
||
|
||
function setRowKey(row: PanelRow, e: KeyboardEvent) {
|
||
if (e.key === 'Tab') return
|
||
e.preventDefault()
|
||
if (e.key === 'Backspace' || e.key === 'Delete' || e.key === 'Escape') ed.setRowKey(row, undefined)
|
||
else if (e.key.length === 1 && e.key !== ' ') ed.setRowKey(row, e.key.toLowerCase())
|
||
else return
|
||
;(e.target as HTMLInputElement).blur()
|
||
}
|
||
|
||
/** What a part is called in messages: its label, its component's name, or its kind. */
|
||
function partName(id: string | undefined): string {
|
||
const p = id ? ed.def.value.nodes.find(x => x.id === id) : undefined
|
||
if (!p) return 'part'
|
||
if (p.label?.trim() && !p.autoLabel) return p.label.trim()
|
||
if (p.kind === 'chip') return (p.chip ? ed.getDef.value(p.chip)?.name : undefined) ?? 'component'
|
||
if (p.kind === 'panel') return 'the input panel'
|
||
return (KIND_NAMES[p.kind] ?? p.kind).toLowerCase()
|
||
}
|
||
|
||
const isCableEnd = computed(() => n.value.kind === 'bundle' || n.value.kind === 'split')
|
||
const plugPart = computed(() => (isCableEnd.value && !n.value.plug ? ed.plugTarget(n.value) : undefined))
|
||
const pitch = computed(() => {
|
||
const o = cableOffsets(n.value)
|
||
return o.every((v, i) => v === i * (o[1] ?? 1)) ? (o[1] ?? 1) : null
|
||
})
|
||
const undriven = computed(() => {
|
||
if (n.value.kind !== 'bundle') return 0
|
||
const fed = new Set(ed.def.value.wires.filter(w => w.to.node === n.value.id).map(w => w.to.pin))
|
||
return cableBits(n.value) - fed.size
|
||
})
|
||
|
||
function setInner(inner: boolean) {
|
||
if (inner) n.value.inner = true
|
||
else delete n.value.inner
|
||
ed.commit()
|
||
}
|
||
|
||
function setRowHz(row: PanelRow, e: Event) {
|
||
const v = Number((e.target as HTMLInputElement).value)
|
||
if (v > 0 && v <= 1000) row.hz = v
|
||
else delete row.hz
|
||
ed.commit()
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<section>
|
||
<h3>{{ title }}</h3>
|
||
<p class="score" :title="n.kind === 'nand' ? 'CMOS NAND: 2 transistors in parallel to the supply, 2 in series to ground' : ''">
|
||
<Icon name="lucide:cpu" class="size-4 shrink-0" />
|
||
<span v-if="n.kind === 'nand'">4 transistors (CMOS: 2 in parallel to the supply, 2 in series to ground)</span>
|
||
<span v-else-if="n.kind === 'chip'">
|
||
{{ ed.transistorsOfNode(n).toLocaleString() }} transistors, from {{ (ed.transistorsOfNode(n) / 4).toLocaleString() }} NAND gates inside
|
||
</span>
|
||
<span v-else>0 transistors: no logic gate inside</span>
|
||
</p>
|
||
|
||
<label v-if="logic" class="field">
|
||
<span>Part</span>
|
||
<select :value="currentType" @change="onSwap">
|
||
<option value="nand">NAND (2 → 1)</option>
|
||
<optgroup v-for="[g, defs] in swapGroups" :key="g" :label="g">
|
||
<option v-for="d in defs" :key="d.id" :value="`chip:${d.id}`" :disabled="!d.ok">{{ d.label }}</option>
|
||
</optgroup>
|
||
</select>
|
||
</label>
|
||
<label v-else-if="family.length" class="field">
|
||
<span>Type</span>
|
||
<select :value="currentType" @change="onSwap">
|
||
<option v-for="k in family" :key="k" :value="k">{{ KIND_NAMES[k] }}</option>
|
||
</select>
|
||
</label>
|
||
<p v-if="logic || family.length" class="hint -mt-1">Swapping keeps the wires on the pins in the same position.</p>
|
||
|
||
<label v-if="widens" class="field">
|
||
<span>Inputs</span>
|
||
<input
|
||
type="number"
|
||
min="2"
|
||
:max="MAX_GATE_INPUTS"
|
||
step="1"
|
||
:value="inputs"
|
||
@change="ed.setInputs(n, Number(($event.target as HTMLInputElement).value))"
|
||
/>
|
||
</label>
|
||
<p v-if="widens && inputs > 2" class="hint -mt-1">Built from {{ inputs - 1 }} two-input gates in a tree, so the transistors count honestly.</p>
|
||
|
||
<div v-if="invertible.length" class="field">
|
||
<span>Inverted inputs (Alt + click a pin)</span>
|
||
<div class="invert-pins">
|
||
<button
|
||
v-for="p in invertible"
|
||
:key="p.key"
|
||
class="invert-pin"
|
||
:class="{ on: p.on }"
|
||
:title="p.on ? 'Inverted: one NAND, 4 transistors. Click to take the bubble off.' : 'Invert this input'"
|
||
@click="ed.toggleInvert(n, p.key)"
|
||
>
|
||
<span class="dot" />{{ p.label }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<label v-if="hasLabel" class="field">
|
||
<span>{{ n.kind === 'note' ? 'Text' : n.kind === 'chip' ? 'Name on the canvas' : n.kind === 'tag' ? 'Signal name' : n.kind === 'ref' ? 'Signal' : 'Label' }}</span>
|
||
<textarea v-if="n.kind === 'note'" ref="labelInput" v-model="n.label" rows="3" @change="ed.commit(false)" />
|
||
<input
|
||
v-else
|
||
ref="labelInput"
|
||
v-model="n.label"
|
||
:placeholder="n.kind === 'chip' ? 'e.g. U1, ALU' : n.kind === 'panel' ? 'Shown above the panel' : n.kind === 'tag' || n.kind === 'ref' ? 'e.g. CLK, RESET' : ''"
|
||
:list="n.kind === 'ref' ? 'signal-names' : undefined"
|
||
@change="onLabel"
|
||
@keydown.enter="($event.target as HTMLInputElement).blur()"
|
||
/>
|
||
</label>
|
||
<p v-if="n.autoLabel && n.label" class="hint -mt-1">Named automatically. Typing a name keeps it.</p>
|
||
<datalist id="signal-names">
|
||
<option v-for="name in signalNames" :key="name" :value="name" />
|
||
</datalist>
|
||
|
||
<!-- Signals -->
|
||
<template v-if="n.kind === 'tag'">
|
||
<p v-if="senders.length > 1" class="result fail">
|
||
<Icon name="lucide:triangle-alert" class="size-4 shrink-0" />
|
||
<span>{{ senders.length }} "Send signal" parts use this name: they all drive it, like a short.</span>
|
||
</p>
|
||
<p class="hint">{{ uses.length ? `Used in ${uses.length} place${uses.length === 1 ? '' : 's'}.` : 'Not used anywhere yet.' }}</p>
|
||
<div class="mb-2 grid grid-cols-2 gap-2">
|
||
<button class="btn" :disabled="!signal" title="A 'Use signal' for it, placed next to it" @click="ed.useSignal(n)"><Icon name="lucide:tag" class="size-4" /> Use it</button>
|
||
<button class="btn" :disabled="!uses.length" @click="ed.selectSignal(signal)"><Icon name="lucide:scan-search" class="size-4" /> Select all</button>
|
||
</div>
|
||
</template>
|
||
<template v-if="n.kind === 'ref'">
|
||
<p v-if="!senders.length" class="result fail">
|
||
<Icon name="lucide:triangle-alert" class="size-4 shrink-0" />
|
||
<span>{{ signal ? `Nothing sends "${signal}" in this circuit, so it reads 0.` : 'Pick the signal it carries.' }}</span>
|
||
</p>
|
||
<div v-else class="mb-2 grid grid-cols-2 gap-2">
|
||
<button class="btn" @click="ed.focusNode(senders[0]!.id)"><Icon name="lucide:locate-fixed" class="size-4" /> Go to source</button>
|
||
<button class="btn" @click="ed.selectSignal(signal)"><Icon name="lucide:scan-search" class="size-4" /> Select all</button>
|
||
</div>
|
||
</template>
|
||
|
||
<!-- Panel rows: switches, buttons and clocks, or lamps -->
|
||
<template v-if="n.kind === 'panel' || n.kind === 'outpanel'">
|
||
<p v-if="dock" class="result pass">
|
||
<Icon name="lucide:link" class="size-4 shrink-0" />
|
||
<span class="grow">Attached to {{ dock }}. It moves with it and gets a row for each new {{ outPanel ? 'output' : 'input' }}.</span>
|
||
<button class="btn-sm" title="Keep the panel and its wires, but stop following the component" @click="ed.undock(n)">Detach</button>
|
||
</p>
|
||
<div class="field">
|
||
<span>Rows</span>
|
||
<ul class="panel-rows">
|
||
<li v-for="(r, i) in n.rows ?? []" :key="r.id" :class="{ open: openRows.has(r.id) }">
|
||
<button
|
||
class="icon-btn"
|
||
:class="{ active: openRows.has(r.id) }"
|
||
:title="openRows.has(r.id) ? 'Fewer settings' : 'Key, colour, spacing and order'"
|
||
@click="toggleRow(r.id)"
|
||
>
|
||
<Icon :name="openRows.has(r.id) ? 'lucide:chevron-down' : 'lucide:chevron-right'" class="size-3.5" />
|
||
</button>
|
||
<input :value="r.label ?? ''" :placeholder="rowLabel({ ...r, label: undefined }, i)" title="Name" @change="setRowLabel(r, $event)" />
|
||
<select v-if="!outPanel" :value="r.type" title="Kind" @change="ed.setRowType(r, ($event.target as HTMLSelectElement).value as PanelControl)">
|
||
<option v-for="c in CONTROLS" :key="c.value" :value="c.value">{{ c.label }}</option>
|
||
</select>
|
||
<input
|
||
v-if="r.type === 'clock'"
|
||
type="number"
|
||
min="0.1"
|
||
max="1000"
|
||
step="any"
|
||
class="hz"
|
||
:value="r.hz ?? ''"
|
||
placeholder="Hz"
|
||
title="Frequency in Hz; empty follows the top bar"
|
||
@change="setRowHz(r, $event)"
|
||
/>
|
||
<button class="icon-btn" title="Remove this row" @click="ed.dropRow(n, r.id)"><Icon name="lucide:x" class="size-3.5" /></button>
|
||
<div v-if="openRows.has(r.id)" class="row-more">
|
||
<label v-if="r.type !== 'clock' && !outPanel" title="Keyboard key that flips the switch or holds the button">
|
||
<span>Key</span>
|
||
<input :value="r.key?.toUpperCase() ?? ''" readonly placeholder="–" class="key-input" @keydown="setRowKey(r, $event)" />
|
||
</label>
|
||
<label v-if="!n.attach && i > 0" title="Empty rows above this one">
|
||
<span>Space</span>
|
||
<input type="number" min="0" max="20" :value="rowGaps[i]" @change="ed.setRowGap(n, i, Number(($event.target as HTMLInputElement).value))" />
|
||
</label>
|
||
<span v-if="!n.attach" class="flex gap-0.5">
|
||
<button class="icon-btn" title="Move up" :disabled="i === 0" @click="ed.moveRow(n, i, -1)"><Icon name="lucide:arrow-up" class="size-3.5" /></button>
|
||
<button class="icon-btn" title="Move down" :disabled="i === (n.rows?.length ?? 0) - 1" @click="ed.moveRow(n, i, 1)"><Icon name="lucide:arrow-down" class="size-3.5" /></button>
|
||
</span>
|
||
<div v-if="r.type !== 'clock' || outPanel" class="swatches mini" title="Colour while on">
|
||
<button
|
||
class="swatch lamp-swatch"
|
||
:class="[outPanel ? 'default' : 'default-on', { active: !r.color, button: r.type === 'button' && !outPanel }]"
|
||
title="Default"
|
||
@click="ed.setRowColor(r, undefined)"
|
||
/>
|
||
<button
|
||
v-for="c in LAMP_COLORS"
|
||
:key="c"
|
||
class="swatch lamp-swatch"
|
||
:class="[`l-${c}`, { active: r.color === c }]"
|
||
:title="c"
|
||
@click="ed.setRowColor(r, c)"
|
||
/>
|
||
</div>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
<div class="flex flex-wrap items-center gap-1">
|
||
<button v-if="!n.attach" class="btn-sm" @click="ed.addRow(n)"><Icon name="lucide:plus" class="size-3.5" /> Add row</button>
|
||
<template v-if="!outPanel && (n.rows?.length ?? 0) > 1">
|
||
<span class="hint ml-auto">All rows:</span>
|
||
<button v-for="c in CONTROLS" :key="c.value" class="btn-sm" :title="`Make every row a ${c.label.toLowerCase()}`" @click="ed.setRowsType(n, c.value)">{{ c.label }}</button>
|
||
</template>
|
||
</div>
|
||
</div>
|
||
<button class="btn w-full" :disabled="!n.rows?.length" @click="ed.startLinking([n.id], outPanel ? 'in' : 'out')">
|
||
<Icon name="lucide:cable" class="size-4" /> Wire rows one by one
|
||
</button>
|
||
<label
|
||
class="check mt-2"
|
||
:title="outPanel ? 'Used as a component, its rows are output pins (top to bottom, with the other outputs).' : 'Used as a component, its switch and button rows are its input pins (top to bottom, with the other inputs). Clock rows stay inside.'"
|
||
>
|
||
<input type="checkbox" :checked="!n.inner" @change="setInner(!($event.target as HTMLInputElement).checked)" />
|
||
Rows are component {{ outPanel ? 'outputs' : 'inputs' }}
|
||
</label>
|
||
<p v-if="n.inner" class="hint">{{ outPanel ? 'Kept inside: the lamps only show in here.' : 'Kept inside: in a component the switches stay as set here, buttons read 0.' }}</p>
|
||
</template>
|
||
|
||
<div v-if="cables.out.length || cables.in.length" class="field cable-choices">
|
||
<span>Plug a cable onto its pins</span>
|
||
<div v-if="cables.out.length" class="cable-row">
|
||
<span class="hint">From outputs</span>
|
||
<button v-for="g in cables.out" :key="g.label" class="btn-sm" :title="`A cable with ${g.pins.length} wires out of these pins`" @click="ed.cableOut(n.id, g.pins)">{{ g.label }}</button>
|
||
</div>
|
||
<div v-if="cables.in.length" class="cable-row">
|
||
<span class="hint">Into inputs</span>
|
||
<button v-for="g in cables.in" :key="g.label" class="btn-sm" :title="`A cable with ${g.pins.length} wires into these pins`" @click="ed.cableIn(n.id, g.pins)">{{ g.label }}</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Kind-specific settings -->
|
||
<template v-if="n.kind === 'input'">
|
||
<div class="field">
|
||
<span>Value</span>
|
||
<div class="seg">
|
||
<button :class="{ active: !n.on }" @click="setOn(false)">0</button>
|
||
<button :class="{ active: n.on }" @click="setOn(true)">1</button>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<label v-if="n.kind === 'input' || n.kind === 'button'" class="field">
|
||
<span>Keyboard key</span>
|
||
<input :value="n.key ?? ''" readonly placeholder="Click, then press a key" class="key-input" @keydown="setKey" />
|
||
</label>
|
||
|
||
<template v-if="n.kind === 'clock'">
|
||
<label class="check">
|
||
<input type="checkbox" :checked="n.hz === undefined" @change="followTopBar" />
|
||
Follow the speed in the top bar
|
||
</label>
|
||
<label v-if="n.hz !== undefined" class="field">
|
||
<span>Frequency (Hz)</span>
|
||
<input type="number" min="0.1" max="1000" step="any" :value="n.hz" list="hz-presets" @change="setHz" />
|
||
<datalist id="hz-presets">
|
||
<option v-for="v in [0.5, 1, 2, 5, 10, 30, 100]" :key="v" :value="v" />
|
||
</datalist>
|
||
</label>
|
||
</template>
|
||
|
||
<label v-if="n.kind === 'pixel'" class="field" title="Pixels with the same screen name make one screen on the component's box; without a name, the main screen">
|
||
<span>Screen on the box</span>
|
||
<input
|
||
:value="n.screen ?? ''"
|
||
list="screen-names"
|
||
placeholder="Main screen"
|
||
@change="ed.setScreen([n.id], ($event.target as HTMLInputElement).value)"
|
||
@keydown.enter="($event.target as HTMLInputElement).blur()"
|
||
/>
|
||
<datalist id="screen-names">
|
||
<option v-for="name in screenNames" :key="name" :value="name" />
|
||
</datalist>
|
||
</label>
|
||
<div v-if="n.kind === 'lamp' || n.kind === 'hex' || n.kind === 'pixel'" class="field">
|
||
<span>Colour</span>
|
||
<div class="swatches">
|
||
<button class="swatch lamp-swatch default" :class="{ active: !n.color, hex: n.kind === 'hex' }" title="Default" @click="setColor(undefined)" />
|
||
<button
|
||
v-for="c in LAMP_COLORS"
|
||
:key="c"
|
||
class="swatch lamp-swatch"
|
||
:class="[`l-${c}`, { active: n.color === c }]"
|
||
:title="c"
|
||
@click="setColor(c)"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-if="n.kind === 'note'" class="field">
|
||
<span>Size</span>
|
||
<div class="seg">
|
||
<button :class="{ active: n.size === 'sm' }" @click="setSize('sm')">Small</button>
|
||
<button :class="{ active: !n.size }" @click="setSize('md')">Normal</button>
|
||
<button :class="{ active: n.size === 'lg' }" @click="setSize('lg')">Large</button>
|
||
</div>
|
||
</div>
|
||
|
||
<template v-if="n.kind === 'bundle' || n.kind === 'split'">
|
||
<p v-if="n.plug" class="result pass">
|
||
<Icon name="lucide:plug-zap" class="size-4 shrink-0" />
|
||
<span class="grow">Plugged into {{ partName(n.plug) }}. It moves with it; drag it away to pull it out.</span>
|
||
<button class="btn-sm" title="Pull it out: it steps aside and its wires show again" @click="ed.unplugEnd(n)">Unplug</button>
|
||
</p>
|
||
<button
|
||
v-else-if="plugPart"
|
||
class="btn mb-2 w-full"
|
||
:title="`Sit straight on the pins of ${partName(plugPart.id)}, without wires in between`"
|
||
@click="ed.plugEnd(n)"
|
||
>
|
||
<Icon name="lucide:plug" class="size-4" /> Plug into {{ partName(plugPart.id) }}
|
||
</button>
|
||
<button
|
||
v-if="n.kind === 'bundle' && undriven && !n.plug"
|
||
class="btn mb-2 w-full"
|
||
title="A switch for every wire nothing drives yet; the cable plugs into it. Make each row a button or clock, give it a key or colour."
|
||
@click="ed.addCablePanel(n.id)"
|
||
>
|
||
<Icon name="lucide:sliders-vertical" class="size-4" /> Attach input panel
|
||
</button>
|
||
<div class="grid grid-cols-2 gap-2">
|
||
<label class="field">
|
||
<span>Wires</span>
|
||
<input type="number" min="2" :max="MAX_BITS" step="1" :value="cableBits(n)" @change="ed.setBits(n, Number(($event.target as HTMLInputElement).value))" />
|
||
</label>
|
||
<label class="field" :title="n.plug ? 'Set by the pins it is plugged into' : 'Rows from one wire to the next, to line up with pins further apart'">
|
||
<span>Spacing</span>
|
||
<input
|
||
type="number"
|
||
min="1"
|
||
max="8"
|
||
step="1"
|
||
:value="pitch ?? ''"
|
||
:placeholder="pitch ? '' : 'as plugged'"
|
||
:disabled="!!n.plug"
|
||
@change="ed.setPitch(n, Number(($event.target as HTMLInputElement).value))"
|
||
/>
|
||
</label>
|
||
</div>
|
||
<p v-if="n.names?.some(Boolean)" class="hint -mt-1">Wires: {{ n.names.map((x, i) => x || i).join(', ') }}</p>
|
||
<div v-if="cableBundle" class="field">
|
||
<span>Sleeve colour (the wires inside keep theirs)</span>
|
||
<div class="swatches">
|
||
<button class="swatch none" :class="{ active: !sleeveColor }" title="Default: grey" @click="ed.setCableColor(cableBundle.id, undefined)" />
|
||
<button
|
||
v-for="c in WIRE_COLORS"
|
||
:key="c"
|
||
class="swatch"
|
||
:class="[`c-${c}`, { active: sleeveColor === c }]"
|
||
:title="c"
|
||
@click="ed.setCableColor(cableBundle.id, c)"
|
||
/>
|
||
</div>
|
||
</div>
|
||
<p class="hint">Drag the bundle and the split to decide where the cable starts and ends. Drop an end with its pins on a part's pins to plug it in.</p>
|
||
<button v-if="cableBundle" class="btn mb-2 w-full" title="Take the cable apart again into single wires" @click="ed.removeCable(cableBundle.id)">
|
||
<Icon name="lucide:split" class="size-4" /> Remove cable
|
||
</button>
|
||
</template>
|
||
|
||
<p v-if="HINTS[n.kind]" class="hint">{{ HINTS[n.kind] }}</p>
|
||
|
||
<template v-if="n.kind === 'chip' && chipDef">
|
||
<p v-if="chipDef.description" class="hint">{{ chipDef.description }}</p>
|
||
<dl v-if="chipStats" class="stats">
|
||
<dt>{{ chipStats.sequential ? 'Memory' : 'Delay' }}</dt>
|
||
<dd>{{ chipStats.sequential ? 'yes (feedback)' : `${chipStats.delay} gates` }}</dd>
|
||
</dl>
|
||
<div class="grid gap-2">
|
||
<button class="btn w-full" @click="ed.open(chipDef.id)"><Icon name="lucide:log-in" class="size-4" /> Open component</button>
|
||
<button class="btn w-full" title="Move its lamps and displays, draw on it, size it: for every copy" @click="ed.designFace(chipDef.id)">
|
||
<Icon name="lucide:pen-tool" class="size-4" /> Design its box
|
||
</button>
|
||
<button
|
||
v-if="chipInputs && !hasPanel"
|
||
class="btn w-full"
|
||
title="A switch for every free input, docked to the left; each one can become a button or clock"
|
||
@click="ed.addPanel(n.id)"
|
||
>
|
||
<Icon name="lucide:sliders-vertical" class="size-4" /> Attach input panel
|
||
</button>
|
||
<button v-if="chipOutputs && !hasOutPanel" class="btn w-full" title="A lamp for every output, docked to the right" @click="ed.addPanel(n.id, 'out')">
|
||
<Icon name="lucide:list-checks" class="size-4" /> Attach output panel
|
||
</button>
|
||
<div v-if="chipInputs || chipOutputs" class="field mb-0">
|
||
<span>Wire one by one</span>
|
||
<div class="grid grid-cols-2 gap-2">
|
||
<button class="btn" :disabled="!chipInputs" title="Click the source for each input in turn" @click="ed.startLinking([n.id], 'in')">
|
||
<Icon name="lucide:cable" class="size-4" /> Inputs
|
||
</button>
|
||
<button class="btn" :disabled="!chipOutputs" title="Click the target for each output in turn" @click="ed.startLinking([n.id], 'out')">
|
||
<Icon name="lucide:cable" class="size-4" /> Outputs
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<button class="btn w-full" title="Replace it with the parts inside; outside wires join them directly" @click="ed.unpack(n.id)">
|
||
<Icon name="lucide:ungroup" class="size-4" /> Unpack into parts
|
||
</button>
|
||
<button class="btn w-full" title="Give this one its own copy, so changing it leaves the others alone" @click="ed.makeIndependent(n.id)">
|
||
<Icon name="lucide:copy-plus" class="size-4" /> Make independent copy
|
||
</button>
|
||
</div>
|
||
</template>
|
||
|
||
<div class="mt-3 grid grid-cols-2 gap-2">
|
||
<label class="field mb-0">
|
||
<span>X</span>
|
||
<input type="number" step="1" :value="n.x" @change="setPos('x', $event)" />
|
||
</label>
|
||
<label class="field mb-0">
|
||
<span>Y</span>
|
||
<input type="number" step="1" :value="n.y" @change="setPos('y', $event)" />
|
||
</label>
|
||
</div>
|
||
|
||
<div class="mt-3 grid grid-cols-2 gap-2">
|
||
<button class="btn" :disabled="!wired" title="Remove every wire attached to it" @click="ed.unlink([n.id])">
|
||
<Icon name="lucide:unlink" class="size-4" /> Unlink all
|
||
</button>
|
||
<button class="btn" @click="ed.duplicate()"><Icon name="lucide:copy" class="size-4" /> Duplicate</button>
|
||
</div>
|
||
<button class="btn btn-ghost mt-2 w-full" @click="ed.deleteSelected()"><Icon name="lucide:trash-2" class="size-4" /> Delete</button>
|
||
</section>
|
||
</template>
|