2021-11-26 22:16:01 +01:00
|
|
|
import { writable } from "svelte/store";
|
|
|
|
import type { RoomConnection } from "../Connexion/RoomConnection";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A store that contains the players avatars pictures
|
|
|
|
*/
|
|
|
|
function createUserWokaPictureStore() {
|
2021-11-26 23:30:21 +01:00
|
|
|
const players = new Map<number, string>();
|
2021-11-26 22:16:01 +01:00
|
|
|
|
|
|
|
const { subscribe, update } = writable(players);
|
|
|
|
|
|
|
|
return {
|
|
|
|
subscribe,
|
|
|
|
connectToRoomConnection: (roomConnection: RoomConnection) => {
|
|
|
|
roomConnection.onUserLeft((userId) => {
|
|
|
|
update((users) => {
|
|
|
|
users.delete(userId);
|
|
|
|
return users;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
setWokaPicture(userId: number, url: string) {
|
|
|
|
update((users) => {
|
|
|
|
users.set(userId, url);
|
|
|
|
return users;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
getWokaPictureById(userId: number): string | undefined {
|
|
|
|
return players.get(userId);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export const userWokaPictureStore = createUserWokaPictureStore();
|