Skip to content

Commit

Permalink
define pinia store
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Apr 28, 2024
1 parent 0f79a59 commit c6d13d6
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import piniaPluginPersistedState from 'pinia-plugin-persistedstate'
import { store, key } from './store'
import router from './router'
import i18n from './i18n'
Expand All @@ -7,8 +9,12 @@ import App from './App.vue'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap'

const pinia = createPinia()
.use(piniaPluginPersistedState)

createApp(App)
.use(pinia)
.use(store, key)
.use(router)
.use(i18n)
.mount('#app');
.mount('#app')
75 changes: 75 additions & 0 deletions src/store/state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import DifficultyLevel from '@/services/enum/DifficultyLevel'
import Opponent from '@/services/enum/Opponent'
import PlayerColor from '@/services/enum/PlayerColor'
import Strategy from '@/services/enum/Strategy'
import { defineStore } from 'pinia'
import { name } from '@/../package.json'

export const useStateStore = defineStore(`${name}.store`, {
state: () => {
return {
language: 'en',
baseFontSize: 1.0,
setup: {
difficultyLevel: DifficultyLevel.EASY,
playerSetup: {
botCount: 1,
opponent: [Opponent.IVAN],
strategy: [Strategy.NONE],
playerColors: [PlayerColor.YELLOW,PlayerColor.BLUE,PlayerColor.RED,PlayerColor.GREEN]
}
},
years: []
} as State
},
actions: {
season(season: Season) {
let year = this.years.find(item => item.year == season.year)
if (!year) {
year = {
year: season.year,
seasons: []
}
this.years.push(year)
}
year.seasons = year.seasons.filter(item => item.season != season.season)
year.seasons.push(season)
},
resetGame() {
this.setup.actualStrategy = undefined
this.years = []
}
},
persist: true
})

export interface State {
language: string
baseFontSize: number
setup: Setup
years: Year[]
}
export interface Setup {
difficultyLevel: DifficultyLevel
playerSetup: PlayerSetup
actualStrategy?: Strategy[]
}
export interface PlayerSetup {
botCount: number
opponent: Opponent[]
strategy: Strategy[]
playerColors: PlayerColor[]
}
export interface Year {
year: number
seasons: Season[]
}
export interface Season {
year: number
season: number
cardDeck: CardDeckPersistence[]
}
export interface CardDeckPersistence {
deck: number[]
discard: number[]
}

0 comments on commit c6d13d6

Please sign in to comment.