110 lines
4.3 KiB
Vue
110 lines
4.3 KiB
Vue
<script setup lang="ts">
|
|
// The panel on the right, floating over the canvas: tabs for the selection,
|
|
// the circuit, its pins, and testing. It opens on its own while something is
|
|
// selected (like a building's info panel in a city builder); the pin keeps it
|
|
// open, and opening a challenge pins it on its Test tab.
|
|
import { ioList } from '~/lib/logic/bulk'
|
|
|
|
const ed = useEditor()
|
|
type Tab = 'selection' | 'circuit' | 'pins' | 'test'
|
|
|
|
const single = computed(() =>
|
|
ed.selection.value.length === 1 && !ed.wireSel.value.length ? ed.def.value.nodes.find(n => n.id === ed.selection.value[0]) : undefined,
|
|
)
|
|
const selected = computed(() => ed.selection.value.length + ed.wireSel.value.length)
|
|
const pinCount = computed(() => {
|
|
const io = ioList(ed.def.value)
|
|
return io.inputs.length + io.outputs.length
|
|
})
|
|
const hasTask = computed(() => !!ed.task.value)
|
|
|
|
function close() {
|
|
ed.toggleSidebar('right', false)
|
|
ed.selection.value = []
|
|
ed.wireSel.value = []
|
|
}
|
|
/** Errors and warnings in the open circuit, on the Circuit tab. */
|
|
const problems = computed(() => ed.issues.value.filter(i => i.level !== 'info').length)
|
|
|
|
const tabs = computed(() => [
|
|
{ id: 'selection' as Tab, label: 'Selection', icon: 'lucide:mouse-pointer-2', badge: selected.value || '' },
|
|
{ id: 'circuit' as Tab, label: 'Circuit', icon: 'lucide:cpu', badge: problems.value || '', warn: problems.value > 0 },
|
|
{ id: 'pins' as Tab, label: 'Pins', icon: 'lucide:list', badge: pinCount.value || '' },
|
|
{ id: 'test' as Tab, label: 'Test', icon: hasTask.value ? 'lucide:flag' : 'lucide:table', badge: '' },
|
|
])
|
|
|
|
// Selecting something shows its settings, unless you are working in Pins or
|
|
// Test (where clicking a switch to try the circuit also selects it).
|
|
let before: Tab = 'circuit'
|
|
watch(selected, (now, was) => {
|
|
const tab = ed.rightTab.value
|
|
if (now && !was && (tab === 'circuit' || !ed.sidebars.right)) {
|
|
before = tab
|
|
ed.rightTab.value = 'selection'
|
|
} else if (!now && tab === 'selection') ed.rightTab.value = before
|
|
})
|
|
watch(
|
|
() => ed.labelFocus.value,
|
|
() => {
|
|
if (selected.value) ed.rightTab.value = 'selection'
|
|
},
|
|
)
|
|
// Opening a challenge or puzzle shows what to build.
|
|
watch(
|
|
() => ed.def.value.id,
|
|
() => {
|
|
if (ed.task.value) {
|
|
ed.rightTab.value = 'test'
|
|
ed.toggleSidebar('right', true)
|
|
} else if (ed.rightTab.value === 'test') ed.rightTab.value = 'circuit'
|
|
},
|
|
{ immediate: true },
|
|
)
|
|
</script>
|
|
|
|
<template>
|
|
<aside class="inspector">
|
|
<nav class="itabs" role="tablist">
|
|
<button
|
|
v-for="t in tabs"
|
|
:key="t.id"
|
|
role="tab"
|
|
:aria-selected="ed.rightTab.value === t.id"
|
|
:class="{ active: ed.rightTab.value === t.id, task: t.id === 'test' && hasTask }"
|
|
:title="t.label"
|
|
@click="ed.rightTab.value = t.id"
|
|
>
|
|
<Icon :name="t.icon" class="size-4 shrink-0" />
|
|
<span class="label">{{ t.label }}</span>
|
|
<span v-if="t.badge" class="badge" :class="{ warn: 'warn' in t && t.warn }">{{ t.badge }}</span>
|
|
</button>
|
|
<div class="itabs-tools">
|
|
<button
|
|
class="collapse-btn"
|
|
:class="{ active: ed.sidebars.right }"
|
|
:title="ed.sidebars.right ? 'Kept open; click to let it close with the selection (])' : 'Keep this panel open (])'"
|
|
@click="ed.toggleSidebar('right')"
|
|
>
|
|
<Icon :name="ed.sidebars.right ? 'lucide:pin' : 'lucide:pin-off'" class="size-3.5" />
|
|
</button>
|
|
<button class="collapse-btn" title="Close" @click="close"><Icon name="lucide:x" class="size-4" /></button>
|
|
</div>
|
|
</nav>
|
|
<div class="scroll">
|
|
<template v-if="ed.rightTab.value === 'selection'">
|
|
<EditorNodeSettings v-if="single" :key="single.id" :node="single" />
|
|
<EditorBulkSettings v-else-if="ed.selection.value.length" />
|
|
<EditorWireSettings v-else-if="ed.wireSel.value.length" />
|
|
<section v-else class="empty-pane">
|
|
<Icon name="lucide:mouse-pointer-click" class="size-6" />
|
|
<p>Click a part or wire to change it.</p>
|
|
<p class="hint">Shift + click or drag a box to select several; you can then rename, swap or switch them all at once.</p>
|
|
</section>
|
|
</template>
|
|
<EditorCircuitPane v-else-if="ed.rightTab.value === 'circuit'" />
|
|
<EditorPinsPane v-else-if="ed.rightTab.value === 'pins'" />
|
|
<EditorTestPane v-else />
|
|
</div>
|
|
</aside>
|
|
</template>
|