Merge branch 'develop' of github.com:thecodingmachine/workadventure into MenuSvelte
This commit is contained in:
commit
9c1926f636
61 changed files with 1911 additions and 552 deletions
105
front/src/Stores/AudioManagerStore.ts
Normal file
105
front/src/Stores/AudioManagerStore.ts
Normal file
|
@ -0,0 +1,105 @@
|
|||
import { get, writable } from "svelte/store";
|
||||
|
||||
export interface audioManagerVolume {
|
||||
muted: boolean;
|
||||
volume: number;
|
||||
decreaseWhileTalking: boolean;
|
||||
volumeReduced: boolean;
|
||||
loop: boolean;
|
||||
talking: boolean;
|
||||
}
|
||||
|
||||
function createAudioManagerVolumeStore() {
|
||||
const { subscribe, update } = writable<audioManagerVolume>({
|
||||
muted: false,
|
||||
volume: 1,
|
||||
decreaseWhileTalking: true,
|
||||
volumeReduced: false,
|
||||
loop: false,
|
||||
talking: false,
|
||||
});
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
setMuted: (newMute: boolean): void => {
|
||||
update((audioPlayerVolume: audioManagerVolume) => {
|
||||
audioPlayerVolume.muted = newMute;
|
||||
return audioPlayerVolume;
|
||||
});
|
||||
},
|
||||
setVolume: (newVolume: number): void => {
|
||||
update((audioPlayerVolume: audioManagerVolume) => {
|
||||
audioPlayerVolume.volume = newVolume;
|
||||
return audioPlayerVolume;
|
||||
});
|
||||
},
|
||||
setDecreaseWhileTalking: (newDecrease: boolean): void => {
|
||||
update((audioManagerVolume: audioManagerVolume) => {
|
||||
audioManagerVolume.decreaseWhileTalking = newDecrease;
|
||||
return audioManagerVolume;
|
||||
});
|
||||
},
|
||||
setVolumeReduced: (newVolumeReduced: boolean): void => {
|
||||
update((audioManagerVolume: audioManagerVolume) => {
|
||||
audioManagerVolume.volumeReduced = newVolumeReduced;
|
||||
return audioManagerVolume;
|
||||
});
|
||||
},
|
||||
setLoop: (newLoop: boolean): void => {
|
||||
update((audioManagerVolume: audioManagerVolume) => {
|
||||
audioManagerVolume.loop = newLoop;
|
||||
return audioManagerVolume;
|
||||
});
|
||||
},
|
||||
setTalking: (newTalk: boolean): void => {
|
||||
update((audioManagerVolume: audioManagerVolume) => {
|
||||
audioManagerVolume.talking = newTalk;
|
||||
return audioManagerVolume;
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function createAudioManagerFileStore() {
|
||||
const { subscribe, update } = writable<string>("");
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
playAudio: (
|
||||
url: string | number | boolean,
|
||||
mapDirUrl: string,
|
||||
volume: number | undefined,
|
||||
loop = false
|
||||
): void => {
|
||||
update((file: string) => {
|
||||
const audioPath = url as string;
|
||||
|
||||
if (audioPath.indexOf("://") > 0) {
|
||||
// remote file or stream
|
||||
file = audioPath;
|
||||
} else {
|
||||
// local file, include it relative to map directory
|
||||
file = mapDirUrl + "/" + url;
|
||||
}
|
||||
audioManagerVolumeStore.setVolume(
|
||||
volume ? Math.min(volume, get(audioManagerVolumeStore).volume) : get(audioManagerVolumeStore).volume
|
||||
);
|
||||
audioManagerVolumeStore.setLoop(loop);
|
||||
|
||||
return file;
|
||||
});
|
||||
},
|
||||
unloadAudio: () => {
|
||||
update((file: string) => {
|
||||
audioManagerVolumeStore.setLoop(false);
|
||||
return "";
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const audioManagerVisibilityStore = writable(false);
|
||||
|
||||
export const audioManagerVolumeStore = createAudioManagerVolumeStore();
|
||||
|
||||
export const audioManagerFileStore = createAudioManagerFileStore();
|
|
@ -1,15 +1,14 @@
|
|||
import { writable } from "svelte/store";
|
||||
import { derived, writable } from "svelte/store";
|
||||
import type { UserInputManager } from "../Phaser/UserInput/UserInputManager";
|
||||
|
||||
export interface LayoutManagerAction {
|
||||
type: string;
|
||||
uuid: string;
|
||||
type: "warning" | "message";
|
||||
message: string | number | boolean | undefined;
|
||||
callback: () => void;
|
||||
userInputManager: UserInputManager | undefined;
|
||||
}
|
||||
|
||||
export const layoutManagerVisibilityStore = writable(false);
|
||||
|
||||
function createLayoutManagerAction() {
|
||||
const { subscribe, set, update } = writable<LayoutManagerAction[]>([]);
|
||||
|
||||
|
@ -18,26 +17,26 @@ function createLayoutManagerAction() {
|
|||
addAction: (newAction: LayoutManagerAction): void => {
|
||||
update((list: LayoutManagerAction[]) => {
|
||||
let found = false;
|
||||
for (const actions of list) {
|
||||
if (actions.type === newAction.type && actions.message === newAction.message) {
|
||||
for (const action of list) {
|
||||
if (action.uuid === newAction.uuid) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
list.push(newAction);
|
||||
newAction.userInputManager?.addSpaceEventListner(newAction.callback);
|
||||
}
|
||||
|
||||
return list;
|
||||
});
|
||||
},
|
||||
removeAction: (oldAction: LayoutManagerAction): void => {
|
||||
removeAction: (uuid: string): void => {
|
||||
update((list: LayoutManagerAction[]) => {
|
||||
const index = list.findIndex(
|
||||
(actions) => actions.type === oldAction.type && actions.message === oldAction.message
|
||||
);
|
||||
const index = list.findIndex((action) => action.uuid === uuid);
|
||||
|
||||
if (index !== -1) {
|
||||
list[index].userInputManager?.removeSpaceEventListner(list[index].callback);
|
||||
list.splice(index, 1);
|
||||
}
|
||||
|
||||
|
@ -51,3 +50,7 @@ function createLayoutManagerAction() {
|
|||
}
|
||||
|
||||
export const layoutManagerActionStore = createLayoutManagerAction();
|
||||
|
||||
export const layoutManagerVisibilityStore = derived(layoutManagerActionStore, ($layoutManagerActionStore) => {
|
||||
return !!$layoutManagerActionStore.length;
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue