2021-08-05 11:19:28 +02:00
|
|
|
import { derived, writable } from "svelte/store";
|
2022-02-07 14:22:43 +01:00
|
|
|
import type { ActivatablesManager } from "../Phaser/Game/ActivatablesManager";
|
2021-08-03 11:13:08 +02:00
|
|
|
import type { UserInputManager } from "../Phaser/UserInput/UserInputManager";
|
|
|
|
|
|
|
|
export interface LayoutManagerAction {
|
2021-08-05 11:19:28 +02:00
|
|
|
uuid: string;
|
|
|
|
type: "warning" | "message";
|
2021-08-03 11:13:08 +02:00
|
|
|
message: string | number | boolean | undefined;
|
|
|
|
callback: () => void;
|
|
|
|
userInputManager: UserInputManager | undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createLayoutManagerAction() {
|
|
|
|
const { subscribe, set, update } = writable<LayoutManagerAction[]>([]);
|
|
|
|
|
|
|
|
return {
|
|
|
|
subscribe,
|
|
|
|
addAction: (newAction: LayoutManagerAction): void => {
|
|
|
|
update((list: LayoutManagerAction[]) => {
|
|
|
|
let found = false;
|
2021-08-05 11:19:28 +02:00
|
|
|
for (const action of list) {
|
|
|
|
if (action.uuid === newAction.uuid) {
|
2021-08-03 11:13:08 +02:00
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
list.push(newAction);
|
2021-08-05 11:19:28 +02:00
|
|
|
newAction.userInputManager?.addSpaceEventListner(newAction.callback);
|
2021-08-03 11:13:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
});
|
|
|
|
},
|
2021-08-05 11:19:28 +02:00
|
|
|
removeAction: (uuid: string): void => {
|
2021-08-03 11:13:08 +02:00
|
|
|
update((list: LayoutManagerAction[]) => {
|
2021-08-05 11:19:28 +02:00
|
|
|
const index = list.findIndex((action) => action.uuid === uuid);
|
2021-08-03 11:13:08 +02:00
|
|
|
|
|
|
|
if (index !== -1) {
|
2021-08-05 11:19:28 +02:00
|
|
|
list[index].userInputManager?.removeSpaceEventListner(list[index].callback);
|
2021-08-03 11:13:08 +02:00
|
|
|
list.splice(index, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
clearActions: (): void => {
|
|
|
|
set([]);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export const layoutManagerActionStore = createLayoutManagerAction();
|
2021-08-05 11:19:28 +02:00
|
|
|
|
2022-01-05 10:27:40 +01:00
|
|
|
export const layoutManagerActionVisibilityStore = derived(layoutManagerActionStore, ($layoutManagerActionStore) => {
|
2021-08-05 11:19:28 +02:00
|
|
|
return !!$layoutManagerActionStore.length;
|
|
|
|
});
|