123 lines
6.0 KiB
Vue
123 lines
6.0 KiB
Vue
<script setup lang="ts">
|
|
const ed = useEditor()
|
|
const menu = ref(false)
|
|
const fileInput = ref<HTMLInputElement>()
|
|
const confirmNew = ref<null | 'empty' | 'examples'>(null)
|
|
|
|
const SPEEDS = [
|
|
{ value: 0.5, label: '0.5 Hz' },
|
|
{ value: 1, label: '1 Hz' },
|
|
{ value: 2, label: '2 Hz' },
|
|
{ value: 5, label: '5 Hz' },
|
|
{ value: 10, label: '10 Hz' },
|
|
{ value: 30, label: '30 Hz' },
|
|
{ value: 0, label: 'Max' },
|
|
]
|
|
|
|
const hasClock = computed(() => (ed.sim.value?.nl.clocks.length ?? 0) > 0)
|
|
const statusText = computed(() => ({ stable: 'Stable', busy: 'Settling', oscillating: 'Oscillating' })[ed.status.value])
|
|
const backName = computed(() => {
|
|
const id = ed.nav.value.at(-1)
|
|
return id ? ed.getDef.value(id)?.name : undefined
|
|
})
|
|
|
|
function onFile(e: Event) {
|
|
const file = (e.target as HTMLInputElement).files?.[0]
|
|
if (file) ed.importJson(file)
|
|
;(e.target as HTMLInputElement).value = ''
|
|
menu.value = false
|
|
}
|
|
|
|
function doNew() {
|
|
if (confirmNew.value) ed.newProject(confirmNew.value === 'examples')
|
|
confirmNew.value = null
|
|
menu.value = false
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<header class="toolbar">
|
|
<div class="flex min-w-0 items-center gap-2">
|
|
<div class="brand">
|
|
<svg viewBox="0 0 32 32" class="size-6" aria-hidden="true">
|
|
<path d="M6 7h10a9 9 0 0 1 0 18H6Z" fill="none" stroke="currentColor" stroke-width="2.5" />
|
|
<circle cx="27" cy="16" r="2.6" fill="none" stroke="currentColor" stroke-width="2.2" />
|
|
</svg>
|
|
<span>Logigate</span>
|
|
</div>
|
|
<button v-if="backName" class="tb-btn" :title="`Back to ${backName}`" @click="ed.back()">
|
|
<Icon name="lucide:arrow-left" class="size-4" />
|
|
<span class="hidden truncate lg:inline">{{ backName }}</span>
|
|
</button>
|
|
<label class="circuit-select" title="Circuit you are editing">
|
|
<Icon name="lucide:cpu" class="size-4 shrink-0 text-(--muted)" />
|
|
<select :value="ed.def.value.id" @change="ed.open(($event.target as HTMLSelectElement).value)">
|
|
<option v-for="d in ed.project.value.components" :key="d.id" :value="d.id">{{ d.name }}</option>
|
|
</select>
|
|
</label>
|
|
</div>
|
|
|
|
<div class="flex items-center gap-1.5">
|
|
<button
|
|
class="tb-btn"
|
|
:class="{ active: ed.running.value }"
|
|
:title="ed.running.value ? 'Pause the clock' : 'Run the clock'"
|
|
:disabled="!hasClock"
|
|
@click="ed.running.value = !ed.running.value"
|
|
>
|
|
<Icon :name="ed.running.value ? 'lucide:pause' : 'lucide:play'" class="size-4" />
|
|
</button>
|
|
<button class="tb-btn" title="One clock cycle" :disabled="!hasClock" @click="ed.running.value = false; ed.step()">
|
|
<Icon name="lucide:step-forward" class="size-4" />
|
|
</button>
|
|
<select v-model.number="ed.hz.value" class="tb-select" title="Clock speed" :disabled="!hasClock">
|
|
<option v-for="s in SPEEDS" :key="s.value" :value="s.value">{{ s.label }}</option>
|
|
</select>
|
|
<span v-if="hasClock" class="cycles tabular-nums" title="Clock cycles since this circuit was opened">{{ ed.cycles.value.toLocaleString() }} ticks</span>
|
|
<span class="status" :class="ed.status.value" :title="ed.status.value === 'oscillating' ? 'A loop keeps flipping and never settles (e.g. a NOT feeding itself)' : 'Simulation state'">
|
|
<span class="dot" />{{ statusText }}
|
|
</span>
|
|
</div>
|
|
|
|
<div class="flex items-center gap-1.5">
|
|
<button class="tb-btn" title="Undo (Ctrl+Z)" :disabled="!ed.canUndo.value" @click="ed.undo()"><Icon name="lucide:undo-2" class="size-4" /></button>
|
|
<button class="tb-btn" title="Redo (Ctrl+Shift+Z)" :disabled="!ed.canRedo.value" @click="ed.redo()"><Icon name="lucide:redo-2" class="size-4" /></button>
|
|
<div class="seg" title="Gate symbols">
|
|
<button :class="{ active: ed.project.value.settings.symbols === 'iec' }" @click="ed.project.value.settings.symbols = 'iec'; ed.commit(false)">IEC</button>
|
|
<button :class="{ active: ed.project.value.settings.symbols === 'ansi' }" @click="ed.project.value.settings.symbols = 'ansi'; ed.commit(false)">ANSI</button>
|
|
</div>
|
|
<button
|
|
class="tb-btn"
|
|
:class="{ active: ed.project.value.settings.flow }"
|
|
title="Animate current flow"
|
|
@click="ed.project.value.settings.flow = !ed.project.value.settings.flow; ed.commit(false)"
|
|
>
|
|
<Icon name="lucide:zap" class="size-4" />
|
|
</button>
|
|
<div class="relative">
|
|
<button class="tb-btn" title="Project" @click="menu = !menu"><Icon name="lucide:folder" class="size-4" /><span class="hidden md:inline">Project</span></button>
|
|
<div v-if="menu" class="menu-backdrop" @click="menu = false; confirmNew = null" />
|
|
<div v-if="menu" class="menu">
|
|
<template v-if="!confirmNew">
|
|
<button @click="ed.exportJson(); menu = false"><Icon name="lucide:download" class="size-4" /> Export as file</button>
|
|
<button @click="fileInput?.click()"><Icon name="lucide:upload" class="size-4" /> Import file</button>
|
|
<hr />
|
|
<button @click="ed.loadExamples(); menu = false"><Icon name="lucide:library" class="size-4" /> Add example parts</button>
|
|
<button @click="confirmNew = 'empty'"><Icon name="lucide:file" class="size-4" /> New project (NAND only)</button>
|
|
<button @click="confirmNew = 'examples'"><Icon name="lucide:file-plus" class="size-4" /> New project with examples</button>
|
|
</template>
|
|
<div v-else class="p-2 text-sm">
|
|
<p class="mb-2">Replace the current project? Export it first if you want to keep it.</p>
|
|
<div class="flex gap-2">
|
|
<button class="btn btn-danger grow" @click="doNew">Replace</button>
|
|
<button class="btn grow" @click="confirmNew = null">Cancel</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<input ref="fileInput" type="file" accept="application/json,.json" class="hidden" @change="onFile" />
|
|
</div>
|
|
<button class="tb-btn" title="Help (?)" @click="ed.showHelp.value = true"><Icon name="lucide:circle-help" class="size-4" /></button>
|
|
</div>
|
|
</header>
|
|
</template>
|