From 20398abe9b193e6872acfc980375c04b6cf1b986 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Sat, 19 Oct 2024 16:29:29 +0200 Subject: [PATCH] round start --- src/locales/de.json | 24 +++++++++++ src/locales/en.json | 24 +++++++++++ src/router/index.ts | 18 +++++++++ src/util/NavigationState.ts | 45 +++++++++++++++++---- src/views/GameEnd.vue | 41 +++++++++++++++++++ src/views/RoundEnd.vue | 69 ++++++++++++++++++++++++++++++++ src/views/RoundStart.vue | 80 +++++++++++++++++++++++++++++++++++++ src/views/SetupBot.vue | 5 +-- src/views/TurnBot.vue | 5 +-- src/views/TurnPlayer.vue | 5 +-- 10 files changed, 298 insertions(+), 18 deletions(-) create mode 100644 src/views/GameEnd.vue create mode 100644 src/views/RoundEnd.vue create mode 100644 src/views/RoundStart.vue diff --git a/src/locales/de.json b/src/locales/de.json index ead28f5..a22ff52 100644 --- a/src/locales/de.json +++ b/src/locales/de.json @@ -33,6 +33,24 @@ "diceNotice": "Diese Würfel werden nicht gewürfelt - sie dienen dazu, die Anzahl von V.I.C.Is Würfeln zu ermitteln.", "noOtherComponents": "Anderes Spielmaterial wird für V.I.C.I nicht benötigt." }, + "roundStart": { + "title": "Beginn der Epoche", + "newCards": { + "title": "1) Neue Karten", + "playAsUsual": "Keine Anpassungen." + }, + "newGoals": { + "title": "2) Neue Ziele", + "playerTakeGoal": "Nehme eine Zielplatine (optional).", + "botDetermine": "Bestimme eine Zielplatine für V.I.C.I.", + "botTakeGoal": "Entferne Zielplatine {goalChip} (wenn verfügbar).", + "botNoGoal": "Es wird keine Zielplatine entfernt." + }, + "extraFind": { + "title": "3) Sonderfund", + "playAsUsual": "Keine Anpassungen. V.I.C.I macht keinen Sonderfund." + } + }, "turnPlayer": { "title": "Spieler", "takeTurn": "Führe deinen Zug aus." @@ -40,6 +58,12 @@ "turnBot": { "title": "V.I.C.I" }, + "roundEnd": { + "title": "Ende der Epoche" + }, + "gameEnd": { + "title": "Spielende" + }, "sideBar": { "round": "Epoche {round}" }, diff --git a/src/locales/en.json b/src/locales/en.json index 75edad9..7ec941e 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -33,6 +33,24 @@ "diceNotice": "You do not roll them, they are used to count the number of V.I.C.I's dice.", "noOtherComponents": "Other components are not used for V.I.C.I." }, + "roundStart": { + "title": "Era Start", + "newCards": { + "title": "1) New Cards", + "playAsUsual": "Play as usual." + }, + "newGoals": { + "title": "2) New goals", + "playerTakeGoal": "Take a goal chip (optional).", + "botDetermine": "Determine goal chip for V.I.C.I.", + "botTakeGoal": "Remove goal chip {goalChip} (if available).", + "botNoGoal": "No goal chip is removed." + }, + "extraFind": { + "title": "3) Extra find", + "playAsUsual": "Play as usual, V.I.C.I makes no extra find." + } + }, "turnPlayer": { "title": "Player", "takeTurn": "Take your turn." @@ -40,6 +58,12 @@ "turnBot": { "title": "V.I.C.I" }, + "roundEnd": { + "title": "Era End" + }, + "gameEnd": { + "title": "Game End" + }, "sideBar": { "round": "Era {round}" }, diff --git a/src/router/index.ts b/src/router/index.ts index f573af4..71cb364 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -7,6 +7,9 @@ import SetupGame from '@/views/SetupGame.vue' import SetupBot from '@/views/SetupBot.vue' import TurnPlayer from '@/views/TurnPlayer.vue' import TurnBot from '@/views/TurnBot.vue' +import RoundStart from '@/views/RoundStart.vue' +import RoundEnd from '@/views/RoundEnd.vue' +import GameEnd from '@/views/GameEnd.vue' const LOCALSTORAGE_KEY = `${name}.route` @@ -26,6 +29,11 @@ const routes: Array = [ name: 'SetupBot', component: SetupBot }, + { + path: '/round/:round/start', + name: 'RoundStart', + component: RoundStart + }, { path: '/round/:round/turn/:turn/player', name: 'TurnPlayer', @@ -36,6 +44,16 @@ const routes: Array = [ name: 'TurnBot', component: TurnBot }, + { + path: '/round/:round/end', + name: 'RoundEnd', + component: RoundEnd + }, + { + path: '/gameEnd', + name: 'GameEnd', + component: GameEnd + }, { path: '/:pathMatch(.*)*', name: 'NotFound', diff --git a/src/util/NavigationState.ts b/src/util/NavigationState.ts index 8034c0b..350383d 100644 --- a/src/util/NavigationState.ts +++ b/src/util/NavigationState.ts @@ -5,12 +5,15 @@ import CardDeck from '@/services/CardDeck' import Card from '@/services/Card' import Cards from '@/services/Cards' import rollDice from '@brdgm/brdgm-commons/src/util/random/rollDice' +import Player from '@/services/enum/Player' export default class NavigationState { readonly round : number readonly turn : number - + readonly startPlayer : Player + readonly player : Player + readonly cardDeck : CardDeck readonly evolutionCount : number readonly prosperityCount : number @@ -21,7 +24,15 @@ export default class NavigationState { constructor(route: RouteLocation, state: State) { this.round = getIntRouteParam(route, 'round') - this.turn = getIntRouteParam(route, 'turn') + if (route.name == 'RoundEnd' || route.name == 'GameEnd') { + this.turn = MAX_TURN + } + else { + this.turn = getIntRouteParam(route, 'turn') + } + + this.startPlayer = getStartPlayer(state, this.round) + this.player = getPlayer(route, this.startPlayer) // try to load persistence with rolled die values for current turns const botPersistence = getBotPersistence(state, this.round, this.turn) @@ -52,13 +63,33 @@ export default class NavigationState { } +const MAX_TURN = 999 + +function getStartPlayer(state: State, round: number) : Player { + const roundData = state.rounds.find(item => item.round == round) + if (roundData) { + return roundData.startPlayer + } + return Player.PLAYER +} + +function getPlayer(route: RouteLocation, startPlayer: Player) : Player { + if (route.name == 'TurnPlayer') { + return Player.PLAYER + } + else if (route.name == 'TurnBot') { + return Player.BOT + } + else { + return startPlayer + } +} + function getBotPersistence(state: State, round: number, turn: number) : BotPersistence|undefined { const roundData = state.rounds.find(item => item.round == round) if (roundData) { const turnData = roundData.turns.find(item => item.turn == turn) - if (turnData && turnData.botPersistence) { - return turnData.botPersistence - } + return turnData?.botPersistence } return undefined } @@ -67,7 +98,7 @@ function getPreviousBotPersistence(state: State, round: number, turn: number) : const roundData = state.rounds.find(item => item.round == round) if (roundData) { const lastBotPersistence = roundData.turns - .filter(item => (item.turn < turn) || turn == 0) + .filter(item => item.turn < turn) .toSorted((a,b) => a.turn - b.turn) .map(item => item.botPersistence) .find(item => item != undefined) @@ -78,7 +109,7 @@ function getPreviousBotPersistence(state: State, round: number, turn: number) : // check previous round if (round > 1) { - return getPreviousBotPersistence(state, round - 1, 0) + return getPreviousBotPersistence(state, round - 1, MAX_TURN) } // get initial card deck diff --git a/src/views/GameEnd.vue b/src/views/GameEnd.vue new file mode 100644 index 0000000..09c6bba --- /dev/null +++ b/src/views/GameEnd.vue @@ -0,0 +1,41 @@ + + + diff --git a/src/views/RoundEnd.vue b/src/views/RoundEnd.vue new file mode 100644 index 0000000..93f9274 --- /dev/null +++ b/src/views/RoundEnd.vue @@ -0,0 +1,69 @@ + + + diff --git a/src/views/RoundStart.vue b/src/views/RoundStart.vue new file mode 100644 index 0000000..d024a3d --- /dev/null +++ b/src/views/RoundStart.vue @@ -0,0 +1,80 @@ + + + diff --git a/src/views/SetupBot.vue b/src/views/SetupBot.vue index 3139871..41b5353 100644 --- a/src/views/SetupBot.vue +++ b/src/views/SetupBot.vue @@ -35,8 +35,7 @@ import { defineComponent } from 'vue' import { useI18n } from 'vue-i18n' import FooterButtons from '@/components/structure/FooterButtons.vue' -import { useStateStore } from '@/store/state' -import { Round } from '@/store/state' +import { useStateStore, Round } from '@/store/state' import Player from '@/services/enum/Player' import CardDeck from '@/services/CardDeck' @@ -59,7 +58,7 @@ export default defineComponent({ turns: [] } this.state.storeRound(round) - this.$router.push('/round/1/turn/1/player') + this.$router.push('/round/1/start') } } }) diff --git a/src/views/TurnBot.vue b/src/views/TurnBot.vue index 860b81f..65b9ce5 100644 --- a/src/views/TurnBot.vue +++ b/src/views/TurnBot.vue @@ -43,10 +43,7 @@ export default defineComponent({ if (this.turn > 1) { return `/round/${this.round}/turn/${this.turn-1}/player` } - if (this.round > 1) { - return `/round/${this.round-1}/end` - } - return '' + return `/round/${this.round}/start` } }, methods: { diff --git a/src/views/TurnPlayer.vue b/src/views/TurnPlayer.vue index f0afa77..3f199eb 100644 --- a/src/views/TurnPlayer.vue +++ b/src/views/TurnPlayer.vue @@ -44,10 +44,7 @@ export default defineComponent({ if (this.turn > 1) { return `/round/${this.round}/turn/${this.turn-1}/bot` } - if (this.round > 1) { - return `/round/${this.round-1}/end` - } - return '' + return `/round/${this.round}/start` } }, methods: {