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

60 lines
3.1 KiB
Vue
Raw Permalink Normal View History

<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)))),
)
/** Coins pay for another village: noblemen at loyalty 0 take one. */
const room = computed(() => props.conquest.slots > props.conquest.used)
</script>
<!-- Minting coins at the academy: coins pay for every village beyond the first; noblemen take no slot. -->
<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.badge', { 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.held') }}</td>
<td class="text-right tabular-nums">{{ conquest.used }}</td>
</tr>
<tr>
<td class="whitespace-nowrap">{{ $t('village.conquest.paid') }}</td>
<td class="text-right tabular-nums">{{ conquest.slots }}</td>
</tr>
<tr>
<td class="whitespace-nowrap">{{ $t('village.conquest.next_village') }}</td>
<td class="text-right whitespace-nowrap tabular-nums">{{ $t('village.conquest.coins_total', { count: conquest.next_slot_coins }) }}</td>
</tr>
</tbody>
</table>
<p v-if="room" class="text-xs font-semibold text-moss-700">{{ $t('village.conquest.room') }}</p>
<p v-else class="border border-gold-600 bg-gold-400 px-2 py-0.5 text-xs text-ink-900">{{ $t('village.conquest.full') }}</p>
<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>