tried to un-spaghetti my code
This commit is contained in:
@ -1,15 +1,30 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import Map from '@/engine/Map/Map'
|
||||
|
||||
export const useMapStore = defineStore('map', {
|
||||
export const useMapStore = defineStore('gameMap', {
|
||||
state: () => ({
|
||||
map: null as any | null,
|
||||
loaded: false,
|
||||
tiles: null,
|
||||
players: {}
|
||||
}),
|
||||
|
||||
getters: {
|
||||
isLoaded: (state) => state.loaded,
|
||||
getTiles: (state) => state.tiles,
|
||||
getPlayers: (state) => state.players
|
||||
},
|
||||
actions: {
|
||||
setMap(map: any) {
|
||||
console.log('Setting map:', map);
|
||||
this.map = map;
|
||||
loadTiles(tiles) {
|
||||
this.tiles = tiles;
|
||||
this.loaded = true;
|
||||
},
|
||||
addPlayers(player) {
|
||||
this.players = player;
|
||||
},
|
||||
addPlayer(player) {
|
||||
this.players[player.id] = player;
|
||||
console.log('Player added:', player);
|
||||
},
|
||||
removePlayer(playerId) {
|
||||
delete this.players[playerId];
|
||||
}
|
||||
}
|
||||
});
|
@ -4,22 +4,20 @@
|
||||
* https://runthatline.com/pinia-watch-state-getters-inside-vue-components/
|
||||
* https://pinia.vuejs.org/
|
||||
*/
|
||||
|
||||
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: () => ({
|
||||
isAuthenticated: false,
|
||||
socket: null as Socket | null,
|
||||
}),
|
||||
|
||||
getters: {
|
||||
auth: (state) => state.isAuthenticated,
|
||||
sockett: (state) => state.socket,
|
||||
},
|
||||
actions: {
|
||||
async register(username: string, password: string) {
|
||||
if ( this.isAuthenticated ) return console.log('User already authenticated');
|
||||
|
Reference in New Issue
Block a user