diff --git a/src/App.vue b/src/App.vue
index 3fbadbb..dece1b7 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -16,6 +16,7 @@ import Debug from '@/components/utilities/Debug.vue'
import Notifications from '@/components/utilities/Notifications.vue'
import { useMapEditorComposable } from '@/composables/useMapEditorComposable'
import { useSoundComposable } from '@/composables/useSoundComposable'
+import { socketManager } from '@/managers/SocketManager'
import { useGameStore } from '@/stores/gameStore'
import { computed, watch } from 'vue'
@@ -26,8 +27,8 @@ const { playSound } = useSoundComposable()
const currentScreen = computed(() => {
if (!gameStore.game.isLoaded) return Loading
- if (!gameStore.connection) return Login
- if (!gameStore.token) return Login
+ if (!socketManager.connection) return Login
+ if (!socketManager.token) return Login
if (!gameStore.character) return Characters
if (mapEditor.active.value) return MapEditor
return Game
diff --git a/src/application/enums.ts b/src/application/enums.ts
index ef91b70..cb8cf15 100644
--- a/src/application/enums.ts
+++ b/src/application/enums.ts
@@ -5,6 +5,8 @@ export enum Direction {
}
export enum SocketEvent {
+ CONNECT_ERROR = 'connect_error',
+ RECONNECT_FAILED = 'reconnect_failed',
CLOSE = '52',
DATA = '51',
CHARACTER_CONNECT = '50',
diff --git a/src/components/game/gui/Chat.vue b/src/components/game/gui/Chat.vue
index 5fdc69c..721b3b7 100644
--- a/src/components/game/gui/Chat.vue
+++ b/src/components/game/gui/Chat.vue
@@ -22,6 +22,7 @@
diff --git a/src/components/game/gui/Clock.vue b/src/components/game/gui/Clock.vue
index f5f9938..73cb892 100644
--- a/src/components/game/gui/Clock.vue
+++ b/src/components/game/gui/Clock.vue
@@ -8,6 +8,7 @@
diff --git a/src/components/game/map/Characters.vue b/src/components/game/map/Characters.vue
index 00b0b47..cfa63f4 100644
--- a/src/components/game/map/Characters.vue
+++ b/src/components/game/map/Characters.vue
@@ -6,6 +6,7 @@
import { SocketEvent } from '@/application/enums'
import type { MapCharacter, UUID } from '@/application/types'
import Character from '@/components/game/character/Character.vue'
+import { socketManager } from '@/managers/SocketManager'
import { useGameStore } from '@/stores/gameStore'
import { useMapStore } from '@/stores/mapStore'
import { onUnmounted } from 'vue'
@@ -17,15 +18,15 @@ const props = defineProps<{
tileMap: Phaser.Tilemaps.Tilemap
}>()
-gameStore.connection?.on(SocketEvent.MAP_CHARACTER_JOIN, (data: MapCharacter) => {
+socketManager.on(SocketEvent.MAP_CHARACTER_JOIN, (data: MapCharacter) => {
mapStore.addCharacter(data)
})
-gameStore.connection?.on(SocketEvent.MAP_CHARACTER_LEAVE, (characterId: UUID) => {
+socketManager.on(SocketEvent.MAP_CHARACTER_LEAVE, (characterId: UUID) => {
mapStore.removeCharacter(characterId)
})
-gameStore.connection?.on(SocketEvent.MAP_CHARACTER_MOVE, ([characterId, posX, posY, rot, isMoving]: [UUID, number, number, number, boolean]) => {
+socketManager.on(SocketEvent.MAP_CHARACTER_MOVE, ([characterId, posX, posY, rot, isMoving]: [UUID, number, number, number, boolean]) => {
mapStore.updateCharacterPosition([characterId, posX, posY, rot, isMoving])
if (characterId === gameStore.character?.id) {
@@ -35,14 +36,14 @@ gameStore.connection?.on(SocketEvent.MAP_CHARACTER_MOVE, ([characterId, posX, po
}
})
-gameStore.connection?.on(SocketEvent.MAP_CHARACTER_ATTACK, (characterId: UUID) => {
+socketManager.on(SocketEvent.MAP_CHARACTER_ATTACK, (characterId: UUID) => {
mapStore.updateCharacterProperty(characterId, 'isAttacking', true)
})
onUnmounted(() => {
- gameStore.connection?.off(SocketEvent.MAP_CHARACTER_ATTACK)
- gameStore.connection?.off(SocketEvent.MAP_CHARACTER_MOVE)
- gameStore.connection?.off(SocketEvent.MAP_CHARACTER_JOIN)
- gameStore.connection?.off(SocketEvent.MAP_CHARACTER_LEAVE)
+ socketManager.off(SocketEvent.MAP_CHARACTER_ATTACK)
+ socketManager.off(SocketEvent.MAP_CHARACTER_MOVE)
+ socketManager.off(SocketEvent.MAP_CHARACTER_JOIN)
+ socketManager.off(SocketEvent.MAP_CHARACTER_LEAVE)
})
diff --git a/src/components/game/map/Map.vue b/src/components/game/map/Map.vue
index fe891ef..dc7f03d 100644
--- a/src/components/game/map/Map.vue
+++ b/src/components/game/map/Map.vue
@@ -11,6 +11,7 @@ import { unduplicateArray } from '@/application/utilities'
import Characters from '@/components/game/map/Characters.vue'
import MapTiles from '@/components/game/map/MapTiles.vue'
import PlacedMapObjects from '@/components/game/map/PlacedMapObjects.vue'
+import { socketManager } from '@/managers/SocketManager'
import { createTileLayer, createTileMap, loadTileTexturesFromMapTileArray } from '@/services/mapService'
import { MapStorage } from '@/storage/storages'
import { useGameStore } from '@/stores/gameStore'
@@ -29,7 +30,7 @@ const tileMap = shallowRef()
const tileMapLayer = shallowRef()
// Event listeners
-gameStore.connection?.on(SocketEvent.MAP_CHARACTER_TELEPORT, (data: mapLoadData) => {
+socketManager.on(SocketEvent.MAP_CHARACTER_TELEPORT, (data: mapLoadData) => {
mapStore.setMapId(data.mapId)
mapStore.setCharacters(data.characters)
})
@@ -65,6 +66,6 @@ onUnmounted(() => {
tileMap.value.destroy()
}
- gameStore.connection?.off(SocketEvent.MAP_CHARACTER_TELEPORT)
+ socketManager.off(SocketEvent.MAP_CHARACTER_TELEPORT)
})
diff --git a/src/components/gameMaster/assetManager/partials/characterHair/CharacterHairDetails.vue b/src/components/gameMaster/assetManager/partials/characterHair/CharacterHairDetails.vue
index 9cdf891..594a6cf 100644
--- a/src/components/gameMaster/assetManager/partials/characterHair/CharacterHairDetails.vue
+++ b/src/components/gameMaster/assetManager/partials/characterHair/CharacterHairDetails.vue
@@ -36,6 +36,7 @@
diff --git a/src/components/screens/Characters.vue b/src/components/screens/Characters.vue
index 36b3936..68869c5 100644
--- a/src/components/screens/Characters.vue
+++ b/src/components/screens/Characters.vue
@@ -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(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)
})
diff --git a/src/components/screens/MapEditor.vue b/src/components/screens/MapEditor.vue
index 5a5219d..b2038de 100644
--- a/src/components/screens/MapEditor.vue
+++ b/src/components/screens/MapEditor.vue
@@ -20,6 +20,7 @@