Skip to content

Commit 42c77fc

Browse files
committed
Support Back Button in Tech Draft phase (instead of Reset button)
1 parent 05c7dca commit 42c77fc

5 files changed

Lines changed: 49 additions & 4 deletions

File tree

src/router/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ const routes: Array<RouteRecordRaw> = [
3838
name: 'PhaseADrafting',
3939
component: PhaseADrafting
4040
},
41+
{
42+
path: '/round/:round/drafting/:step',
43+
name: 'PhaseADraftingStep',
44+
component: PhaseADrafting
45+
},
4146
{
4247
path: '/round/:round/prosperity',
4348
name: 'PhaseBProsperity',

src/store/state.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ export interface Round {
5252
botCards: BotCardsPersistence
5353
rowPlaceholders: RowPlaceholdersPersistence
5454
techCardSelection: TechCardSelectionPersistence
55+
techDraftSteps?: TechDraftStep[]
56+
// the following fields are deprecated, latest implementation uses the techDraftSteps field instead
57+
nextStartPlayer?: Player
58+
nextArchitectPlayer?: Player
59+
botTechs?: Tech[]
60+
playerTechs?: Tech[]
61+
playerSpecialActions?: number
62+
}
63+
64+
export interface TechDraftStep {
65+
step: number
66+
player: Player
5567
nextStartPlayer?: Player
5668
nextArchitectPlayer?: Player
5769
botTechs?: Tech[]

src/util/NavigationState.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Round, State } from '@/store/state'
1+
import { Round, State, TechDraftStep } from '@/store/state'
22
import { RouteLocation } from 'vue-router'
33
import getIntRouteParam from '@brdgm/brdgm-commons/src/util/router/getIntRouteParam'
44
import Player from '@/services/enum/Player'
@@ -10,6 +10,7 @@ import TechCardSelection from '@/services/TechCardSelection'
1010
export default class NavigationState {
1111

1212
readonly round : number
13+
readonly draftingStep: number
1314
readonly prosperityCards : ProsperityCards
1415
readonly botCards : BotCards
1516
readonly rowPlaceholders : RowPlaceholders
@@ -19,6 +20,7 @@ export default class NavigationState {
1920

2021
constructor(route: RouteLocation, state: State) {
2122
this.round = getIntRouteParam(route, 'round')
23+
this.draftingStep = getIntRouteParam(route, 'step')
2224

2325
let roundData = state.rounds.find(item => item.round === this.round)
2426
if (!roundData) {
@@ -42,11 +44,17 @@ export default class NavigationState {
4244
}
4345

4446
public get startPlayer() : Player {
45-
return this.roundData.nextStartPlayer ?? this.roundData.startPlayer
47+
return this.lastDraftStep?.nextStartPlayer ?? this.roundData.nextStartPlayer ?? this.roundData.startPlayer
4648
}
4749

4850
public get architectPlayer() : Player {
49-
return this.roundData.nextArchitectPlayer ?? this.roundData.architectPlayer
51+
return this.lastDraftStep?.nextArchitectPlayer ?? this.roundData.nextArchitectPlayer ?? this.roundData.architectPlayer
52+
}
53+
54+
private get lastDraftStep() : TechDraftStep|undefined {
55+
if (this.roundData.techDraftSteps) {
56+
return this.roundData.techDraftSteps.toSorted((a, b) => a.step - b.step)[this.roundData.techDraftSteps.length - 1]
57+
}
5058
}
5159

5260
}

tests/unit/helper/mockRound.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Player from '@/services/enum/Player'
2-
import { BotCardsPersistence, ProsperityCardsPersistence, Round, RowPlaceholdersPersistence, TechCardSelectionPersistence } from '@/store/state'
2+
import { BotCardsPersistence, ProsperityCardsPersistence, Round, RowPlaceholdersPersistence, TechCardSelectionPersistence, TechDraftStep } from '@/store/state'
33

44
export default function mockRound(params?: MockRoundParams) : Round {
55
const round : Round = {
@@ -15,6 +15,7 @@ export default function mockRound(params?: MockRoundParams) : Round {
1515
},
1616
rowPlaceholders: params?.rowPlaceholders ?? { rows: [] },
1717
techCardSelection: params?.techCardSelection ?? { techs: [], removedTechs: [] },
18+
techDraftSteps: params?.techDraftSteps,
1819
nextStartPlayer: params?.nextStartPlayer,
1920
nextArchitectPlayer: params?.nextArchitectPlayer
2021
}
@@ -29,6 +30,8 @@ export interface MockRoundParams {
2930
botCards?: BotCardsPersistence
3031
rowPlaceholders?: RowPlaceholdersPersistence
3132
techCardSelection?: TechCardSelectionPersistence
33+
techDraftSteps?: TechDraftStep[]
34+
// deprecated fields, latest implementation uses the techDraftSteps field instead
3235
nextStartPlayer?: Player,
3336
nextArchitectPlayer?: Player,
3437
}

tests/unit/util/NavigationState.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ describe('util/NavigationState', () => {
1919
})
2020

2121
it('nextStartArchitectPlayer', () => {
22+
const route = mockRouteLocation({params:{round:'1',turn:'3'}})
23+
const state = mockState({startPlayer:Player.BOT,rounds:[
24+
mockRound({round:1,startPlayer:Player.BOT,architectPlayer:Player.PLAYER,
25+
techDraftSteps:[
26+
{ step: 0, player: Player.BOT },
27+
{ step: 1, player: Player.PLAYER, nextStartPlayer: Player.PLAYER },
28+
{ step: 2, player: Player.PLAYER, nextStartPlayer: Player.PLAYER, nextArchitectPlayer: Player.BOT },
29+
]})
30+
]})
31+
const navigationState = new NavigationState(route, state)
32+
33+
expect(navigationState.round).to.eq(1)
34+
expect(navigationState.startPlayer).to.eq(Player.PLAYER)
35+
expect(navigationState.architectPlayer).to.eq(Player.BOT)
36+
})
37+
38+
it('nextStartArchitectPlayer_oldPersistence', () => {
2239
const route = mockRouteLocation({params:{round:'1',turn:'3'}})
2340
const state = mockState({startPlayer:Player.BOT,rounds:[
2441
mockRound({round:1,startPlayer:Player.BOT,architectPlayer:Player.PLAYER,

0 commit comments

Comments
 (0)