11<template >
2- <ActionBox :instruction-title =" t (' rules.action.price.title' )" :currentCard =" currentCard " >
2+ <ActionBox :instruction-title =" t (' rules.action.price.title' )" :currentCard =" currentCard " : managedByApp = " managedByApp " >
33 <template #action >
44 <div class =" action" >
55 <AppIcon type="action" :name =" iconName " class="icon"/>
66 </div >
7+ <div class =" mt-3" v-if =" managedByApp || done" >
8+ <div class =" mb-2" v-html =" t('rules.action.price.priceIncreased', selectedFlowers.length)" ></div >
9+ <FlowerIcon v-for =" flower in selectedFlowers " :key =" flower " :flower =" flower " />
10+ </div >
11+ <div v-else class =" mt-3" @click.stop >
12+ <p v-html =" t('rules.action.price.selectFlowers')" ></p >
13+ <FlowerSelection v-model =" selectedFlowers " :marketPrices =" navigationState .marketPrices " :max =" flowerCount " />
14+ <div v-if =" selectedFlowers.length == flowerCount" class =" mt-2" >
15+ <button class =" btn btn-secondary" @click =" windowIsDefined()" >{{t('rules.action.price.windowDefined')}}</button >
16+ </div >
17+ <div v-if =" selectedFlowers.length == 0" >
18+ <div >{{t('rules.action.price.or')}}</div >
19+ <div class =" mt-1" >
20+ <button class =" btn btn-secondary" @click =" windowIsUndefined()" >{{t('rules.action.price.windowUndefined')}}</button >
21+ </div >
22+ </div >
23+ </div >
724 </template >
825 <template #instruction >
9- <p v-html =" t('rules.action.price.instruction')" />
26+ <p v-html =" t('rules.action.price.definedWindowInstruction')" />
27+ <p v-html =" t(`rules.action.price.undefinedWindowInstruction.${action.priceSelection}`)" />
1028 </template >
1129 </ActionBox >
1230</template >
1331
1432<script lang="ts">
15- import { defineComponent , PropType } from ' vue'
33+ import { defineComponent , PropType , ref } from ' vue'
1634import { useI18n } from ' vue-i18n'
1735import NavigationState from ' @/util/NavigationState'
1836import Card from ' @/services/Card'
1937import { BotAction } from ' @/services/BotActions'
2038import ActionBox from ' ../ActionBox.vue'
2139import AppIcon from ' @/components/structure/AppIcon.vue'
40+ import FlowerSelection from ' @/components/structure/FlowerSelection.vue'
41+ import getWindowSelectionFloorCount from ' @/util/getWindowSelectionFloorCount'
42+ import PriceSelection from ' @/services/enum/PriceSelection'
43+ import FlowerIcon from ' @/components/structure/FlowerIcon.vue'
2244
2345export default defineComponent ({
2446 name: ' ActionPrice' ,
2547 inheritAttrs: false ,
2648 components: {
2749 ActionBox ,
28- AppIcon
50+ AppIcon ,
51+ FlowerSelection ,
52+ FlowerIcon
2953 },
3054 emits: {
31- ready : () => true
55+ ready : (_ready : boolean ) => true
3256 },
33- setup() {
57+ setup(props ) {
3458 const { t } = useI18n ()
35- return { t }
59+
60+ // window already defined?
61+ const definedFlowers = props .action .windowSelection ? props .navigationState .botPersistence .definedWindows .getDefinedWindow (props .action .windowSelection ) : undefined
62+ const selectedFlowers = ref (definedFlowers ?? [])
63+ const managedByApp = (definedFlowers != undefined )
64+
65+ return { t , selectedFlowers , managedByApp }
3666 },
3767 props: {
3868 action: {
@@ -48,13 +78,47 @@ export default defineComponent({
4878 required: false
4979 }
5080 },
81+ data() {
82+ return {
83+ done: false
84+ }
85+ },
5186 computed: {
5287 iconName(): string {
5388 return ` price-${this .action .windowSelection ?.toLocaleLowerCase ()} `
89+ },
90+ flowerCount() : number {
91+ return this .action .windowSelection ? getWindowSelectionFloorCount (this .action .windowSelection ) : 0
92+ }
93+ },
94+ methods: {
95+ windowIsDefined() : void {
96+ if (this .action .windowSelection ) {
97+ this .navigationState .botPersistence .definedWindows .setDefinedWindow (this .action .windowSelection , this .selectedFlowers )
98+ }
99+ this .doIncreasePrices ()
100+ },
101+ windowIsUndefined() : void {
102+ if (this .action .priceSelection == PriceSelection .MOST_EXPENSIVE ) {
103+ this .selectedFlowers = [this .navigationState .marketPrices .getMostExpensiveFlower ()]
104+ }
105+ else {
106+ this .selectedFlowers = [this .navigationState .marketPrices .getCheapestFlower ()]
107+ }
108+ this .doIncreasePrices ()
109+ },
110+ doIncreasePrices() : void {
111+ for (const flower of this .selectedFlowers ) {
112+ this .navigationState .marketPrices .increase (flower )
113+ }
114+ this .done = true
115+ this .$emit (' ready' , true )
54116 }
55117 },
56118 mounted() {
57- this .$emit (' ready' )
119+ if (this .managedByApp ) {
120+ this .$emit (' ready' , true )
121+ }
58122 }
59123})
60124 </script >
0 commit comments