1
0
forked from noxious/client

Refactor assetManager, renamed assetManager to assetStorage, renamed AssetT to AssetDataT, added better error handling in authentication service, continued working on dynamic asset loading for both maps and map editor

This commit is contained in:
2024-10-30 09:36:16 +01:00
parent 08f55c9680
commit c62ff2efc1
18 changed files with 421 additions and 357 deletions

View File

@ -1,37 +1,48 @@
import { defineStore } from 'pinia'
import { io, Socket } from 'socket.io-client'
import type { Asset, Character, Notification, User, WorldSettings } from '@/types'
import type { AssetDataT, Character, Notification, User, WorldSettings } from '@/types'
import config from '@/config'
import { useCookies } from '@vueuse/integrations/useCookies'
import { getDomain } from '@/utilities'
export const useGameStore = defineStore('game', {
state: () => {
return {
notifications: [] as Notification[],
isAssetsLoaded: false,
loadedAssets: [] as string[],
token: '' as string | null,
connection: null as Socket | null,
user: null as User | null,
character: null as Character | null,
isPlayerDraggingCamera: false,
world: {
date: new Date(),
isRainEnabled: false,
isFogEnabled: false,
fogDensity: 0.5
} as WorldSettings,
gameSettings: {
game: {
isAssetsLoaded: false,
loadedAssets: [] as AssetDataT[],
isPlayerDraggingCamera: false,
isCameraFollowingCharacter: false
},
uiSettings: {
isChatOpen: false,
isCharacterProfileOpen: false,
isGmPanelOpen: false,
isPasswordResetOpen: false
isGmPanelOpen: false
}
}
},
getters: {
getLoadedAssets: (state) => {
return state.game.loadedAssets
},
getLoadedAsset: (state) => {
return (key: string) => state.game.loadedAssets.find((asset) => asset.key === key)
},
getLoadedAssetsByGroup: (state) => {
return (group: string) => state.game.loadedAssets.filter((asset) => asset.group === group)
}
},
actions: {
addNotification(notification: Notification) {
if (!notification.id) {
@ -54,17 +65,8 @@ export const useGameStore = defineStore('game', {
toggleGmPanel() {
this.uiSettings.isGmPanelOpen = !this.uiSettings.isGmPanelOpen
},
togglePlayerDraggingCamera() {
this.isPlayerDraggingCamera = !this.isPlayerDraggingCamera
},
setPlayerDraggingCamera(moving: boolean) {
this.isPlayerDraggingCamera = moving
},
toggleCameraFollowingCharacter() {
this.gameSettings.isCameraFollowingCharacter = !this.gameSettings.isCameraFollowingCharacter
},
setCameraFollowingCharacter(following: boolean) {
this.gameSettings.isCameraFollowingCharacter = following
this.game.isPlayerDraggingCamera = moving
},
toggleChat() {
this.uiSettings.isChatOpen = !this.uiSettings.isChatOpen
@ -72,9 +74,6 @@ export const useGameStore = defineStore('game', {
toggleCharacterProfile() {
this.uiSettings.isCharacterProfileOpen = !this.uiSettings.isCharacterProfileOpen
},
togglePasswordReset() {
this.uiSettings.isPasswordResetOpen = !this.uiSettings.isPasswordResetOpen
},
initConnection() {
this.connection = io(config.server_endpoint, {
secure: !config.development,
@ -108,17 +107,19 @@ export const useGameStore = defineStore('game', {
domain: getDomain()
})
this.isAssetsLoaded = false
this.connection = null
this.token = null
this.user = null
this.character = null
this.uiSettings.isGmPanelOpen = false
this.isPlayerDraggingCamera = false
this.gameSettings.isCameraFollowingCharacter = false
this.game.isAssetsLoaded = false
this.game.loadedAssets = []
this.game.isPlayerDraggingCamera = false
this.game.isCameraFollowingCharacter = false
this.uiSettings.isChatOpen = false
this.uiSettings.isCharacterProfileOpen = false
this.uiSettings.isPasswordResetOpen = false
this.uiSettings.isGmPanelOpen = false
this.world.date = new Date()
this.world.isRainEnabled = false