game-village-politics-frontend/app/components/village/CoinPanel.vue

48 lines
2.4 KiB
Vue

<script setup lang="ts">
import type { Conquest, Resources } from '~/types/game'
const props = defineProps<{ conquest: Conquest; resources: Resources; busy: boolean }>()
const emit = defineEmits<{ mint: [count: number] }>()
const count = ref(1)
/** How many coins the stock pays for now. */
const affordable = computed(() =>
Math.floor(Math.min(...(['wood', 'clay', 'iron'] as const).map((r) => (props.conquest.coin_cost[r] ? props.resources[r] / props.conquest.coin_cost[r] : Infinity)))),
)
</script>
<!-- Minting coins at the academy: coins pay for noble slots, the n-th slot n more coins. -->
<template>
<section class="panel">
<div class="panel-head">
<span class="panel-title">{{ $t('village.conquest.title') }}</span>
<span class="badge badge-plain tabular-nums">{{ $t('village.conquest.slots', { used: conquest.used, slots: conquest.slots }) }}</span>
</div>
<div class="panel-body space-y-2 text-sm">
<p class="text-ink-700">{{ $t('village.conquest.about') }}</p>
<table class="grid-table">
<tbody>
<tr>
<td class="whitespace-nowrap">{{ $t('village.conquest.coins') }}</td>
<td class="text-right font-semibold tabular-nums">{{ conquest.coins }}</td>
</tr>
<tr>
<td class="whitespace-nowrap">{{ $t('village.conquest.next_slot') }}</td>
<td class="text-right tabular-nums">{{ $t('village.conquest.coins_more', { count: conquest.next_slot_coins }) }}</td>
</tr>
</tbody>
</table>
<p class="flex flex-wrap items-center justify-between gap-x-2 gap-y-1">
<span>{{ $t('village.conquest.coin_cost') }}</span>
<UiCost :cost="conquest.coin_cost" :have="resources" />
</p>
<form class="flex items-center justify-end gap-1.5" @submit.prevent="emit('mint', count)">
<input v-model.number="count" type="number" min="1" :max="Math.max(1, affordable)" class="input w-16 text-right" :aria-label="$t('village.conquest.count')" />
<span class="text-xs text-ink-500 tabular-nums">({{ affordable }})</span>
<button type="submit" class="btn btn-primary" :disabled="busy || count < 1 || count > affordable">{{ $t('village.conquest.mint') }}</button>
</form>
<p v-if="conquest.max_distance" class="text-xs text-ink-500">{{ $t('village.conquest.range', { fields: conquest.max_distance }) }}</p>
</div>
</section>
</template>