|
| 1 | +<template> |
| 2 | + <div class="mt-4"> |
| 3 | + <div v-for="floor in floors" :key="floor.number" class="floor mb-3"> |
| 4 | + <h5>{{t('playerMakeDelivery.floor', {floor: floor.number})}}</h5> |
| 5 | + <div class="d-flex flex-wrap gap-3"> |
| 6 | + <div v-for="window in floor.windows" :key="window.selection" class="window-box border rounded p-2"> |
| 7 | + <div v-if="floor.windows.length > 1" class="fw-bold small mb-1">{{window.label}}</div> |
| 8 | + <div v-if="getDisplayFlowers(window.selection, floor.number).length > 0" |
| 9 | + class="d-flex flex-wrap gap-1 align-items-center"> |
| 10 | + <FlowerIcon v-for="(flower, i) in getDisplayFlowers(window.selection, floor.number)" |
| 11 | + :key="'f'+i" :flower="flower"/> |
| 12 | + </div> |
| 13 | + <div v-if="getDisplayDeliveries(window.selection).length > 0" |
| 14 | + class="d-flex flex-wrap gap-1 align-items-center mt-1"> |
| 15 | + <PlayerColorIcon v-for="(player, i) in getDisplayDeliveries(window.selection)" |
| 16 | + :key="'d'+i" :player="player"/> |
| 17 | + </div> |
| 18 | + <div v-if="canDeliver(window.selection)" class="mt-2"> |
| 19 | + <template v-if="selectingWindow === window.selection"> |
| 20 | + <p class="small mb-1" v-html="t('playerMakeDelivery.selectFlowers', {count: floor.number})"/> |
| 21 | + <FlowerSelection v-model="selectedFlowers" :marketPrices="marketPrices" :max="floor.number"/> |
| 22 | + <button v-if="selectedFlowers.length === floor.number" |
| 23 | + class="btn btn-success btn-sm mt-2" @click="confirmDelivery(window.selection, floor.number)"> |
| 24 | + {{t('playerMakeDelivery.confirm')}} |
| 25 | + </button> |
| 26 | + </template> |
| 27 | + <button v-else class="btn btn-outline-primary btn-sm" @click="deliverHere(window.selection, floor.number)"> |
| 28 | + {{t('playerMakeDelivery.deliverHere')}} |
| 29 | + </button> |
| 30 | + </div> |
| 31 | + </div> |
| 32 | + </div> |
| 33 | + </div> |
| 34 | + </div> |
| 35 | +</template> |
| 36 | + |
| 37 | +<script lang="ts"> |
| 38 | +import { defineComponent, type PropType, ref } from 'vue' |
| 39 | +import { useI18n } from 'vue-i18n' |
| 40 | +import WindowStates from '@/services/WindowStates' |
| 41 | +import WindowSelection from '@/services/enum/WindowSelection' |
| 42 | +import Flower from '@/services/enum/Flower' |
| 43 | +import Player from '@/services/enum/Player' |
| 44 | +import MarketPrices from '@/services/MarketPrices' |
| 45 | +import FlowerIcon from '@/components/structure/FlowerIcon.vue' |
| 46 | +import PlayerColorIcon from '@/components/structure/PlayerColorIcon.vue' |
| 47 | +import FlowerSelection from '@/components/structure/FlowerSelection.vue' |
| 48 | +import getAllEnumValues from '@brdgm/brdgm-commons/src/util/enum/getAllEnumValues' |
| 49 | +
|
| 50 | +interface FloorInfo { |
| 51 | + number: number |
| 52 | + windows: { selection: WindowSelection, label: string }[] |
| 53 | +} |
| 54 | +
|
| 55 | +export default defineComponent({ |
| 56 | + name: 'PlayerMakeDelivery', |
| 57 | + components: { |
| 58 | + FlowerIcon, |
| 59 | + PlayerColorIcon, |
| 60 | + FlowerSelection |
| 61 | + }, |
| 62 | + emits: ['deliver'], |
| 63 | + props: { |
| 64 | + windowStates: { |
| 65 | + type: Object as PropType<WindowStates>, |
| 66 | + required: true |
| 67 | + }, |
| 68 | + marketPrices: { |
| 69 | + type: Object as PropType<MarketPrices>, |
| 70 | + required: true |
| 71 | + } |
| 72 | + }, |
| 73 | + setup() { |
| 74 | + const { t } = useI18n() |
| 75 | + const selectingWindow = ref<WindowSelection|null>(null) |
| 76 | + const selectedFlowers = ref<Flower[]>([]) |
| 77 | + return { t, selectingWindow, selectedFlowers } |
| 78 | + }, |
| 79 | + computed: { |
| 80 | + floors() : FloorInfo[] { |
| 81 | + return [ |
| 82 | + { number: 5, windows: [ |
| 83 | + { selection: WindowSelection.WINDOW_5, label: '' } |
| 84 | + ]}, |
| 85 | + { number: 4, windows: [ |
| 86 | + { selection: WindowSelection.WINDOW_4L, label: this.t('playerMakeDelivery.windowLeft') }, |
| 87 | + { selection: WindowSelection.WINDOW_4R, label: this.t('playerMakeDelivery.windowRight') } |
| 88 | + ]}, |
| 89 | + { number: 3, windows: [ |
| 90 | + { selection: WindowSelection.WINDOW_3L, label: this.t('playerMakeDelivery.windowLeft') }, |
| 91 | + { selection: WindowSelection.WINDOW_3R, label: this.t('playerMakeDelivery.windowRight') } |
| 92 | + ]}, |
| 93 | + { number: 2, windows: [ |
| 94 | + { selection: WindowSelection.WINDOW_2L, label: this.t('playerMakeDelivery.windowLeft') }, |
| 95 | + { selection: WindowSelection.WINDOW_2R, label: this.t('playerMakeDelivery.windowRight') } |
| 96 | + ]}, |
| 97 | + { number: 1, windows: [ |
| 98 | + { selection: WindowSelection.WINDOW_1L, label: this.t('playerMakeDelivery.windowLeft') }, |
| 99 | + { selection: WindowSelection.WINDOW_1R, label: this.t('playerMakeDelivery.windowRight') } |
| 100 | + ]} |
| 101 | + ] |
| 102 | + } |
| 103 | + }, |
| 104 | + methods: { |
| 105 | + getDisplayFlowers(windowSelection: WindowSelection, floorNumber: number) : Flower[] { |
| 106 | + const state = this.windowStates.getWindowState(windowSelection) |
| 107 | + if (state) return state.flowers |
| 108 | + if (floorNumber === 5) return getAllEnumValues(Flower) |
| 109 | + return [] |
| 110 | + }, |
| 111 | + getDisplayDeliveries(windowSelection: WindowSelection) : Player[] { |
| 112 | + const state = this.windowStates.getWindowState(windowSelection) |
| 113 | + return state?.deliveries ?? [] |
| 114 | + }, |
| 115 | + canDeliver(windowSelection: WindowSelection) : boolean { |
| 116 | + const state = this.windowStates.getWindowState(windowSelection) |
| 117 | + if (!state) return true |
| 118 | + return state.deliveries.length < 4 |
| 119 | + }, |
| 120 | + deliverHere(windowSelection: WindowSelection, floorNumber: number) : void { |
| 121 | + const state = this.windowStates.getWindowState(windowSelection) |
| 122 | + if (state) { |
| 123 | + this.windowStates.addDelivery(windowSelection, Player.PLAYER) |
| 124 | + this.$emit('deliver', floorNumber) |
| 125 | + } |
| 126 | + else if (floorNumber === 5) { |
| 127 | + this.windowStates.setWindowState(windowSelection, getAllEnumValues(Flower), [Player.PLAYER]) |
| 128 | + this.$emit('deliver', floorNumber) |
| 129 | + } |
| 130 | + else { |
| 131 | + this.selectingWindow = windowSelection |
| 132 | + this.selectedFlowers = [] |
| 133 | + } |
| 134 | + }, |
| 135 | + confirmDelivery(windowSelection: WindowSelection, floorNumber: number) : void { |
| 136 | + this.windowStates.setWindowState(windowSelection, [...this.selectedFlowers], [Player.PLAYER]) |
| 137 | + this.selectingWindow = null |
| 138 | + this.$emit('deliver', floorNumber) |
| 139 | + } |
| 140 | + } |
| 141 | +}) |
| 142 | +</script> |
| 143 | + |
| 144 | +<style lang="scss" scoped> |
| 145 | +.window-box { |
| 146 | + min-width: 8rem; |
| 147 | +} |
| 148 | +</style> |
0 commit comments