#363 : Moved socket logic into socketManager and removed it from Pinia store

This commit is contained in:
2025-02-17 01:17:02 +01:00
parent 0c61fe77de
commit a6d6d894a9
30 changed files with 196 additions and 114 deletions

View File

@ -126,6 +126,7 @@ import { SocketEvent } from '@/application/enums'
import { type CharacterHair, type Character as CharacterT, type Map } from '@/application/types'
import Modal from '@/components/utilities/Modal.vue'
import { useSoundComposable } from '@/composables/useSoundComposable'
import { socketManager } from '@/managers/SocketManager'
import { CharacterHairStorage } from '@/storage/storages'
import { useGameStore } from '@/stores/gameStore'
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
@ -142,10 +143,10 @@ const selectedHairId = ref<string | null>(null)
// Fetch characters
setTimeout(() => {
gameStore.connection?.emit(SocketEvent.CHARACTER_LIST)
socketManager.emit(SocketEvent.CHARACTER_LIST)
}, 750)
gameStore.connection?.on(SocketEvent.CHARACTER_LIST, (data: any) => {
socketManager.on(SocketEvent.CHARACTER_LIST, (data: any) => {
characters.value = data
isLoading.value = false
})
@ -154,7 +155,7 @@ gameStore.connection?.on(SocketEvent.CHARACTER_LIST, (data: any) => {
function loginWithCharacter() {
if (!selectedCharacterId.value) return
gameStore.connection?.emit(
socketManager.emit(
SocketEvent.CHARACTER_CONNECT,
{
characterId: selectedCharacterId.value,
@ -168,7 +169,7 @@ function loginWithCharacter() {
// Create character logics
function createCharacter() {
gameStore.connection?.emit(SocketEvent.CHARACTER_CREATE, { name: newCharacterName.value }, (success: boolean) => {
socketManager.emit(SocketEvent.CHARACTER_CREATE, { name: newCharacterName.value }, (success: boolean) => {
if (success) return
isCreateNewCharacterModalOpen.value = false
})
@ -187,8 +188,8 @@ onMounted(async () => {
})
onBeforeUnmount(() => {
gameStore.connection?.off(SocketEvent.CHARACTER_LIST)
gameStore.connection?.off(SocketEvent.CHARACTER_CONNECT)
gameStore.connection?.off(SocketEvent.CHARACTER_CREATE)
socketManager.off(SocketEvent.CHARACTER_LIST)
socketManager.off(SocketEvent.CHARACTER_CONNECT)
socketManager.off(SocketEvent.CHARACTER_CREATE)
})
</script>