forked from noxious/client
Renamed zone > map
This commit is contained in:
58
src/stores/mapStore.ts
Normal file
58
src/stores/mapStore.ts
Normal file
@ -0,0 +1,58 @@
|
||||
import type { Map, MapCharacter } from '@/application/types'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useMapStore = defineStore('map', {
|
||||
state: () => {
|
||||
return {
|
||||
map: null as Map | null,
|
||||
characters: [] as MapCharacter[],
|
||||
characterLoaded: false
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
getCharacterById: (state) => {
|
||||
return (id: number) => state.characters.find((char) => char.character.id === id)
|
||||
},
|
||||
getCharacterCount: (state) => {
|
||||
return state.characters.length
|
||||
},
|
||||
isMapSet: (state) => {
|
||||
return state.map !== null
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
setMap(map: Map | null) {
|
||||
this.map = map
|
||||
},
|
||||
setCharacters(characters: MapCharacter[]) {
|
||||
this.characters = characters
|
||||
},
|
||||
addCharacter(character: MapCharacter) {
|
||||
this.characters.push(character)
|
||||
},
|
||||
updateCharacter(updatedCharacter: MapCharacter) {
|
||||
const index = this.characters.findIndex((char) => char.character.id === updatedCharacter.character.id)
|
||||
if (index !== -1) this.characters[index] = updatedCharacter
|
||||
},
|
||||
removeCharacter(characterId: number) {
|
||||
this.characters = this.characters.filter((char) => char.character.id !== characterId)
|
||||
},
|
||||
setCharacterLoaded(loaded: boolean) {
|
||||
this.characterLoaded = loaded
|
||||
},
|
||||
updateCharacterPosition(data: { characterId: number; positionX: number; positionY: number; rotation: number; isMoving: boolean }) {
|
||||
const character = this.characters.find((char) => char.character.id === data.characterId)
|
||||
if (character) {
|
||||
character.character.positionX = data.positionX
|
||||
character.character.positionY = data.positionY
|
||||
character.character.rotation = data.rotation
|
||||
character.isMoving = data.isMoving
|
||||
}
|
||||
},
|
||||
reset() {
|
||||
this.map = null
|
||||
this.characters = []
|
||||
this.characterLoaded = false
|
||||
}
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user