1
0
forked from noxious/client

npm run format

This commit is contained in:
2024-06-02 02:35:42 +02:00
parent 8329afe897
commit 86b80f8244
28 changed files with 572 additions and 562 deletions

View File

@ -10,10 +10,10 @@ export const useNotificationStore: StoreDefinition = defineStore('notifications'
},
actions: {
addNotification(notification: Notification) {
this.notifications.push(notification);
this.notifications.push(notification)
},
removeNotification(id: string) {
this.notifications = this.notifications.filter((notification: Notification) => notification.id !== id);
this.notifications = this.notifications.filter((notification: Notification) => notification.id !== id)
}
}
});
})

View File

@ -1,7 +1,7 @@
import { defineStore, type StoreDefinition } from 'pinia'
import { io, Socket } from 'socket.io-client';
import {useCookies} from '@vueuse/integrations/useCookies'
import config from '@/config';
import { io, Socket } from 'socket.io-client'
import { useCookies } from '@vueuse/integrations/useCookies'
import config from '@/config'
import type { Character, User } from '@/types'
import { useNotificationStore } from '@/stores/notifications'
@ -9,58 +9,58 @@ export const useSocketStore: StoreDefinition = defineStore('socket', {
state: () => ({
connection: null as Socket | null,
user: null as User | null,
character: null as Character | null,
character: null as Character | null
}),
getters: {
getConnection: (state: any) => state.connection as Socket,
getUser: (state: any) => state.user as User,
getCharacter: (state: any) => state.character as Character,
getCharacter: (state: any) => state.character as Character
},
actions: {
setupSocketConnection() {
this.connection = io(config.server_endpoint, {
withCredentials: true,
transports: ['websocket'],
reconnectionAttempts: 5,
});
reconnectionAttempts: 5
})
// Let the server know the user is logged in
this.connection.emit('login');
this.connection.emit('login')
// set user
this.connection.on('login', (user: User) => {
this.setUser(user);
});
this.setUser(user)
})
// When we can't reconnect, disconnect
this.connection.on('reconnect_failed', () => {
console.log("Reconnect failed")
this.disconnectSocket();
console.log('Reconnect failed')
this.disconnectSocket()
})
},
disconnectSocket() {
if (!this.connection) return;
if (!this.connection) return
this.connection.disconnect();
this.connection = null;
this.connection.disconnect()
this.connection = null
this.user = null;
this.character = null;
this.user = null
this.character = null
useCookies().remove('token');
useCookies().remove('token')
},
setUser(user: User|null) {
this.user = user;
setUser(user: User | null) {
this.user = user
},
setCharacter(character: Character|null) {
this.character = character;
setCharacter(character: Character | null) {
this.character = character
}
}
});
})
/**
* Resources:
* https://www.dynetisgames.com/2017/03/06/how-to-make-a-multiplayer-online-game-with-phaser-socket-io-and-node-js/
* https://runthatline.com/pinia-watch-state-getters-inside-vue-components/
* https://pinia.vuejs.org/
*/
*/

View File

@ -1,4 +1,4 @@
import { defineStore } from 'pinia';
import { defineStore } from 'pinia'
export const useZoneStore = defineStore('zone', {
state: () => ({
@ -13,18 +13,18 @@ export const useZoneStore = defineStore('zone', {
},
actions: {
loadTiles(tiles: any) {
this.tiles = tiles;
this.loaded = true;
this.tiles = tiles
this.loaded = true
},
addPlayers(player: any) {
this.players = player;
this.players = player
},
addPlayer(player: any) {
this.players[player.id] = player;
console.log('Player added:', player);
this.players[player.id] = player
console.log('Player added:', player)
},
removePlayer(playerId: any) {
delete this.players[playerId];
delete this.players[playerId]
}
}
});
})