42 lines
1.8 KiB
Vue
42 lines
1.8 KiB
Vue
|
|
<script setup lang="ts">
|
||
|
|
import type { MapMovement } from '~/types/map'
|
||
|
|
|
||
|
|
const props = defineProps<{
|
||
|
|
/** The village whose groups to list: those leaving it and those coming to it. */
|
||
|
|
villageId: number
|
||
|
|
movements: MapMovement[]
|
||
|
|
now: number
|
||
|
|
}>()
|
||
|
|
const emit = defineEmits<{ march: [id: number] }>()
|
||
|
|
const { t } = useI18n()
|
||
|
|
|
||
|
|
/** Groups under way to or from the village, soonest first; arrived ones are gone. */
|
||
|
|
const marches = computed(() =>
|
||
|
|
props.movements
|
||
|
|
.filter((m) => (m.from.id === props.villageId || m.to.id === props.villageId) && Date.parse(m.arrives_at) > props.now)
|
||
|
|
.sort((a, b) => Date.parse(a.arrives_at) - Date.parse(b.arrives_at)),
|
||
|
|
)
|
||
|
|
const label = (m: MapMovement) => {
|
||
|
|
const out = m.from.id === props.villageId
|
||
|
|
const other = out ? m.to : m.from
|
||
|
|
return `${t(`map.march.legend.${m.raid ? 'raid' : m.type}`)} ${t(out ? 'map.march.out' : 'map.march.in', { village: `${other.name} (${other.x}|${other.y})` })}`
|
||
|
|
}
|
||
|
|
const left = (m: MapMovement) => formatDuration(Math.max(0, Math.ceil((Date.parse(m.arrives_at) - props.now) / 1000)))
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<!-- Groups leaving or coming to a village on the map; a click opens the group's card. -->
|
||
|
|
<template>
|
||
|
|
<div v-if="marches.length">
|
||
|
|
<p class="mb-1 text-xs font-semibold tracking-wide text-ink-500 uppercase">{{ $t('map.march.under_way') }}</p>
|
||
|
|
<ul class="space-y-0.5">
|
||
|
|
<li v-for="m in marches" :key="m.id">
|
||
|
|
<button type="button" class="flex w-full items-center gap-2 text-left hover:underline" @click="emit('march', m.id)">
|
||
|
|
<span class="inline-block h-1 w-3 shrink-0" :style="{ background: m.raid ? MARCH_COLOURS.raid : MARCH_COLOURS[m.type] }" />
|
||
|
|
<span class="min-w-0 flex-1 truncate">{{ label(m) }}</span>
|
||
|
|
<span class="font-semibold tabular-nums">{{ left(m) }}</span>
|
||
|
|
</button>
|
||
|
|
</li>
|
||
|
|
</ul>
|
||
|
|
</div>
|
||
|
|
</template>
|