feature/#215-dexie-caching-implementation
This commit is contained in:
@ -7,9 +7,8 @@ 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,
|
||||
token: '' as string | null,
|
||||
connection: null as Socket | null,
|
||||
user: null as User | null,
|
||||
@ -47,54 +46,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 +103,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
|
||||
|
Reference in New Issue
Block a user