1
0
forked from noxious/client

Merge remote-tracking branch 'origin/feature/#215-dexie-caching-implementation' into feature/character-profile

# Conflicts:
#	src/screens/Game.vue
This commit is contained in:
2024-10-25 22:20:34 +02:00
26 changed files with 673 additions and 723 deletions

View File

@ -7,9 +7,9 @@ import { useCookies } from '@vueuse/integrations/useCookies'
export const useGameStore = defineStore('game', {
state: () => {
return {
loginMessage: null as string | null,
notifications: [] as Notification[],
assets: [] as Asset[],
isAssetsLoaded: false,
loadedAssets: [] as string[],
token: '' as string | null,
connection: null as Socket | null,
user: null as User | null,
@ -31,12 +31,6 @@ export const useGameStore = defineStore('game', {
}
}
},
getters: {
getNotifications: (state: any) => state.notifications,
getAssetByKey: (state) => {
return (key: string) => state.assets.find((asset) => asset.key === key)
}
},
actions: {
addNotification(notification: Notification) {
if (!notification.id) {
@ -47,54 +41,6 @@ export const useGameStore = defineStore('game', {
removeNotification(id: string) {
this.notifications = this.notifications.filter((notification: Notification) => notification.id !== id)
},
setAssets(assets: Asset[]) {
this.assets = assets
},
addAsset(asset: Asset) {
this.assets.push(asset)
},
addAssets(assets: Asset[]) {
this.assets = this.assets.concat(assets)
},
async fetchSpriteAssets() {
return fetch(config.server_endpoint + '/assets/sprites')
.then((response) => response.json())
.then((assets) => {
// Only add the sprites that are not already in the store
this.addAssets(assets.filter((asset: Asset) => !this.getAssetByKey(asset.key)))
return true
})
.catch((error) => {
console.error('Error fetching assets:', error)
return false
})
},
async fetchZoneAssets(zoneId: number) {
return fetch(config.server_endpoint + '/assets/zone/' + zoneId)
.then((response) => response.json())
.then((assets) => {
// Only add the zones that are not already in the store
this.addAssets(assets.filter((asset: Asset) => !this.getAssetByKey(asset.key)))
return true
})
.catch((error) => {
console.error('Error fetching assets:', error)
return false
})
},
async fetchAllZoneAssets() {
return fetch(config.server_endpoint + '/assets/zone')
.then((response) => response.json())
.then((assets) => {
// Only add the zones that are not already in the store
this.addAssets(assets.filter((asset: Asset) => !this.getAssetByKey(asset.key)))
return true
})
.catch((error) => {
console.error('Error fetching assets:', error)
return false
})
},
setToken(token: string) {
this.token = token
},
@ -152,15 +98,15 @@ export const useGameStore = defineStore('game', {
})
},
disconnectSocket() {
if (this.connection) this.connection.disconnect()
this.connection?.disconnect()
useCookies().remove('token', {
// for whole domain
// @TODO : #190
domain: window.location.hostname.split('.').slice(-2).join('.')
// domain: window.location.hostname.split('.').slice(-2).join('.')
})
this.assets = []
this.isAssetsLoaded = false
this.connection = null
this.token = null
this.user = null