logigate/app/components/editor/TruthTable.vue

36 lines
1.2 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import type { TruthTable } from '~/lib/logic/analyze'
import { chipPins } from '~/lib/logic/geometry'
defineProps<{ table: TruthTable; large?: boolean }>()
const ed = useEditor()
/** The row the switches are set to right now. */
const current = computed(() => {
const d = ed.def.value
const on = new Map(d.nodes.map(n => [n.id, !!n.on]))
return chipPins(d).inputs.reduce((i, p) => i * 2 + (on.get(p.key) ? 1 : 0), 0)
})
</script>
<template>
<div class="truth" :class="{ large }">
<table>
<thead>
<tr>
<th v-for="(l, i) in table.inputs" :key="`i${i}`">{{ l }}</th>
<th class="sep" />
<th v-for="(l, i) in table.outputs" :key="`o${i}`" class="out">{{ l }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(r, i) in table.rows" :key="i" :class="{ unstable: !r.settled, current: i === current }">
<td v-for="(v, k) in r.ins" :key="`i${k}`" :class="{ one: v }">{{ v }}</td>
<td class="sep" />
<td v-for="(v, k) in r.outs" :key="`o${k}`" class="out" :class="{ one: v }">{{ r.settled ? v : '~' }}</td>
</tr>
</tbody>
</table>
</div>
</template>