Worked on character animations

This commit is contained in:
2024-07-30 23:30:54 +02:00
parent fea1b849bb
commit 336f90128d
13 changed files with 176 additions and 155 deletions

View File

@ -1,26 +1,15 @@
import { defineStore } from 'pinia'
import { type Asset, type Object } from '@/types'
import { type Asset } from '@/types'
import config from '@/config'
export const useAssetStore = defineStore('assets', {
state: () => ({
assets: [] as Asset[],
tiles: [] as string[],
objects: [] as Object[]
}),
actions: {
setAssets(assets: Asset[]) {
this.assets = assets
},
addAsset(asset: Asset) {
this.assets.push(asset)
},
setTiles(tiles: string[]) {
this.tiles = tiles
},
setObjects(objects: Object[]) {
this.objects = objects
},
async fetchAssets() {
return fetch(config.server_endpoint + '/assets')
.then((response) => response.json())

View File

@ -1,32 +1,44 @@
import { defineStore } from 'pinia'
import type { Character, Zone } from '@/types'
import type { ExtendedCharacter, Zone } from '@/types'
export const useZoneStore = defineStore('zone', {
state: () => ({
zone: null as Zone | null,
characters: [] as Character[]
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: Character[]) {
setCharacters(characters: ExtendedCharacter[]) {
this.characters = characters
},
addCharacter(character: Character) {
addCharacter(character: ExtendedCharacter) {
this.characters.push(character)
},
updateCharacter(character: Character) {
const index = this.characters.findIndex((c) => c.id === character.id)
if (index === -1) return
this.characters[index] = 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((c) => c.id !== character_id)
this.characters = this.characters.filter(char => char.id !== character_id)
},
reset() {
this.zone = null
this.characters = []
}
}
})
})