1
0
forked from noxious/client

Renamed store files to (xyz)Store for better readability

This commit is contained in:
2024-09-22 00:53:29 +02:00
parent 88bd039a04
commit 42291b93eb
44 changed files with 59 additions and 59 deletions

44
src/stores/zoneStore.ts Normal file
View File

@ -0,0 +1,44 @@
import { defineStore } from 'pinia'
import type { ExtendedCharacter, Zone } from '@/types'
export const useZoneStore = defineStore('zone', {
state: () => ({
zone: null as Zone | null,
characters: [] as ExtendedCharacter[]
}),
getters: {
getCharacterById: (state) => {
return (id: number) => state.characters.find((char) => char.id === id)
},
getCharacterCount: (state) => {
return state.characters.length
},
isZoneSet: (state) => {
return state.zone !== null
}
},
actions: {
setZone(zone: Zone | null) {
this.zone = zone
},
setCharacters(characters: ExtendedCharacter[]) {
this.characters = characters
},
addCharacter(character: ExtendedCharacter) {
this.characters.push(character)
},
updateCharacter(updatedCharacter: ExtendedCharacter) {
const index = this.characters.findIndex((char) => char.id === updatedCharacter.id)
if (index !== -1) {
this.characters[index] = { ...this.characters[index], ...updatedCharacter }
}
},
removeCharacter(character_id: number) {
this.characters = this.characters.filter((char) => char.id !== character_id)
},
reset() {
this.zone = null
this.characters = []
}
}
})