logigate/app/components/editor/WireSettings.vue

62 lines
3.2 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import { cableOf } from '~/lib/logic/cables'
import { WIRE_COLORS } from '~/lib/logic/types'
const ed = useEditor()
const wires = ed.selectedWires
const wireColor = computed(() => {
const colors = new Set(wires.value.map(w => w.color ?? ''))
return colors.size === 1 ? [...colors][0] : null
})
const cable = computed(() => (wires.value.length === 1 ? cableOf(ed.def.value, wires.value[0]!) : undefined))
/** The selected wire is the cable itself (it leaves a bundle). */
const isCable = computed(() => wires.value.length === 1 && cable.value?.id === wires.value[0]!.from.node)
</script>
<template>
<section>
<h3>{{ isCable ? 'Cable' : wires.length === 1 ? 'Wire' : `${wires.length} wires` }}</h3>
<p v-if="isCable" class="hint">The colour is the cable's sleeve; each wire inside keeps its own colour. Drag its bundle and split to move where it starts and ends.</p>
<div class="field">
<span>{{ isCable ? 'Sleeve colour' : 'Colour' }}</span>
<div class="swatches">
<button class="swatch none" :class="{ active: wireColor === '' }" title="Default: grey, green while on" @click="ed.setWireColor(undefined)" />
<button
v-for="c in WIRE_COLORS"
:key="c"
class="swatch"
:class="[`c-${c}`, { active: wireColor === c }]"
:title="c"
@click="ed.setWireColor(c)"
/>
</div>
</div>
<div class="grid grid-cols-2 gap-2">
<button v-if="wires.length === 1" class="btn" @click="ed.selectNet(wires[0]!.id)"><Icon name="lucide:git-fork" class="size-4" /> Whole signal</button>
<button class="btn" :disabled="!wires.some(w => w.pts)" @click="ed.autoRoute()"><Icon name="lucide:wand-sparkles" class="size-4" /> Auto route</button>
</div>
<template v-if="wires.length >= 2">
<button class="btn btn-primary mt-2 w-full" title="Starts right after the sources, ends right before the targets (Ctrl+G)" @click="ed.bundleSelected()">
<Icon name="lucide:merge" class="size-4" /> Bundle into cable
</button>
<button class="btn btn-ghost mt-1 w-full" title="Click where the cable starts, then where it ends (Ctrl+Shift+G)" @click="ed.startCable()">
Place the ends yourself…
</button>
</template>
<button v-if="cable" class="btn mt-2 w-full" title="Take the cable apart again into single wires" @click="ed.removeCable(cable.id)">
<Icon name="lucide:split" class="size-4" /> Remove cable
</button>
<button class="btn btn-ghost mt-2 w-full" @click="ed.deleteSelected()"><Icon name="lucide:trash-2" class="size-4" /> Delete</button>
<details class="tips-box">
<summary>Editing wires</summary>
<ul class="tips">
<li><strong>Drag</strong> a segment to move it, a <strong>corner square</strong> to move a bend.</li>
<li><strong>Alt + drag</strong> pulls a new bend out of a segment.</li>
<li><strong>Ctrl + drag</strong> starts a new wire from this signal.</li>
<li><strong>Double-click</strong> selects the whole signal, <strong>Shift + click</strong> adds wires.</li>
<li><strong>Arrow keys</strong> shift the selected wires.</li>
</ul>
</details>
</section>
</template>