game-village-politics-frontend/app/components/ui/Cost.vue

34 lines
1.1 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import type { Cost, Resources } from '~/types/game'
defineProps<{
cost: Cost
/** Projected stock; amounts the village lacks show in red. */
have?: Resources | null
/** Keep the three amounts on one line, for table cells. */
nowrap?: boolean
/** Free villagers the level needs as workers (the server's `villagers`); hidden at 0. */
villagers?: number
/** The village's free villagers (`population.idle`): the villager count turns red above it. */
idle?: number
}>()
const list = ['wood', 'clay', 'iron'] as const
</script>
<template>
<span class="inline-flex items-center gap-x-2.5 gap-y-1 text-xs tabular-nums" :class="nowrap ? 'whitespace-nowrap' : 'flex-wrap'">
<span
v-for="r in list"
:key="r"
class="inline-flex items-center gap-1"
:class="have && have[r] < cost[r] ? 'font-semibold text-blood-700' : 'text-ink-700'"
:title="$t(`resources.${r}`)"
>
<IconResource :resource="r" class="size-4" />
{{ cost[r] }}
</span>
<UiVillagers :villagers="villagers" :idle="idle" />
</span>
</template>