improvements on svelte store + handling

This commit is contained in:
Lurkars 2021-09-12 11:11:52 +02:00
parent e553392d9d
commit 3080e1fdc7
4 changed files with 29 additions and 22 deletions
front/src
Components/EmoteMenu
Phaser
Stores

View File

@ -26,11 +26,11 @@
}); });
picker.on("hidden", () => { picker.on("hidden", () => {
emoteMenuStore.set(false); emoteMenuStore.closeEmoteMenu();
}); });
unsubscriber = emoteMenuStore.subscribe(() => { unsubscriber = emoteMenuStore.subscribe((isEmoteMenuVisible) => {
if (get(emoteMenuStore)) { if (isEmoteMenuVisible && !picker.isPickerVisible()) {
picker.showPicker(emojiContainer); picker.showPicker(emojiContainer);
} else { } else {
picker.hidePicker(); picker.hidePicker();
@ -42,6 +42,8 @@
if (unsubscriber) { if (unsubscriber) {
unsubscriber(); unsubscriber();
} }
picker.destroyPicker();
}) })
</script> </script>

View File

@ -82,7 +82,7 @@ import { biggestAvailableAreaStore } from "../../Stores/BiggestAvailableAreaStor
import { SharedVariablesManager } from "./SharedVariablesManager"; import { SharedVariablesManager } from "./SharedVariablesManager";
import { playersStore } from "../../Stores/PlayersStore"; import { playersStore } from "../../Stores/PlayersStore";
import { chatVisibilityStore } from "../../Stores/ChatStore"; import { chatVisibilityStore } from "../../Stores/ChatStore";
import { emoteStore } from "../../Stores/EmoteStore"; import { emoteStore, emoteMenuStore } from "../../Stores/EmoteStore";
import { import {
audioManagerFileStore, audioManagerFileStore,
audioManagerVisibilityStore, audioManagerVisibilityStore,
@ -616,8 +616,7 @@ export class GameScene extends DirtyScene {
this.openChatIcon.setVisible(!v); this.openChatIcon.setVisible(!v);
}); });
this.emoteUnsubscribe = emoteStore.subscribe(() => { this.emoteUnsubscribe = emoteStore.subscribe((emoteKey) => {
const emoteKey = get(emoteStore);
if (emoteKey) { if (emoteKey) {
this.CurrentPlayer?.playEmote(emoteKey); this.CurrentPlayer?.playEmote(emoteKey);
this.connection?.emitEmoteEvent(emoteKey); this.connection?.emitEmoteEvent(emoteKey);
@ -1445,7 +1444,12 @@ ${escapedMessage}
return; //we don't want the menu to open when pinching on a touch screen. return; //we don't want the menu to open when pinching on a touch screen.
} }
this.CurrentPlayer.openOrCloseEmoteMenu(); // toggle EmoteMenu
if (get(emoteMenuStore)) {
emoteMenuStore.closeEmoteMenu();
} else {
emoteMenuStore.openEmoteMenu();
}
}); });
this.CurrentPlayer.on(requestEmoteEventName, (emoteKey: string) => { this.CurrentPlayer.on(requestEmoteEventName, (emoteKey: string) => {
this.connection?.emitEmoteEvent(emoteKey); this.connection?.emitEmoteEvent(emoteKey);

View File

@ -84,17 +84,4 @@ export class Player extends Character {
public isMoving(): boolean { public isMoving(): boolean {
return this.wasMoving; return this.wasMoving;
} }
playEmote(emote: string) {
super.playEmote(emote);
emoteMenuStore.set(false);
}
openOrCloseEmoteMenu() {
if (get(emoteMenuStore)) {
emoteMenuStore.set(false);
} else {
emoteMenuStore.set(true);
}
}
} }

View File

@ -1,4 +1,18 @@
import { writable } from "svelte/store"; import { writable } from "svelte/store";
function createEmoteMenuStore() {
const { subscribe, set } = writable(false);
return {
subscribe,
openEmoteMenu() {
set(true);
},
closeEmoteMenu() {
set(false);
},
};
}
export const emoteStore = writable<string | null>(null); export const emoteStore = writable<string | null>(null);
export const emoteMenuStore = writable(false); export const emoteMenuStore = createEmoteMenuStore();