Skip to content

Commit 2fac8b9

Browse files
committed
simplify price action
1 parent 29d14b7 commit 2fac8b9

4 files changed

Lines changed: 50 additions & 65 deletions

File tree

src/components/round/botAction/ActionPrice.vue

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
11
<template>
2-
<ActionBox :instruction-title="t('rules.action.price.title')" :currentCard="currentCard" :managedByApp="managedByApp">
2+
<ActionBox :instruction-title="t('rules.action.price.title')" :currentCard="currentCard" :managedByApp="true">
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>
7+
<div class="mt-2 mb-1" v-html="t('rules.action.price.priceIncreased', flowers.length)"></div>
8+
<FlowerIcon v-for="flower in flowers" :key="flower" :flower="flower"/>
249
</template>
2510
<template #instruction>
2611
<p v-html="t('rules.action.price.definedWindowInstruction')"/>
@@ -37,8 +22,6 @@ import Card from '@/services/Card'
3722
import { BotAction } from '@/services/BotActions'
3823
import ActionBox from '../ActionBox.vue'
3924
import AppIcon from '@/components/structure/AppIcon.vue'
40-
import FlowerSelection from '@/components/structure/FlowerSelection.vue'
41-
import PriceSelection from '@/services/enum/PriceSelection'
4225
import FlowerIcon from '@/components/structure/FlowerIcon.vue'
4326
import WindowSelection from '@/services/enum/WindowSelection'
4427
@@ -48,21 +31,17 @@ export default defineComponent({
4831
components: {
4932
ActionBox,
5033
AppIcon,
51-
FlowerSelection,
5234
FlowerIcon
5335
},
5436
emits: ['ready'],
5537
setup(props) {
5638
const { t } = useI18n()
5739
58-
// window already defined?
5940
const floor = props.action.floor ?? 1
6041
const windowSelection = props.action.windowSelection ?? WindowSelection.LEFT
61-
const windowState = props.navigationState.botPersistence.windowStates.getWindowState(floor, windowSelection)
62-
const selectedFlowers = ref(windowState?.flowers ?? [])
63-
const managedByApp = (windowState != undefined)
42+
const flowers = props.action.flowers ?? []
6443
65-
return { t, floor, windowSelection, selectedFlowers, managedByApp }
44+
return { t, floor, windowSelection, flowers }
6645
},
6746
props: {
6847
action: {
@@ -91,32 +70,8 @@ export default defineComponent({
9170
return this.floor
9271
}
9372
},
94-
methods: {
95-
windowIsDefined() : void {
96-
this.navigationState.botPersistence.windowStates.setWindowState(this.floor, this.windowSelection, this.selectedFlowers, [])
97-
this.doIncreasePrices()
98-
},
99-
windowIsUndefined() : void {
100-
if (this.action.priceSelection == PriceSelection.MOST_EXPENSIVE) {
101-
this.selectedFlowers = [this.navigationState.marketPrices.getMostExpensiveFlower()]
102-
}
103-
else {
104-
this.selectedFlowers = [this.navigationState.marketPrices.getCheapestFlower()]
105-
}
106-
this.doIncreasePrices()
107-
},
108-
doIncreasePrices() : void {
109-
for (const flower of this.selectedFlowers) {
110-
this.navigationState.marketPrices.increase(flower)
111-
}
112-
this.done = true
113-
this.$emit('ready')
114-
}
115-
},
11673
mounted() {
117-
if (this.managedByApp) {
118-
this.$emit('ready')
119-
}
74+
this.$emit('ready')
12075
}
12176
})
12277
</script>

src/locales/en.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@
127127
},
128128
"price": {
129129
"title": "Price",
130-
"selectFlowers": "Select the flowers defined for this window:",
131-
"or": "or",
132-
"windowDefined": "Done",
133-
"windowUndefined": "Window is undefined",
134130
"priceIncreased": "Price increased for flower: | Price increased for flowers:",
135131
"definedWindowInstruction": "If the given window is defined, the price for <i>each flower</i> in that box is increased.",
136132
"undefinedWindowInstruction": {

src/services/BotActions.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import Action from './enum/Action'
77
import Season from './enum/Season'
88
import NavigationState from '@/util/NavigationState'
99
import WindowStates from './WindowStates'
10+
import WindowSelection from './enum/WindowSelection'
11+
import PriceSelection from './enum/PriceSelection'
1012

1113
/**
1214
* Collects the bot's actions and manages the automatic actions.
@@ -88,14 +90,19 @@ export default class BotActions {
8890
break
8991

9092
case Action.PRICE:
91-
// if windows is already defined: increase price of flowers in that window by 1, otherwise wait for user input
92-
if (action.floor && action.windowSelection) {
93-
const windowState = this._windowStates.getWindowState(action.floor, action.windowSelection)
94-
if (windowState) {
95-
for (const flower of windowState.flowers) {
96-
this._marketPrices.increase(flower)
97-
}
98-
}
93+
// if windows is already defined: increase price of flowers in that window by 1, otherwise increase 1 least/most expensive flower
94+
const windowState = this._windowStates.getWindowState(action.floor ?? 1, action.windowSelection ?? WindowSelection.LEFT)
95+
if (windowState) {
96+
botAction.flowers = windowState.flowers
97+
}
98+
else if (action.priceSelection == PriceSelection.MOST_EXPENSIVE) {
99+
botAction.flowers = [this._marketPrices.getMostExpensiveFlower()]
100+
}
101+
else {
102+
botAction.flowers = [this._marketPrices.getCheapestFlower()]
103+
}
104+
for (const flower of botAction.flowers) {
105+
this._marketPrices.increase(flower)
99106
}
100107
break
101108
}
@@ -126,5 +133,6 @@ export default class BotActions {
126133

127134
export interface BotAction extends CardAction {
128135
flower?: Flower
136+
flowers?: Flower[]
129137
vp?: number
130138
}

tests/unit/services/BotActions.spec.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,36 @@ describe('services/BotActions', () => {
158158
expect(navigationState.marketPrices.getPrice(Flower.BLUE)).to.eq(4)
159159
})
160160

161-
it('window not yet defined - no price changes', () => {
161+
it('window not yet defined - falls back to most expensive flower', () => {
162162
const cardDeck = mockCardDeck({ pile: ['price-1'] })
163163
cardDeck.draw()
164164
const windowStates = WindowStates.new()
165165
const navigationState = mockNavigationState({
166166
marketPrices: [
167-
{ flower: Flower.RED, price: 4 },
167+
{ flower: Flower.RED, price: 3 },
168+
{ flower: Flower.BLUE, price: 6 },
169+
],
170+
windowStates,
171+
cardDeck
172+
})
173+
174+
const botActions = new BotActions(navigationState)
175+
176+
expect(botActions.actions[0].action).to.eq(Action.PRICE)
177+
expect(botActions.actions[0].flowers).to.eql([Flower.BLUE])
178+
// BLUE was most expensive, increased from 6 to 7
179+
expect(navigationState.marketPrices.getPrice(Flower.BLUE)).to.eq(7)
180+
expect(navigationState.marketPrices.getPrice(Flower.RED)).to.eq(3)
181+
})
182+
183+
it('window not yet defined - falls back to cheapest flower', () => {
184+
const cardDeck = mockCardDeck({ pile: ['price-2'] })
185+
cardDeck.draw()
186+
const windowStates = WindowStates.new()
187+
const navigationState = mockNavigationState({
188+
marketPrices: [
189+
{ flower: Flower.RED, price: 3 },
190+
{ flower: Flower.BLUE, price: 6 },
168191
],
169192
windowStates,
170193
cardDeck
@@ -173,7 +196,10 @@ describe('services/BotActions', () => {
173196
const botActions = new BotActions(navigationState)
174197

175198
expect(botActions.actions[0].action).to.eq(Action.PRICE)
199+
expect(botActions.actions[0].flowers).to.eql([Flower.RED])
200+
// RED was cheapest, increased from 3 to 4
176201
expect(navigationState.marketPrices.getPrice(Flower.RED)).to.eq(4)
202+
expect(navigationState.marketPrices.getPrice(Flower.BLUE)).to.eq(6)
177203
})
178204
})
179205

0 commit comments

Comments
 (0)