Skip to content

Commit 95b59c6

Browse files
committed
simplify code
1 parent f9da71d commit 95b59c6

1 file changed

Lines changed: 16 additions & 22 deletions

File tree

src/components/round/TechCardDraft.vue

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@
3434
</button>
3535

3636
<div class="draftedCards">
37-
<div v-if="playerTechs.length > 0" class="mt-3">
38-
<TechCardsPlayerDraft :navigationState="navigationState" :playerTechs="playerTechs"/>
37+
<div v-if="techDraftStep.playerTechs.length > 0" class="mt-3">
38+
<TechCardsPlayerDraft :navigationState="navigationState" :playerTechs="techDraftStep.playerTechs"/>
3939
</div>
4040

41-
<div v-if="botTechs.length > 0" class="mt-3">
41+
<div v-if="techDraftStep.botTechs.length > 0" class="mt-3">
4242
<h5>{{t('phaseADrafting.botDraft')}}</h5>
4343
<div class="techs">
4444
<div class="techRow">
45-
<TechCard v-for="tech of botTechs" :key="tech" :navigationState="navigationState" :tech="tech" class="techCard disabled"/>
45+
<TechCard v-for="tech of techDraftStep.botTechs" :key="tech" :navigationState="navigationState" :tech="tech" class="techCard disabled"/>
4646
</div>
4747
</div>
4848
</div>
@@ -79,20 +79,17 @@ export default defineComponent({
7979
8080
const roundData = state.rounds.find(item => item.round == props.navigationState.round)!
8181
const lastTechDraftStep = props.navigationState.lastDraftStep
82-
const botTechs = ref(cloneDeep(lastTechDraftStep?.botTechs ?? []))
83-
const playerTechs = ref(cloneDeep(lastTechDraftStep?.playerTechs ?? []))
84-
const playerSpecialActions = ref(lastTechDraftStep?.playerSpecialActions ?? 0)
8582
const techDraftStep = ref({
8683
round: props.navigationState.round,
8784
step: props.navigationState.draftingStep,
8885
nextStartPlayer: lastTechDraftStep?.nextStartPlayer,
8986
nextArchitectPlayer: lastTechDraftStep?.nextArchitectPlayer,
90-
botTechs: botTechs.value,
91-
playerTechs: playerTechs.value,
87+
botTechs: cloneDeep(lastTechDraftStep?.botTechs ?? []),
88+
playerTechs: cloneDeep(lastTechDraftStep?.playerTechs ?? []),
9289
playerSpecialActions: lastTechDraftStep?.playerSpecialActions ?? 0
9390
} as TechDraftStep)
9491
95-
return { t, state, router, roundData, techDraftStep, botTechs, playerTechs, playerSpecialActions }
92+
return { t, state, router, roundData, techDraftStep }
9693
},
9794
props: {
9895
navigationState: {
@@ -115,22 +112,22 @@ export default defineComponent({
115112
return this.navigationState.techCardSelection
116113
},
117114
botMarkerPlaced() : number {
118-
return this.botTechs.length
115+
return this.techDraftStep.botTechs.length
119116
},
120117
playerMarkerPlaced() : number {
121-
return this.playerTechs.length + this.playerSpecialActions
118+
return this.techDraftStep.playerTechs.length + this.techDraftStep.playerSpecialActions
122119
},
123120
draftingCompleted() : boolean {
124121
return this.botMarkerPlaced == 4 && this.playerMarkerPlaced == 4
125122
},
126123
playerIncomeTotal() : number {
127-
return this.playerTechs.map(tech => this.techCardSelection.getIncome(tech)).filter(value => value < 5).reduce((a,b) => a+b, 0)
124+
return this.techDraftStep.playerTechs.map(tech => this.techCardSelection.getIncome(tech)).filter(value => value < 5).reduce((a,b) => a+b, 0)
128125
},
129126
playerIncomeLockedTotal() : number {
130-
return this.playerTechs.map(tech => this.techCardSelection.getIncome(tech)).filter(value => value == 5).reduce((a,b) => a+b, 0)
127+
return this.techDraftStep.playerTechs.map(tech => this.techCardSelection.getIncome(tech)).filter(value => value == 5).reduce((a,b) => a+b, 0)
131128
},
132129
botRound8Army() : boolean {
133-
return this.navigationState.round == 8 && this.botTechs.includes(Tech.ARMY)
130+
return this.navigationState.round == 8 && this.techDraftStep.botTechs.includes(Tech.ARMY)
134131
}
135132
},
136133
methods: {
@@ -170,7 +167,7 @@ export default defineComponent({
170167
const draftingRowCard = botCards.draftingRow.draw()
171168
const draftingPriorityCard = botCards.draftingPriority.draw()
172169
const tech = techCardSelection.determineTech(draftingRowCard, draftingPriorityCard, prosperityCards.current.flat())
173-
this.botTechs.push(tech)
170+
this.techDraftStep.botTechs.push(tech)
174171
if (tech == Tech.ARMY) {
175172
this.techDraftStep.nextStartPlayer = Player.BOT
176173
}
@@ -191,8 +188,8 @@ export default defineComponent({
191188
return
192189
}
193190
this.playerTurn = false
194-
this.playerTechs.push(t)
195-
this.techDraftStep.playerTechs = this.playerTechs
191+
this.techDraftStep.playerTechs.push(t)
192+
this.techDraftStep.playerTechs = this.techDraftStep.playerTechs
196193
if (t == Tech.ARMY) {
197194
this.techDraftStep.nextStartPlayer = Player.PLAYER
198195
}
@@ -207,7 +204,7 @@ export default defineComponent({
207204
this.router.push(this.nextButtonRouteTo)
208205
}
209206
else {
210-
this.playerSpecialActions++
207+
this.techDraftStep.playerSpecialActions++
211208
this.playerTurn = false
212209
await this.playerTurnCompleted()
213210
}
@@ -221,9 +218,6 @@ export default defineComponent({
221218
},
222219
persistAndNextStep() : void {
223220
this.techDraftStep.techCardSelection = this.techCardSelection.toPersistence()
224-
this.techDraftStep.botTechs = this.botTechs
225-
this.techDraftStep.playerTechs = this.playerTechs
226-
this.techDraftStep.playerSpecialActions = this.playerSpecialActions
227221
this.state.storeTechDraftStep(this.techDraftStep)
228222
this.router.push(`/round/${this.navigationState.round}/drafting/${this.techDraftStep.step+1}`)
229223
}

0 commit comments

Comments
 (0)