Changed the way WOKA's are stored
This commit is contained in:
parent
2ea54fd243
commit
642d3bb301
6 changed files with 61 additions and 73 deletions
|
@ -1,34 +1,8 @@
|
|||
import { writable } from "svelte/store";
|
||||
import type { RoomConnection } from "../Connexion/RoomConnection";
|
||||
import { writable, Writable } from "svelte/store";
|
||||
|
||||
/**
|
||||
* A store that contains the players avatars pictures
|
||||
* A store that contains the player avatar picture
|
||||
*/
|
||||
function createUserWokaPictureStore() {
|
||||
const players = new Map<number, string>();
|
||||
|
||||
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();
|
||||
export class UserWokaPictureStore {
|
||||
constructor(public picture: Writable<HTMLImageElement | undefined> = writable(undefined)) {}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue