logigate/app/components/editor/MenuCampaign.vue

70 lines
2.9 KiB
Vue

<script setup lang="ts">
// The campaign page of the title menu: how far you are, what is next.
import { CHALLENGES } from '~/lib/logic/challenges'
import { campaignProgress, challengeOpen, KIND_NAMES, KIND_UNLOCK } from '~/lib/logic/progress'
import type { NodeKind } from '~/lib/logic/types'
const ed = useEditor()
const p = ed.projectOf('campaign')
const solved = new Set(p?.solved ?? [])
const next = p ? CHALLENGES.find(c => !solved.has(c.id) && challengeOpen(p, c.id)) : CHALLENGES[0]
const parts = (id: string) =>
(Object.keys(KIND_UNLOCK) as NodeKind[])
.filter(k => KIND_UNLOCK[k] === id)
.map(k => KIND_NAMES[k])
.join(', ')
function fresh() {
ed.startCampaign()
ed.enterGame()
}
</script>
<template>
<div class="menu-campaign">
<p class="hint">
You start with a NAND gate, switches and lamps. Each challenge you solve becomes a part you can use, and opens the next ones. Clocks, buttons, panels and
displays are earned on the way.
</p>
<div class="menu-card">
<template v-if="p">
<div class="flex items-center justify-between">
<span class="font-semibold">{{ solved.size }} of {{ CHALLENGES.length }} solved</span>
<span class="tabular-nums text-(--muted)">{{ Math.round(campaignProgress(p) * 100) }}%</span>
</div>
<div class="bar"><span :style="{ width: `${campaignProgress(p) * 100}%` }" /></div>
<p v-if="next" class="mt-2">Next: <strong>{{ next.name }}</strong>, {{ next.goal }}</p>
<p v-else class="mt-2">Every challenge solved. You built it all from NAND.</p>
</template>
<p v-else>Not started yet. The first task: build NOT from a single NAND gate.</p>
<div class="mt-3 flex flex-wrap gap-2">
<button class="btn btn-primary" @click="ed.playCampaign()">
<Icon name="lucide:play" class="size-4" /> {{ p ? 'Continue the campaign' : 'Start the campaign' }}
</button>
<button v-if="p" class="btn" title="A second campaign from the start; the first one stays in your projects" @click="fresh">
<Icon name="lucide:rotate-ccw" class="size-4" /> Start over
</button>
</div>
</div>
<ol class="menu-steps">
<li
v-for="c in CHALLENGES"
:key="c.id"
:class="{ solved: solved.has(c.id), locked: p ? !challengeOpen(p, c.id) : c !== CHALLENGES[0], next: c === next }"
>
<Icon
:name="solved.has(c.id) ? 'lucide:circle-check' : (p ? challengeOpen(p, c.id) : c === CHALLENGES[0]) ? 'lucide:circle-dot' : 'lucide:lock'"
class="size-4 shrink-0"
/>
<span class="grow">
<span class="font-medium">{{ c.name }}</span>
<span v-if="parts(c.id)" class="unlocks"> · unlocks {{ parts(c.id) }}</span>
</span>
<span v-if="p?.best?.[c.id] !== undefined" class="tabular-nums text-xs text-(--muted)">{{ p.best[c.id] }} transistors</span>
</li>
</ol>
</div>
</template>