Skip to content

Commit

Permalink
module selection
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Sep 16, 2024
1 parent 55ecd85 commit b2cb5ca
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/components/setup/DifficultyLevel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
<div class="row">
<div class="offset-1 col-10">
<p class="text-muted">
{{t('setup.difficultyLevel.useCards', { count: state.setup.difficultyLevel }, state.setup.difficultyLevel)}}<br/>
{{t('setup.difficultyLevel.infoModules')}}
{{t('setup.difficultyLevel.useCards', { count: state.setup.difficultyLevel }, state.setup.difficultyLevel)}}
</p>
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/components/setup/SelectExpansion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { defineComponent } from 'vue'
import { useI18n } from 'vue-i18n'
import { useStateStore } from '@/store/state'
import Expansion from '@/services/enum/Expansion'
import Module from '@/services/enum/Module';
export default defineComponent({
name: 'SelectExpansion',
Expand All @@ -62,6 +63,9 @@ export default defineComponent({
},
toggleAfricanEmpires() {
this.state.setupToggleExpansionAfricanEmpires()
if (!this.hasAfricanEmpires) {
this.state.setup.modules = this.state.setup.modules.filter(module => module != Module.QUESTS)
}
}
}
})
Expand All @@ -78,4 +82,4 @@ export default defineComponent({
opacity: 0.4;
filter: grayscale(1);
}
</style>
</style>
61 changes: 61 additions & 0 deletions src/components/setup/SelectModules.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<template>
<h3 class="mt-4 mb-3">{{t('setup.selectModules.title')}}</h3>
<div class="row">
<div class="col">
<div class="form-check form-switch" v-for="item of modules" :key="item">
<label class="form-check-label">
<input class="form-check-input" type="checkbox" :checked="hasModule(item)" @input="toggleModule(item)" :disabled="!isAvailable(item)">
{{t(`module.${item}`)}}
</label>
</div>
</div>
</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { useI18n } from 'vue-i18n'
import { useStateStore } from '@/store/state'
import toggleArrayItem from '@brdgm/brdgm-commons/src/util/array/toggleArrayItem'
import Module from '@/services/enum/Module'
import Expansion from '@/services/enum/Expansion'
export default defineComponent({
name: 'SelectModules',
setup() {
const { t } = useI18n()
const state = useStateStore()
return { t, state }
},
data() {
return {
show: false
}
},
computed: {
modules() : Module[] {
return Object.values(Module)
},
hasAfricanEmpiresExpansion() {
return this.state.setup.expansions.includes(Expansion.AFRICAN_EMPIRES)
}
},
methods: {
hasModule(module : Module) : boolean {
return (this.state.setup.modules ?? []).includes(module)
},
toggleModule(module : Module) {
if (!this.state.setup.modules) {
this.state.setup.modules = []
}
toggleArrayItem(this.state.setup.modules, module)
},
isAvailable(module : Module) : boolean {
if (module === Module.QUESTS) {
return this.hasAfricanEmpiresExpansion
}
return true
}
}
})
</script>
11 changes: 9 additions & 2 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
"lostKingdoms": "Lost Kingdoms",
"africanEmpires": "African Empires"
},
"selectModules": {
"title": "Modules"
},
"difficultyLevel": {
"title": "Difficulty Level",
"easy": "Easy",
"hard": "Hard",
"useCards": "Use no advanced action cards | Use 1 advanced action card | Use {count} advanced action cards",
"infoModules": "You can add the hero or monster module to make the game easier for human players. The bots cannot benefit from them."
"useCards": "Use no advanced action cards | Use 1 advanced action card | Use {count} advanced action cards"
},
"civilization": {
"numberPlayers": "Total number of players",
Expand Down Expand Up @@ -144,6 +146,11 @@
"gold": "Gold / 3 (only bots)",
"total": "Total VP"
},
"module": {
"monsters": "Monsters",
"heroes": "Heroes",
"quests": "Quests"
},
"action": {
"playGame": "Play Game",
"startGame": "Start Game",
Expand Down
3 changes: 1 addition & 2 deletions src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"title": "Niveau de difficulté",
"easy": "Facile",
"hard": "Difficile",
"useCards": "N'utilise pas de cartes Action Avancée | Utilise 1 carte Action Avancée | Utilise {count} cartes Action Avancée",
"infoModules": "Vous pouvez ajouter le module Héro ou Monstre pour facilité le jeu aux joueurs humains. Les Automas ne peuvent pas bénéficier de ces derniers."
"useCards": "N'utilise pas de cartes Action Avancée | Utilise 1 carte Action Avancée | Utilise {count} cartes Action Avancée"
},
"civilization": {
"numberPlayers": "Nombre de joueurs total",
Expand Down
6 changes: 6 additions & 0 deletions src/services/enum/Module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
enum Module {
MONSTERS = 'monsters',
HEROES = 'heroes',
QUESTS = 'quests'
}
export default Module
3 changes: 3 additions & 0 deletions src/store/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import CardName from '@/services/enum/CardName'
import toggleArrayItem from '@brdgm/brdgm-commons/src/util/array/toggleArrayItem'
import Action from '@/services/enum/Action'
import { name } from '@/../package.json'
import Module from '@/services/enum/Module'

export const useStateStore = defineStore(`${name}.store`, {
state: () => {
Expand All @@ -16,6 +17,7 @@ export const useStateStore = defineStore(`${name}.store`, {
setup: {
difficultyLevel: DifficultyLevel.BEGINNER,
expansions: [],
modules: [],
civilizations: {
numberPlayers: 2,
numberHumanPlayers: 1,
Expand Down Expand Up @@ -79,6 +81,7 @@ export interface State {
export interface Setup {
difficultyLevel: DifficultyLevel
expansions: Expansion[]
modules: Module[]
civilizations: CivilizationSetup
}
export interface CivilizationSetup {
Expand Down
3 changes: 3 additions & 0 deletions src/views/SetupGameDifficulty.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<h1>{{t('setup.title')}}</h1>

<SelectExpansion/>
<SelectModules/>
<DifficultyLevel/>

<router-link to="/setup/civilization" class="btn btn-primary btn-lg mt-3">
Expand All @@ -17,11 +18,13 @@ import { useI18n } from 'vue-i18n'
import SelectExpansion from '@/components/setup/SelectExpansion.vue'
import DifficultyLevel from '@/components/setup/DifficultyLevel.vue'
import FooterButtons from '@/components/structure/FooterButtons.vue'
import SelectModules from '@/components/setup/SelectModules.vue'
export default defineComponent({
name: 'SetupGameDifficulty',
components: {
SelectExpansion,
SelectModules,
DifficultyLevel,
FooterButtons
},
Expand Down

0 comments on commit b2cb5ca

Please sign in to comment.