1
0
forked from noxious/client
This commit is contained in:
2024-05-06 22:55:59 +02:00
parent 0e9cb3e000
commit 1ab9ae32df
3 changed files with 74 additions and 19 deletions

View File

@ -3,11 +3,12 @@ import Map from '@/engine/Map/Map'
export const useMapStore = defineStore('map', {
state: () => ({
map: null as Map | null,
map: null as any | null,
}),
actions: {
setMap(map: Map) {
setMap(map: any) {
console.log('Setting map:', map);
this.map = map;
}
}

View File

@ -9,6 +9,10 @@ import { defineStore } from 'pinia';
import { io, Socket } from 'socket.io-client';
import config from '@/config';
import axios from 'axios';
import { useMapStore } from '@/stores/map';
export const useSocketStore = defineStore('socket', {
state: () => ({
@ -59,7 +63,6 @@ export const useSocketStore = defineStore('socket', {
this.socket.on('message', (message) => {
console.log('Received message:', message);
});
// Handle more socket events as needed
},
@ -68,6 +71,17 @@ export const useSocketStore = defineStore('socket', {
this.socket.disconnect();
this.socket = null;
}
},
getMap() {
if (this.socket) {
this.socket.emit('get_map');
this.socket.on('map', (map) => {
const mapStore = useMapStore();
// Get map from server
mapStore.setMap(map);
});
}
}
}
});