First commit
This commit is contained in:
370
frontend/app/pages/account.vue
Normal file
370
frontend/app/pages/account.vue
Normal file
@@ -0,0 +1,370 @@
|
||||
<script setup lang="ts">
|
||||
import { authHeaders, hasAuth, setAuthToken } from '~/utils/auth'
|
||||
import { saveDeck, type SavedDeck } from '~/utils/decks'
|
||||
import { loadPlaymatChoice, savePlaymatChoice, type PlaymatChoice, type PlaymatSelection } from '~/utils/playmat'
|
||||
|
||||
const { public: { apiBase } } = useRuntimeConfig()
|
||||
const route = useRoute()
|
||||
|
||||
const mode = ref<'login' | 'register'>('login')
|
||||
const username = ref('')
|
||||
const password = ref('')
|
||||
const signedIn = ref('')
|
||||
const busy = ref(false)
|
||||
const error = ref('')
|
||||
|
||||
const playmat = ref<PlaymatChoice>()
|
||||
const playmatError = ref('')
|
||||
const playmatPreview = computed(() => {
|
||||
if (playmat.value?.kind === 'card') return playmat.value
|
||||
if (playmat.value?.kind === 'upload') return { kind: 'upload' as const, url: playmat.value.data }
|
||||
return null
|
||||
})
|
||||
|
||||
async function choosePlaymat(selection: PlaymatSelection) {
|
||||
playmatError.value = ''
|
||||
if (selection.kind === 'none') {
|
||||
if (!(await savePlaymatChoice(apiBase, undefined))) {
|
||||
playmatError.value = 'Could not save that playmat to your account.'
|
||||
return
|
||||
}
|
||||
playmat.value = undefined
|
||||
return
|
||||
}
|
||||
const choice: PlaymatChoice = selection.kind === 'card'
|
||||
? { kind: 'card', oracleId: selection.oracleId }
|
||||
: { kind: 'upload', data: selection.data }
|
||||
if (!(await savePlaymatChoice(apiBase, choice))) {
|
||||
playmatError.value = 'Could not save that playmat to your account. Try a smaller image.'
|
||||
return
|
||||
}
|
||||
playmat.value = choice
|
||||
}
|
||||
|
||||
function nextPath(): string {
|
||||
const next = route.query.next
|
||||
return typeof next === 'string' && next.startsWith('/') && !next.startsWith('//') ? next : '/'
|
||||
}
|
||||
|
||||
function message(caught: unknown): string {
|
||||
const data = (caught as { data?: { error?: string } })?.data
|
||||
return data?.error ?? 'Could not reach the server.'
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
if (!hasAuth()) return
|
||||
try {
|
||||
const data = await $fetch<{ username: string }>(`${apiBase}/auth/me`, { headers: authHeaders() })
|
||||
signedIn.value = data.username
|
||||
} catch {
|
||||
setAuthToken(undefined)
|
||||
}
|
||||
}
|
||||
|
||||
/** Move decks and cosmetic preferences saved by older browser-only versions. */
|
||||
async function migrateLocalData() {
|
||||
if (typeof localStorage === 'undefined') return
|
||||
|
||||
const decks = localStorage.getItem('commander-decks-v1')
|
||||
if (decks !== null) {
|
||||
try {
|
||||
const parsed = JSON.parse(decks) as SavedDeck[]
|
||||
if (Array.isArray(parsed)) {
|
||||
for (const deck of parsed) await saveDeck(apiBase, deck)
|
||||
localStorage.removeItem('commander-decks-v1')
|
||||
}
|
||||
} catch {
|
||||
// Keep corrupt data in place rather than deleting it.
|
||||
}
|
||||
}
|
||||
|
||||
const playmat = localStorage.getItem('commander-playmat-v1')
|
||||
if (playmat !== null) {
|
||||
try {
|
||||
const choice = JSON.parse(playmat) as PlaymatChoice | null
|
||||
if (await savePlaymatChoice(apiBase, choice ?? undefined)) {
|
||||
localStorage.removeItem('commander-playmat-v1')
|
||||
}
|
||||
} catch {
|
||||
// Keep corrupt data in place rather than deleting it.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
busy.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const data = await $fetch<{ token: string; username: string }>(`${apiBase}/auth/${mode.value}`, {
|
||||
method: 'POST',
|
||||
body: { username: username.value, password: password.value },
|
||||
})
|
||||
setAuthToken(data.token)
|
||||
signedIn.value = data.username
|
||||
try {
|
||||
await migrateLocalData()
|
||||
} catch {
|
||||
// A failed migration must not block signing in.
|
||||
}
|
||||
await navigateTo(nextPath())
|
||||
} catch (caught) {
|
||||
error.value = message(caught)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
try {
|
||||
await $fetch(`${apiBase}/auth/logout`, { method: 'POST', headers: authHeaders() })
|
||||
} catch {
|
||||
// Clearing the token locally is enough.
|
||||
}
|
||||
setAuthToken(undefined)
|
||||
password.value = ''
|
||||
signedIn.value = ''
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await refresh()
|
||||
if (!signedIn.value) return
|
||||
playmat.value = await loadPlaymatChoice(apiBase)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="page account-page">
|
||||
<section class="auth-card" :class="{ wide: signedIn }">
|
||||
<header class="auth-head">
|
||||
<span class="auth-mark" aria-hidden="true">◆</span>
|
||||
<p v-if="signedIn" class="muted">
|
||||
Signed in as <strong>{{ signedIn }}</strong>
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<template v-if="signedIn">
|
||||
<div class="signed-actions">
|
||||
<NuxtLink class="auth-link" to="/">Play</NuxtLink>
|
||||
<NuxtLink class="auth-link" to="/decks">Decks</NuxtLink>
|
||||
<button type="button" class="mini" @click="logout">Sign out</button>
|
||||
</div>
|
||||
|
||||
<section class="prefs">
|
||||
<h2>Playmat</h2>
|
||||
<p class="muted">
|
||||
Your mat for new games. Pick card art or upload an image; you can still change it in-game.
|
||||
</p>
|
||||
<p v-if="playmatError" class="error">{{ playmatError }}</p>
|
||||
<PlaymatPicker :current="playmatPreview" @select="choosePlaymat" />
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div class="auth-tabs" role="tablist" aria-label="Account mode">
|
||||
<button
|
||||
type="button"
|
||||
role="tab"
|
||||
:aria-selected="mode === 'login'"
|
||||
:class="{ active: mode === 'login' }"
|
||||
@click="mode = 'login'"
|
||||
>Sign in</button>
|
||||
<button
|
||||
type="button"
|
||||
role="tab"
|
||||
:aria-selected="mode === 'register'"
|
||||
:class="{ active: mode === 'register' }"
|
||||
@click="mode = 'register'"
|
||||
>Create account</button>
|
||||
</div>
|
||||
|
||||
<form @submit.prevent="submit">
|
||||
<label class="field">
|
||||
<span>Username</span>
|
||||
<input
|
||||
v-model="username"
|
||||
autocomplete="username"
|
||||
minlength="3"
|
||||
maxlength="32"
|
||||
placeholder="your name"
|
||||
required
|
||||
>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>Password</span>
|
||||
<input
|
||||
v-model="password"
|
||||
type="password"
|
||||
:autocomplete="mode === 'login' ? 'current-password' : 'new-password'"
|
||||
minlength="8"
|
||||
maxlength="200"
|
||||
placeholder="••••••••"
|
||||
required
|
||||
>
|
||||
</label>
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
<button type="submit" class="primary" :disabled="busy">
|
||||
{{ busy ? 'Working…' : mode === 'login' ? 'Sign in' : 'Create account' }}
|
||||
</button>
|
||||
</form>
|
||||
</template>
|
||||
</section>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
main.account-page {
|
||||
min-height: calc(100vh - 3rem);
|
||||
max-width: none;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 2rem 1.25rem;
|
||||
background: radial-gradient(60rem 32rem at 50% -12%, rgba(122, 162, 247, 0.13), transparent 70%);
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.25rem;
|
||||
width: 100%;
|
||||
max-width: 26rem;
|
||||
padding: 1.75rem;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(180deg, #1b1f2b, var(--panel));
|
||||
box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
|
||||
}
|
||||
|
||||
.auth-card.wide {
|
||||
max-width: 42rem;
|
||||
}
|
||||
|
||||
.prefs {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.6rem;
|
||||
padding-top: 1.25rem;
|
||||
border-top: 1px solid var(--line);
|
||||
}
|
||||
|
||||
.prefs h2 {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.auth-head {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.45rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.auth-head h1 {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.auth-head p {
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.auth-mark {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 2.5rem;
|
||||
height: 2.5rem;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 12px;
|
||||
background: linear-gradient(135deg, rgba(122, 162, 247, 0.35), rgba(122, 162, 247, 0.08));
|
||||
color: var(--accent);
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.auth-tabs {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 0.25rem;
|
||||
padding: 0.25rem;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 10px;
|
||||
background: var(--panel-2);
|
||||
}
|
||||
|
||||
.auth-tabs button {
|
||||
padding: 0.5rem;
|
||||
border: 0;
|
||||
border-radius: 7px;
|
||||
background: transparent;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.auth-tabs button:hover {
|
||||
border: 0;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.auth-tabs button.active {
|
||||
color: var(--text);
|
||||
background: rgba(122, 162, 247, 0.16);
|
||||
box-shadow: inset 0 0 0 1px rgba(122, 162, 247, 0.35);
|
||||
}
|
||||
|
||||
.auth-card form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.85rem;
|
||||
}
|
||||
|
||||
.auth-card .field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.auth-card .field span {
|
||||
color: var(--muted);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.auth-card .field input {
|
||||
width: 100%;
|
||||
padding: 0.65rem 0.75rem;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.auth-card .field input:focus {
|
||||
border-color: var(--accent);
|
||||
outline: none;
|
||||
box-shadow: 0 0 0 3px rgba(122, 162, 247, 0.16);
|
||||
}
|
||||
|
||||
.auth-card button[type="submit"] {
|
||||
margin-top: 0.25rem;
|
||||
padding: 0.65rem;
|
||||
border-radius: 8px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.auth-card .error {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.signed-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
gap: 0.6rem;
|
||||
}
|
||||
|
||||
.auth-link {
|
||||
padding: 0.45rem 0.7rem;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
color: var(--muted);
|
||||
font-size: 0.85rem;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.auth-link:hover {
|
||||
border-color: var(--accent);
|
||||
color: var(--text);
|
||||
}
|
||||
</style>
|
||||
445
frontend/app/pages/cards.vue
Normal file
445
frontend/app/pages/cards.vue
Normal file
@@ -0,0 +1,445 @@
|
||||
<script setup lang="ts">
|
||||
import CardGraphEditor from '../components/CardGraphEditor.vue'
|
||||
import PseudoGuide from '../components/PseudoGuide.vue'
|
||||
|
||||
type Status = 'supported' | 'partial' | 'unsupported'
|
||||
|
||||
interface CardSummary {
|
||||
oracle_id: string
|
||||
name: string
|
||||
mana_cost?: string
|
||||
type_line: string
|
||||
oracle_text?: string
|
||||
card_faces?: Array<{
|
||||
name: string
|
||||
mana_cost?: string
|
||||
type_line?: string
|
||||
oracle_text?: string
|
||||
}>
|
||||
implementation: { status: Status; manual: boolean } | null
|
||||
}
|
||||
|
||||
interface ImplementationResponse {
|
||||
card: CardSummary
|
||||
compiled: { status: Status }
|
||||
source: string
|
||||
manual: boolean
|
||||
updatedAt?: string
|
||||
error?: string
|
||||
}
|
||||
|
||||
interface Stats {
|
||||
supported: number
|
||||
partial: number
|
||||
unsupported: number
|
||||
manual: number
|
||||
}
|
||||
|
||||
const { public: { apiBase } } = useRuntimeConfig()
|
||||
const pageSize = 50
|
||||
|
||||
const formatOptions = [
|
||||
{ value: 'commander', label: 'Commander' },
|
||||
{ value: 'brawl', label: 'Brawl' },
|
||||
{ value: 'standard', label: 'Standard' },
|
||||
{ value: 'pioneer', label: 'Pioneer' },
|
||||
{ value: 'modern', label: 'Modern' },
|
||||
{ value: 'legacy', label: 'Legacy' },
|
||||
{ value: 'vintage', label: 'Vintage' },
|
||||
{ value: 'pauper', label: 'Pauper' },
|
||||
{ value: 'historic', label: 'Historic' },
|
||||
{ value: 'timeless', label: 'Timeless' },
|
||||
{ value: 'explorer', label: 'Explorer' },
|
||||
{ value: 'alchemy', label: 'Alchemy' },
|
||||
{ value: 'oathbreaker', label: 'Oathbreaker' },
|
||||
{ value: 'duel', label: 'Duel Commander' },
|
||||
{ value: 'paupercommander', label: 'Pauper Commander' },
|
||||
{ value: 'standardbrawl', label: 'Standard Brawl' },
|
||||
{ value: 'gladiator', label: 'Gladiator' },
|
||||
{ value: 'competitivebrawl', label: 'Competitive Brawl' },
|
||||
{ value: 'premodern', label: 'Premodern' },
|
||||
{ value: 'predh', label: 'PreDH' },
|
||||
{ value: 'oldschool', label: 'Old School' },
|
||||
{ value: 'penny', label: 'Penny Dreadful' },
|
||||
]
|
||||
const colorOptions = [
|
||||
{ value: 'W', label: 'White' },
|
||||
{ value: 'U', label: 'Blue' },
|
||||
{ value: 'B', label: 'Black' },
|
||||
{ value: 'R', label: 'Red' },
|
||||
{ value: 'G', label: 'Green' },
|
||||
{ value: 'M', label: 'Multicolor' },
|
||||
{ value: 'C', label: 'Colorless' },
|
||||
]
|
||||
const typeOptions = [
|
||||
{ value: 'creature', label: 'Creature' },
|
||||
{ value: 'instant', label: 'Instant' },
|
||||
{ value: 'sorcery', label: 'Sorcery' },
|
||||
{ value: 'artifact', label: 'Artifact' },
|
||||
{ value: 'enchantment', label: 'Enchantment' },
|
||||
{ value: 'planeswalker', label: 'Planeswalker' },
|
||||
{ value: 'battle', label: 'Battle' },
|
||||
{ value: 'land', label: 'Land' },
|
||||
{ value: 'kindred', label: 'Kindred' },
|
||||
{ value: 'legendary', label: 'Legendary' },
|
||||
]
|
||||
const rarityOptions = ['common', 'uncommon', 'rare', 'mythic', 'special', 'bonus']
|
||||
const cmcOptions = ['0', '1', '2', '3', '4', '5', '6', '7+']
|
||||
|
||||
const view = ref<'editor' | 'guide'>('editor')
|
||||
const editorMode = ref<'text' | 'visual'>('text')
|
||||
const search = ref('')
|
||||
const statusFilter = ref('needs-work')
|
||||
const formatFilter = ref('')
|
||||
const colorFilter = ref('')
|
||||
const typeFilter = ref('')
|
||||
const rarityFilter = ref('')
|
||||
const cmcFilter = ref('')
|
||||
const cards = ref<CardSummary[]>([])
|
||||
const total = ref(0)
|
||||
const offset = ref(0)
|
||||
const loadingList = ref(false)
|
||||
const listError = ref('')
|
||||
|
||||
const stats = ref<Stats | null>(null)
|
||||
const selectedId = ref('')
|
||||
const detail = ref<ImplementationResponse | null>(null)
|
||||
const source = ref('')
|
||||
const detailLoading = ref(false)
|
||||
const saving = ref(false)
|
||||
const translating = ref(false)
|
||||
const editorError = ref('')
|
||||
|
||||
const page = computed(() => Math.floor(offset.value / pageSize) + 1)
|
||||
const pageCount = computed(() => Math.max(1, Math.ceil(total.value / pageSize)))
|
||||
const dirty = computed(() => Boolean(detail.value) && source.value !== detail.value!.source)
|
||||
|
||||
function errorMessage(error: unknown): string {
|
||||
const data = (error as { data?: { error?: string } })?.data
|
||||
return data?.error ?? (error instanceof Error ? error.message : String(error))
|
||||
}
|
||||
|
||||
function manaCostOf(card: CardSummary): string | undefined {
|
||||
const faces = card.card_faces?.map(face => face.mana_cost).filter(Boolean) ?? []
|
||||
return card.mana_cost ?? (faces.length ? faces.join(' // ') : undefined)
|
||||
}
|
||||
|
||||
async function loadStats() {
|
||||
try {
|
||||
stats.value = await $fetch<Stats>(`${apiBase}/stats`)
|
||||
} catch {
|
||||
stats.value = null
|
||||
}
|
||||
}
|
||||
|
||||
async function loadCards(reset = false) {
|
||||
loadingList.value = true
|
||||
listError.value = ''
|
||||
if (reset) offset.value = 0
|
||||
try {
|
||||
const data = await $fetch<{ total: number; cards: CardSummary[] }>(`${apiBase}/cards`, {
|
||||
query: {
|
||||
q: search.value,
|
||||
status: statusFilter.value,
|
||||
format: formatFilter.value || undefined,
|
||||
color: colorFilter.value || undefined,
|
||||
type: typeFilter.value || undefined,
|
||||
rarity: rarityFilter.value || undefined,
|
||||
cmcMin: cmcFilter.value === '7+' ? '7' : cmcFilter.value || undefined,
|
||||
cmcMax: cmcFilter.value === '7+' ? undefined : cmcFilter.value || undefined,
|
||||
limit: pageSize,
|
||||
offset: offset.value,
|
||||
},
|
||||
})
|
||||
cards.value = data.cards
|
||||
total.value = data.total
|
||||
} catch (error) {
|
||||
listError.value = errorMessage(error)
|
||||
} finally {
|
||||
loadingList.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function selectCard(card: CardSummary) {
|
||||
selectedId.value = card.oracle_id
|
||||
detailLoading.value = true
|
||||
editorError.value = ''
|
||||
try {
|
||||
detail.value = await $fetch<ImplementationResponse>(
|
||||
`${apiBase}/cards/${card.oracle_id}/implementation`,
|
||||
)
|
||||
source.value = detail.value.source
|
||||
} catch (error) {
|
||||
detail.value = null
|
||||
editorError.value = errorMessage(error)
|
||||
} finally {
|
||||
detailLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (!detail.value || saving.value) return
|
||||
saving.value = true
|
||||
editorError.value = ''
|
||||
try {
|
||||
const data = await $fetch<ImplementationResponse>(
|
||||
`${apiBase}/cards/${detail.value.card.oracle_id}/implementation`,
|
||||
{ method: 'PUT', body: { source: source.value } },
|
||||
)
|
||||
detail.value = data
|
||||
source.value = data.source
|
||||
updateSummary(data)
|
||||
await loadStats()
|
||||
} catch (error) {
|
||||
editorError.value = errorMessage(error)
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function translate() {
|
||||
if (!detail.value || translating.value) return
|
||||
if (dirty.value && !window.confirm('Replace the current edits with an AI draft?')) return
|
||||
translating.value = true
|
||||
editorError.value = ''
|
||||
try {
|
||||
const data = await $fetch<{ source: string }>(
|
||||
`${apiBase}/cards/${detail.value.card.oracle_id}/translate`,
|
||||
{ method: 'POST' },
|
||||
)
|
||||
source.value = data.source
|
||||
} catch (error) {
|
||||
editorError.value = errorMessage(error)
|
||||
} finally {
|
||||
translating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function reset() {
|
||||
if (!detail.value || saving.value) return
|
||||
if (!window.confirm('Delete the manual implementation and restore the generated one?')) return
|
||||
saving.value = true
|
||||
editorError.value = ''
|
||||
try {
|
||||
const data = await $fetch<ImplementationResponse>(
|
||||
`${apiBase}/cards/${detail.value.card.oracle_id}/implementation`,
|
||||
{ method: 'DELETE' },
|
||||
)
|
||||
detail.value = data
|
||||
source.value = data.source
|
||||
updateSummary(data)
|
||||
await loadStats()
|
||||
} catch (error) {
|
||||
editorError.value = errorMessage(error)
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function updateSummary(data: ImplementationResponse) {
|
||||
const card = cards.value.find(entry => entry.oracle_id === data.card.oracle_id)
|
||||
if (card) card.implementation = { status: data.compiled.status, manual: data.manual }
|
||||
}
|
||||
|
||||
function previousPage() {
|
||||
if (offset.value === 0) return
|
||||
offset.value = Math.max(0, offset.value - pageSize)
|
||||
loadCards()
|
||||
}
|
||||
|
||||
function nextPage() {
|
||||
if (offset.value + pageSize >= total.value) return
|
||||
offset.value += pageSize
|
||||
loadCards()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadStats()
|
||||
loadCards(true)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="fill-page">
|
||||
<header>
|
||||
<div>
|
||||
<h1>Card implementations</h1>
|
||||
<p class="muted">
|
||||
<template v-if="stats">
|
||||
{{ stats.supported.toLocaleString() }} supported ·
|
||||
{{ stats.partial.toLocaleString() }} partial ·
|
||||
{{ stats.unsupported.toLocaleString() }} unsupported ·
|
||||
{{ stats.manual.toLocaleString() }} manual
|
||||
</template>
|
||||
<template v-else>Loading stats…</template>
|
||||
</p>
|
||||
</div>
|
||||
<div class="head-actions">
|
||||
<div class="tabs">
|
||||
<button type="button" :class="{ active: view === 'editor' }" @click="view = 'editor'">Editor</button>
|
||||
<button type="button" :class="{ active: view === 'guide' }" @click="view = 'guide'">Guide</button>
|
||||
</div>
|
||||
<a :href="`${apiBase}/health`" target="_blank" rel="noreferrer">API health</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div v-if="view === 'editor'" class="layout">
|
||||
<section class="list-panel">
|
||||
<form class="search" @submit.prevent="loadCards(true)">
|
||||
<input v-model="search" type="search" placeholder="Search card names…">
|
||||
<select v-model="statusFilter" aria-label="Implementation status" @change="loadCards(true)">
|
||||
<option value="needs-work">Needs work</option>
|
||||
<option value="unsupported">Not implemented</option>
|
||||
<option value="partial">Partial</option>
|
||||
<option value="supported">Supported</option>
|
||||
<option value="manual">Manual</option>
|
||||
<option value="all">All cards</option>
|
||||
</select>
|
||||
<button type="submit">Search</button>
|
||||
</form>
|
||||
|
||||
<div class="filters">
|
||||
<select v-model="formatFilter" aria-label="Format legality" @change="loadCards(true)">
|
||||
<option value="">Any format</option>
|
||||
<option v-for="format in formatOptions" :key="format.value" :value="format.value">
|
||||
{{ format.label }}
|
||||
</option>
|
||||
</select>
|
||||
<select v-model="colorFilter" aria-label="Color identity" @change="loadCards(true)">
|
||||
<option value="">Any color</option>
|
||||
<option v-for="color in colorOptions" :key="color.value" :value="color.value">
|
||||
{{ color.label }}
|
||||
</option>
|
||||
</select>
|
||||
<select v-model="typeFilter" aria-label="Card type" @change="loadCards(true)">
|
||||
<option value="">Any type</option>
|
||||
<option v-for="type in typeOptions" :key="type.value" :value="type.value">
|
||||
{{ type.label }}
|
||||
</option>
|
||||
</select>
|
||||
<select v-model="rarityFilter" aria-label="Rarity" @change="loadCards(true)">
|
||||
<option value="">Any rarity</option>
|
||||
<option v-for="rarity in rarityOptions" :key="rarity" :value="rarity">
|
||||
{{ rarity }}
|
||||
</option>
|
||||
</select>
|
||||
<select v-model="cmcFilter" aria-label="Mana value" @change="loadCards(true)">
|
||||
<option value="">Any mana value</option>
|
||||
<option v-for="cmc in cmcOptions" :key="cmc" :value="cmc">
|
||||
{{ cmc === '7+' ? '7 or more' : cmc }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<p v-if="listError" class="error">{{ listError }}</p>
|
||||
<p v-else-if="loadingList" class="muted">Loading…</p>
|
||||
<p v-else-if="!cards.length" class="muted">No cards match.</p>
|
||||
|
||||
<ul class="card-list">
|
||||
<li v-for="card in cards" :key="card.oracle_id">
|
||||
<CardHover :oracle-id="card.oracle_id" :name="card.name">
|
||||
<button
|
||||
type="button"
|
||||
class="card-row"
|
||||
:class="{ selected: card.oracle_id === selectedId }"
|
||||
@click="selectCard(card)"
|
||||
>
|
||||
<span class="card-main">
|
||||
<span class="card-name">{{ card.name }}</span>
|
||||
<ManaCost :cost="manaCostOf(card)" />
|
||||
</span>
|
||||
<span class="badges">
|
||||
<span
|
||||
v-if="card.implementation"
|
||||
class="badge"
|
||||
:class="card.implementation.status"
|
||||
>{{ card.implementation.status }}</span>
|
||||
<span v-if="card.implementation?.manual" class="badge manual">manual</span>
|
||||
</span>
|
||||
</button>
|
||||
</CardHover>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="pager">
|
||||
<button type="button" :disabled="offset === 0 || loadingList" @click="previousPage">Previous</button>
|
||||
<span class="muted">Page {{ page }} of {{ pageCount }} · {{ total.toLocaleString() }} cards</span>
|
||||
<button type="button" :disabled="offset + pageSize >= total || loadingList" @click="nextPage">Next</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="detail-panel">
|
||||
<p v-if="!selectedId" class="muted">Select a card to view or edit its implementation.</p>
|
||||
<p v-else-if="detailLoading" class="muted">Loading card…</p>
|
||||
<template v-else-if="detail">
|
||||
<div class="detail-head">
|
||||
<div>
|
||||
<h2>{{ detail.card.name }}</h2>
|
||||
<p class="muted">
|
||||
{{ detail.card.type_line }}
|
||||
<ManaCost :cost="manaCostOf(detail.card)" />
|
||||
</p>
|
||||
</div>
|
||||
<div class="badges">
|
||||
<span class="badge" :class="detail.compiled.status">{{ detail.compiled.status }}</span>
|
||||
<span v-if="detail.manual" class="badge manual">manual</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template v-if="detail.card.card_faces?.length">
|
||||
<div v-for="face in detail.card.card_faces" :key="face.name" class="oracle">
|
||||
<h3>{{ face.name }}</h3>
|
||||
<p class="muted">{{ face.type_line }}</p>
|
||||
<p><SymbolText :text="face.oracle_text" /></p>
|
||||
</div>
|
||||
</template>
|
||||
<div v-else class="oracle">
|
||||
<p><SymbolText :text="detail.card.oracle_text" /></p>
|
||||
</div>
|
||||
|
||||
<p v-if="detail.error" class="error">
|
||||
The saved implementation does not parse: {{ detail.error }}
|
||||
</p>
|
||||
<p v-else-if="editorError" class="error">{{ editorError }}</p>
|
||||
|
||||
<div class="row">
|
||||
<div class="tabs">
|
||||
<button type="button" :class="{ active: editorMode === 'text' }" @click="editorMode = 'text'">Text</button>
|
||||
<button type="button" :class="{ active: editorMode === 'visual' }" @click="editorMode = 'visual'">Visual</button>
|
||||
</div>
|
||||
<span class="muted grow">{{ editorMode === 'text' ? 'Pseudocode' : 'Node graph' }}</span>
|
||||
</div>
|
||||
|
||||
<textarea
|
||||
v-if="editorMode === 'text'"
|
||||
v-model="source"
|
||||
spellcheck="false"
|
||||
aria-label="Card implementation"
|
||||
@keydown.ctrl.s.prevent="save"
|
||||
@keydown.meta.s.prevent="save"
|
||||
/>
|
||||
<CardGraphEditor v-else :key="detail.card.oracle_id" v-model="source" />
|
||||
|
||||
<div class="actions">
|
||||
<button type="button" class="primary" :disabled="saving || !dirty" @click="save">
|
||||
{{ saving ? 'Saving…' : 'Save' }}
|
||||
</button>
|
||||
<span class="muted">{{ dirty ? 'Unsaved changes' : 'Saved' }}</span>
|
||||
<button type="button" :disabled="saving || translating" @click="translate">
|
||||
{{ translating ? 'Drafting…' : 'Draft with AI' }}
|
||||
</button>
|
||||
<button type="button" :disabled="saving || !detail.manual" @click="reset">
|
||||
Reset to generated
|
||||
</button>
|
||||
<span v-if="detail.updatedAt" class="muted saved-at">
|
||||
Updated {{ new Date(detail.updatedAt).toLocaleString() }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<PseudoGuide v-else />
|
||||
</main>
|
||||
</template>
|
||||
|
||||
1002
frontend/app/pages/decks.vue
Normal file
1002
frontend/app/pages/decks.vue
Normal file
File diff suppressed because it is too large
Load Diff
2236
frontend/app/pages/games/[id].vue
Normal file
2236
frontend/app/pages/games/[id].vue
Normal file
File diff suppressed because it is too large
Load Diff
258
frontend/app/pages/index.vue
Normal file
258
frontend/app/pages/index.vue
Normal file
@@ -0,0 +1,258 @@
|
||||
<script setup lang="ts">
|
||||
import { deckValidation, loadDecks, type SavedDeck } from '~/utils/decks'
|
||||
import { loadPlaymatChoice, type PlaymatChoice } from '~/utils/playmat'
|
||||
|
||||
interface MatchSummary {
|
||||
id: string
|
||||
hostName: string
|
||||
status: 'lobby' | 'active' | 'finished'
|
||||
playerCount: number
|
||||
maxPlayers: number
|
||||
players: string[]
|
||||
createdAt: number
|
||||
}
|
||||
|
||||
definePageMeta({ middleware: 'auth' })
|
||||
|
||||
const { public: { apiBase } } = useRuntimeConfig()
|
||||
const SESSION_PREFIX = 'commander-session-'
|
||||
|
||||
const playerName = ref('')
|
||||
const maxPlayers = ref(4)
|
||||
const decks = ref<SavedDeck[]>([])
|
||||
const selectedDeckId = ref('')
|
||||
const games = ref<MatchSummary[]>([])
|
||||
const loading = ref(false)
|
||||
const starting = ref(false)
|
||||
const error = ref('')
|
||||
let poll: ReturnType<typeof setInterval> | undefined
|
||||
|
||||
const selectedDeck = computed(() => decks.value.find(deck => deck.id === selectedDeckId.value))
|
||||
const deckErrors = computed(() => selectedDeck.value ? deckValidation(selectedDeck.value) : ['Choose a deck.'])
|
||||
const canStart = computed(() => Boolean(playerName.value.trim() && selectedDeck.value && !deckErrors.value.length))
|
||||
|
||||
const playmat = ref<PlaymatChoice>()
|
||||
|
||||
function deckPayload(deck: SavedDeck) {
|
||||
return {
|
||||
commander: deck.commander.oracleId,
|
||||
cards: deck.cards.map(card => card.oracleId),
|
||||
}
|
||||
}
|
||||
|
||||
async function loadGames() {
|
||||
try {
|
||||
const data = await $fetch<{ games: MatchSummary[] }>(`${apiBase}/games`)
|
||||
games.value = data.games
|
||||
} catch (caught) {
|
||||
error.value = errorMessage(caught)
|
||||
}
|
||||
}
|
||||
|
||||
async function createGame() {
|
||||
if (!canStart.value || !selectedDeck.value) return
|
||||
starting.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const data = await $fetch<{ matchId: string; playerId: string; token: string }>(`${apiBase}/games`, {
|
||||
method: 'POST',
|
||||
body: {
|
||||
name: playerName.value,
|
||||
maxPlayers: maxPlayers.value,
|
||||
deck: deckPayload(selectedDeck.value),
|
||||
playmat: playmat.value,
|
||||
},
|
||||
})
|
||||
enterGame(data.matchId, data)
|
||||
} catch (caught) {
|
||||
error.value = errorMessage(caught)
|
||||
} finally {
|
||||
starting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function joinGame(game: MatchSummary) {
|
||||
if (!canStart.value || !selectedDeck.value) {
|
||||
error.value = 'Choose a valid deck and enter your name first.'
|
||||
return
|
||||
}
|
||||
starting.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const data = await $fetch<{ matchId: string; playerId: string; token: string }>(
|
||||
`${apiBase}/games/${game.id}/join`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: { name: playerName.value, deck: deckPayload(selectedDeck.value), playmat: playmat.value },
|
||||
},
|
||||
)
|
||||
enterGame(data.matchId, data)
|
||||
} catch (caught) {
|
||||
error.value = errorMessage(caught)
|
||||
} finally {
|
||||
starting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function enterGame(matchId: string, data: { playerId: string; token: string }) {
|
||||
sessionStorage.setItem(`${SESSION_PREFIX}${matchId}`, JSON.stringify(data))
|
||||
void navigateTo(`/games/${matchId}`)
|
||||
}
|
||||
|
||||
function errorMessage(caught: unknown): string {
|
||||
const data = (caught as { data?: { error?: string } })?.data
|
||||
return data?.error ?? (caught instanceof Error ? caught.message : String(caught))
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
playerName.value = localStorage.getItem('commander-player-name') ?? ''
|
||||
playmat.value = await loadPlaymatChoice(apiBase)
|
||||
decks.value = (await loadDecks(apiBase)).sort((a, b) => b.updatedAt - a.updatedAt)
|
||||
selectedDeckId.value = decks.value.find(deck => !deckValidation(deck).length)?.id
|
||||
?? decks.value[0]?.id
|
||||
?? ''
|
||||
void loadGames()
|
||||
poll = setInterval(loadGames, 5000)
|
||||
})
|
||||
|
||||
watch(playerName, value => {
|
||||
if (typeof localStorage !== 'undefined') localStorage.setItem('commander-player-name', value)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (poll) clearInterval(poll)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="page">
|
||||
<header>
|
||||
<h1>Play Commander</h1>
|
||||
<p class="muted">
|
||||
Four-player free-for-all with 40 life, command zones, commander tax, and
|
||||
21 commander damage. Games live in the API process and disappear on restart.
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
|
||||
<div class="home-grid">
|
||||
<section class="panel">
|
||||
<h2>Start or join</h2>
|
||||
<label class="field">
|
||||
<span class="muted">Your name</span>
|
||||
<input v-model="playerName" maxlength="30" placeholder="Player">
|
||||
</label>
|
||||
<label class="field">
|
||||
<span class="muted">Deck</span>
|
||||
<select v-model="selectedDeckId">
|
||||
<option v-for="deck in decks" :key="deck.id" :value="deck.id">
|
||||
{{ deck.name }} ({{ deck.cards.length + 1 }})
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<p v-if="!decks.length" class="warn">
|
||||
No decks yet. <NuxtLink to="/decks">Create or import one</NuxtLink>.
|
||||
</p>
|
||||
<ul v-else-if="deckErrors.length" class="errors">
|
||||
<li v-for="message in deckErrors.slice(0, 3)" :key="message" class="warn">{{ message }}</li>
|
||||
</ul>
|
||||
<label v-else class="field">
|
||||
<span class="muted">Seats</span>
|
||||
<select v-model.number="maxPlayers">
|
||||
<option :value="2">2 players</option>
|
||||
<option :value="3">3 players</option>
|
||||
<option :value="4">4 players</option>
|
||||
</select>
|
||||
</label>
|
||||
<button type="button" class="primary" :disabled="!canStart || starting" @click="createGame">
|
||||
{{ starting ? 'Starting…' : 'Create game' }}
|
||||
</button>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<div class="row">
|
||||
<h2 class="grow">Open games</h2>
|
||||
<button type="button" class="mini" @click="loadGames">Refresh</button>
|
||||
</div>
|
||||
<p v-if="!games.length" class="muted">No games yet. Create one and send the link to your friends.</p>
|
||||
<ul class="games">
|
||||
<li v-for="game in games" :key="game.id" class="game-row">
|
||||
<div class="grow">
|
||||
<div class="row wrap">
|
||||
<strong>{{ game.hostName }}'s game</strong>
|
||||
<span class="tag">{{ game.status }}</span>
|
||||
<span class="tag">{{ game.playerCount }}/{{ game.maxPlayers }}</span>
|
||||
</div>
|
||||
<p class="muted">{{ game.players.join(', ') || 'Waiting for players' }}</p>
|
||||
</div>
|
||||
<button
|
||||
v-if="game.status === 'lobby' && game.playerCount < game.maxPlayers"
|
||||
type="button"
|
||||
:disabled="!canStart || starting"
|
||||
@click="joinGame(game)"
|
||||
>Join</button>
|
||||
<span v-else class="muted">{{ game.status === 'active' ? 'In progress' : 'Full' }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.home-grid {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(18rem, 24rem) 1fr;
|
||||
gap: 1rem;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.3rem;
|
||||
}
|
||||
|
||||
.field select,
|
||||
.field input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.errors {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.games {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.game-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
padding: 0.6rem 0;
|
||||
border-top: 1px solid var(--line);
|
||||
}
|
||||
|
||||
.game-row:first-child {
|
||||
border-top: 0;
|
||||
}
|
||||
|
||||
.mini {
|
||||
font-size: 0.75rem;
|
||||
padding: 0.2rem 0.45rem;
|
||||
}
|
||||
|
||||
@media (max-width: 800px) {
|
||||
.home-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user